Skip to content

Commit

Permalink
add tests for extension
Browse files Browse the repository at this point in the history
Signed-off-by: Darshan Kumar <itsdarshankumar@gmail.com>
  • Loading branch information
itsdarshankumar committed Feb 2, 2023
1 parent 25f6af3 commit d820b36
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 7 deletions.
51 changes: 51 additions & 0 deletions internal/commands/extension_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
})
}
6 changes: 3 additions & 3 deletions pkg/testmocks/mock_build_module.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pkg/testmocks/mock_buildpack_downloader.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d820b36

Please sign in to comment.