Skip to content

Commit

Permalink
test: integ test for stdout of rename operation
Browse files Browse the repository at this point in the history
  • Loading branch information
sapessi committed Nov 26, 2020
1 parent db8ecbd commit 809189c
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
package main

import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -46,6 +48,51 @@ func TestSimple(t *testing.T) {
assert.Equal(t, "test - 2 - Chapel.avi", files[1])
}

func TestNameStdout(t *testing.T) {
testCtx, err := createIntegTestContext(t)
assert.Nil(t, err)

err = testCtx.CreateFiles("[UnionVideos] Wedding - $cnt - $title.mkv", "Home", "Chapel", "Church", "Reception", "Party")
assert.Nil(t, err)

app := getApp()
args := []string{"raf", "--prop", "title=\\d\\ \\-\\ ([A-Za-z0-9]+)\\.mkv", "--output", "test - $cnt - $title.avi"}
args = append(args, testCtx.Files(true)...)

// capture stdout
old := os.Stdout // keep backup of the real stdout
r, w, _ := os.Pipe()
os.Stdout = w
err = app.Run(args)
assert.Nil(t, err)

outC := make(chan string)
// copy the output in a separate goroutine so printing can't block indefinitely
go func() {
var buf bytes.Buffer
io.Copy(&buf, r)
outC <- buf.String()
}()
// back to normal state
w.Close()
os.Stdout = old // restoring the real stdout
out := <-outC

files, err := testCtx.ListFilesInWorkingDir(false, false)
assert.Nil(t, err)
assert.Equal(t, 5, len(files))
assert.Equal(t, "test - 2 - Chapel.avi", files[1])

outFiles := strings.Split(out, "\n")
assert.Equal(t, 6, len(outFiles))
assert.Equal(t, "test - 1 - Home.avi", outFiles[0])
assert.Equal(t, "test - 2 - Chapel.avi", outFiles[1])
assert.Equal(t, "test - 3 - Church.avi", outFiles[2])
assert.Equal(t, "test - 4 - Reception.avi", outFiles[3])
assert.Equal(t, "test - 5 - Party.avi", outFiles[4])
assert.Equal(t, "", outFiles[5])
}

func TestUndo(t *testing.T) {
testCtx, err := createIntegTestContext(t)
assert.Nil(t, err)
Expand Down

0 comments on commit 809189c

Please sign in to comment.