github.com/buildpacks/pack@v0.33.3-0.20240516162812-884dd1837311/internal/commands/builder_test.go (about) 1 package commands_test 2 3 import ( 4 "bytes" 5 "testing" 6 7 "github.com/golang/mock/gomock" 8 "github.com/sclevine/spec" 9 "github.com/sclevine/spec/report" 10 "github.com/spf13/cobra" 11 12 "github.com/buildpacks/pack/internal/commands" 13 "github.com/buildpacks/pack/internal/commands/testmocks" 14 "github.com/buildpacks/pack/internal/config" 15 "github.com/buildpacks/pack/pkg/logging" 16 h "github.com/buildpacks/pack/testhelpers" 17 ) 18 19 func TestBuilderCommand(t *testing.T) { 20 spec.Run(t, "BuilderCommand", testBuilderCommand, spec.Parallel(), spec.Report(report.Terminal{})) 21 } 22 23 func testBuilderCommand(t *testing.T, when spec.G, it spec.S) { 24 var ( 25 cmd *cobra.Command 26 logger logging.Logger 27 outBuf bytes.Buffer 28 ) 29 30 it.Before(func() { 31 logger = logging.NewLogWithWriters(&outBuf, &outBuf) 32 mockController := gomock.NewController(t) 33 mockClient := testmocks.NewMockPackClient(mockController) 34 cmd = commands.NewBuilderCommand(logger, config.Config{}, mockClient) 35 cmd.SetOut(logging.GetWriterForLevel(logger, logging.InfoLevel)) 36 }) 37 38 when("builder", func() { 39 it("prints help text", func() { 40 cmd.SetArgs([]string{}) 41 h.AssertNil(t, cmd.Execute()) 42 output := outBuf.String() 43 h.AssertContains(t, output, "Interact with builders") 44 h.AssertContains(t, output, "Usage:") 45 for _, command := range []string{"create", "suggest", "inspect"} { 46 h.AssertContains(t, output, command) 47 h.AssertNotContains(t, output, command+"-builder") 48 } 49 }) 50 }) 51 }