github.com/sandwich-go/boost@v1.3.29/xproc/process_test.go (about) 1 package xproc 2 3 import ( 4 "bytes" 5 "github.com/sandwich-go/boost/xos" 6 "github.com/sandwich-go/boost/xstrings" 7 . "github.com/smartystreets/goconvey/convey" 8 "os" 9 "path/filepath" 10 "testing" 11 ) 12 13 func TestProcess(t *testing.T) { 14 Convey("", t, func() { 15 tmpFile := filepath.Join(os.TempDir(), "test.sh") 16 err := xos.FilePutContents(tmpFile, []byte("echo \"GOT ME $1\"")) 17 So(err, ShouldBeNil) 18 stdOut, errSteErr := ShellRun(tmpFile, WithArgs("1.2.0")) 19 So(stdOut, ShouldEqual, "GOT ME 1.2.0") 20 So(errSteErr, ShouldBeNil) 21 22 stdOut1 := new(bytes.Buffer) 23 stdErr1 := new(bytes.Buffer) 24 p := NewProcessShellCmdWithOptions(tmpFile, NewProcessOptions( 25 WithArgs("1.3.0"), 26 WithStdout(stdOut1), 27 WithStderr(stdErr1), 28 )) 29 err = p.Run() 30 So(err, ShouldBeNil) 31 So(xstrings.Trim(stdOut1.String()), ShouldEqual, "GOT ME 1.3.0") 32 So(stdErr1.Len(), ShouldBeZeroValue) 33 }) 34 }