github.com/buildpacks/pack@v0.33.3-0.20240516162812-884dd1837311/internal/commands/manifest_inspect_test.go (about) 1 package commands_test 2 3 import ( 4 "bytes" 5 "testing" 6 7 "github.com/golang/mock/gomock" 8 "github.com/heroku/color" 9 "github.com/sclevine/spec" 10 "github.com/sclevine/spec/report" 11 "github.com/spf13/cobra" 12 13 "github.com/buildpacks/pack/internal/commands" 14 "github.com/buildpacks/pack/internal/commands/testmocks" 15 "github.com/buildpacks/pack/pkg/logging" 16 h "github.com/buildpacks/pack/testhelpers" 17 ) 18 19 func TestManifestInspectCommand(t *testing.T) { 20 color.Disable(true) 21 defer color.Disable(false) 22 23 spec.Run(t, "Commands", testManifestInspectCommand, spec.Random(), spec.Report(report.Terminal{})) 24 } 25 26 func testManifestInspectCommand(t *testing.T, when spec.G, it spec.S) { 27 var ( 28 command *cobra.Command 29 logger *logging.LogWithWriters 30 outBuf bytes.Buffer 31 mockController *gomock.Controller 32 mockClient *testmocks.MockPackClient 33 ) 34 35 it.Before(func() { 36 logger = logging.NewLogWithWriters(&outBuf, &outBuf) 37 mockController = gomock.NewController(t) 38 mockClient = testmocks.NewMockPackClient(mockController) 39 command = commands.ManifestInspect(logger, mockClient) 40 }) 41 42 when("args are valid", func() { 43 var indexRepoName string 44 it.Before(func() { 45 indexRepoName = h.NewRandomIndexRepoName() 46 }) 47 48 when("index exists", func() { 49 when("no extra flags are provided", func() { 50 it.Before(func() { 51 mockClient.EXPECT().InspectManifest(indexRepoName).Return(nil) 52 }) 53 54 it("should call inspect operation with the given index repo name", func() { 55 command.SetArgs([]string{indexRepoName}) 56 h.AssertNil(t, command.Execute()) 57 }) 58 }) 59 60 when("--help", func() { 61 it("should have help flag", func() { 62 command.SetArgs([]string{"--help"}) 63 h.AssertNilE(t, command.Execute()) 64 h.AssertEq(t, outBuf.String(), "") 65 }) 66 }) 67 }) 68 }) 69 }