github.com/buildpacks/pack@v0.33.3-0.20240516162812-884dd1837311/internal/term/term_test.go (about) 1 package term_test 2 3 import ( 4 "bytes" 5 "os" 6 "testing" 7 8 "github.com/sclevine/spec" 9 "github.com/sclevine/spec/report" 10 11 "github.com/buildpacks/pack/internal/term" 12 h "github.com/buildpacks/pack/testhelpers" 13 ) 14 15 func TestTerm(t *testing.T) { 16 spec.Run(t, "Term", testTerm, spec.Parallel(), spec.Report(report.Terminal{})) 17 } 18 19 func testTerm(t *testing.T, when spec.G, it spec.S) { 20 when("#IsTerminal", func() { 21 it("returns false for a pipe", func() { 22 r, _, _ := os.Pipe() 23 fd, isTerm := term.IsTerminal(r) 24 h.AssertFalse(t, isTerm) 25 h.AssertNotEq(t, fd, term.InvalidFileDescriptor) // The mock writer is a pipe, and therefore has a file descriptor 26 }) 27 28 it("returns InvalidFileDescriptor if passed a normal Writer", func() { 29 fd, isTerm := term.IsTerminal(&bytes.Buffer{}) 30 h.AssertFalse(t, isTerm) 31 h.AssertEq(t, fd, term.InvalidFileDescriptor) 32 }) 33 }) 34 }