diff --git a/internal/commands/extension_test.go b/internal/commands/extension_test.go new file mode 100644 index 000000000..396d77290 --- /dev/null +++ b/internal/commands/extension_test.go @@ -0,0 +1,51 @@ +package commands_test + +import ( + "bytes" + "testing" + + "github.com/golang/mock/gomock" + "github.com/sclevine/spec" + "github.com/sclevine/spec/report" + "github.com/spf13/cobra" + + "github.com/buildpacks/pack/internal/commands" + "github.com/buildpacks/pack/internal/commands/fakes" + "github.com/buildpacks/pack/internal/commands/testmocks" + "github.com/buildpacks/pack/internal/config" + "github.com/buildpacks/pack/pkg/logging" + h "github.com/buildpacks/pack/testhelpers" +) + +func TestExtensionCommand(t *testing.T) { + spec.Run(t, "ExtensionCommand", testExtensionCommand, spec.Parallel(), spec.Report(report.Terminal{})) +} + +func testExtensionCommand(t *testing.T, when spec.G, it spec.S) { + var ( + cmd *cobra.Command + logger logging.Logger + outBuf bytes.Buffer + mockClient *testmocks.MockPackClient + ) + + it.Before(func() { + logger = logging.NewLogWithWriters(&outBuf, &outBuf) + mockController := gomock.NewController(t) + mockClient = testmocks.NewMockPackClient(mockController) + cmd = commands.NewExtensionCommand(logger, config.Config{}, mockClient, fakes.NewFakePackageConfigReader()) + cmd.SetOut(logging.GetWriterForLevel(logger, logging.InfoLevel)) + }) + + when("extension", func() { + it("prints help text", func() { + cmd.SetArgs([]string{}) + h.AssertNil(t, cmd.Execute()) + output := outBuf.String() + h.AssertContains(t, output, "Interact with extensions") + for _, command := range []string{"Usage", "package", "register", "yank", "pull", "inspect"} { + h.AssertContains(t, output, command) + } + }) + }) +} diff --git a/pkg/testmocks/mock_build_module.go b/pkg/testmocks/mock_build_module.go index 80ae2f965..5548ad6f6 100644 --- a/pkg/testmocks/mock_build_module.go +++ b/pkg/testmocks/mock_build_module.go @@ -10,7 +10,7 @@ import ( gomock "github.com/golang/mock/gomock" - buildmodule "github.com/buildpacks/pack/pkg/buildpack" + buildpack "github.com/buildpacks/pack/pkg/buildpack" ) // MockBuildModule is a mock of BuildModule interface. @@ -37,10 +37,10 @@ func (m *MockBuildModule) EXPECT() *MockBuildModuleMockRecorder { } // Descriptor mocks base method. -func (m *MockBuildModule) Descriptor() buildmodule.Descriptor { +func (m *MockBuildModule) Descriptor() buildpack.Descriptor { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Descriptor") - ret0, _ := ret[0].(buildmodule.Descriptor) + ret0, _ := ret[0].(buildpack.Descriptor) return ret0 } diff --git a/pkg/testmocks/mock_buildpack_downloader.go b/pkg/testmocks/mock_buildpack_downloader.go index 724ce467c..d67ff548d 100644 --- a/pkg/testmocks/mock_buildpack_downloader.go +++ b/pkg/testmocks/mock_buildpack_downloader.go @@ -10,7 +10,7 @@ import ( gomock "github.com/golang/mock/gomock" - buildmodule "github.com/buildpacks/pack/pkg/buildpack" + buildpack "github.com/buildpacks/pack/pkg/buildpack" ) // MockBuildpackDownloader is a mock of BuildpackDownloader interface. @@ -37,11 +37,11 @@ func (m *MockBuildpackDownloader) EXPECT() *MockBuildpackDownloaderMockRecorder } // Download mocks base method. -func (m *MockBuildpackDownloader) Download(arg0 context.Context, arg1 string, arg2 buildmodule.DownloadOptions) (buildmodule.BuildModule, []buildmodule.BuildModule, error) { +func (m *MockBuildpackDownloader) Download(arg0 context.Context, arg1 string, arg2 buildpack.DownloadOptions) (buildpack.BuildModule, []buildpack.BuildModule, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Download", arg0, arg1, arg2) - ret0, _ := ret[0].(buildmodule.BuildModule) - ret1, _ := ret[1].([]buildmodule.BuildModule) + ret0, _ := ret[0].(buildpack.BuildModule) + ret1, _ := ret[1].([]buildpack.BuildModule) ret2, _ := ret[2].(error) return ret0, ret1, ret2 }