github.com/flaque/thaum@v0.6.1-0.20170321004702-75c5b71efb81/thaum/thaum_test.go (about) 1 package main 2 3 import ( 4 "bytes" 5 filet "github.com/Flaque/filet" 6 testUtil "github.com/Flaque/thaum/thaum/testingutil" 7 "github.com/stretchr/testify/assert" 8 "io" 9 "os" 10 "path/filepath" 11 "testing" 12 ) 13 14 // Credit to https://gist.github.com/mindscratch/0faa78bd3c0005d080bf 15 func captureStdout(f func()) string { 16 old := os.Stdout 17 r, w, _ := os.Pipe() 18 os.Stdout = w 19 20 f() 21 22 w.Close() 23 os.Stdout = old 24 25 var buf bytes.Buffer 26 io.Copy(&buf, r) 27 return buf.String() 28 } 29 30 var testRegistry []string 31 32 func TestThaum(t *testing.T) { 33 defer filet.CleanUp(t) 34 35 // Create thaum_files with myTemplate with filepath: 36 // myLocation 37 // - thaum_files 38 // - myTemplate 39 // - mySrc 40 myLocation := filet.TmpDir(t, "") 41 os.Chdir(myLocation) // Move the working directory to our temp location 42 wd, _ := os.Getwd() 43 44 mySrc := filet.TmpDir(t, wd) 45 thaum_files := testUtil.TmpThaumFiles(t, wd) 46 myTemplate := filet.TmpDir(t, thaum_files) 47 // myFile := testUtil.TmpFile(myTemplate) 48 49 // Change directory back to where a user might use it. 50 os.Chdir(mySrc) 51 52 // Run Thaum 53 app := buildApp() 54 args := []string{"", filepath.Base(myTemplate)} 55 text := captureStdout(func() { 56 app.Run(args) 57 }) 58 59 assert.Contains(t, text, "Using thaum_files", "thaum myTemplate does not contain thaum_files") 60 }