|
| 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/fakes" |
| 14 | + "github.com/buildpacks/pack/internal/commands/testmocks" |
| 15 | + "github.com/buildpacks/pack/internal/config" |
| 16 | + "github.com/buildpacks/pack/pkg/logging" |
| 17 | + h "github.com/buildpacks/pack/testhelpers" |
| 18 | +) |
| 19 | + |
| 20 | +func TestExtensionCommand(t *testing.T) { |
| 21 | + spec.Run(t, "ExtensionCommand", testExtensionCommand, spec.Parallel(), spec.Report(report.Terminal{})) |
| 22 | +} |
| 23 | + |
| 24 | +func testExtensionCommand(t *testing.T, when spec.G, it spec.S) { |
| 25 | + var ( |
| 26 | + cmd *cobra.Command |
| 27 | + logger logging.Logger |
| 28 | + outBuf bytes.Buffer |
| 29 | + mockClient *testmocks.MockPackClient |
| 30 | + ) |
| 31 | + |
| 32 | + it.Before(func() { |
| 33 | + logger = logging.NewLogWithWriters(&outBuf, &outBuf) |
| 34 | + mockController := gomock.NewController(t) |
| 35 | + mockClient = testmocks.NewMockPackClient(mockController) |
| 36 | + cmd = commands.NewExtensionCommand(logger, config.Config{}, mockClient, fakes.NewFakePackageConfigReader()) |
| 37 | + cmd.SetOut(logging.GetWriterForLevel(logger, logging.InfoLevel)) |
| 38 | + }) |
| 39 | + |
| 40 | + when("extension", func() { |
| 41 | + it("prints help text", func() { |
| 42 | + cmd.SetArgs([]string{}) |
| 43 | + h.AssertNil(t, cmd.Execute()) |
| 44 | + output := outBuf.String() |
| 45 | + h.AssertContains(t, output, "Interact with extensions") |
| 46 | + for _, command := range []string{"Usage", "package", "register", "yank", "pull", "inspect"} { |
| 47 | + h.AssertContains(t, output, command) |
| 48 | + } |
| 49 | + }) |
| 50 | + }) |
| 51 | +} |
0 commit comments