Skip to content

Commit 029026d

Browse files
add tests for extension
1 parent 5f96a65 commit 029026d

3 files changed

Lines changed: 58 additions & 7 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
}

pkg/testmocks/mock_build_module.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/testmocks/mock_buildpack_downloader.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)