github.com/buildpacks/pack@v0.33.3-0.20240516162812-884dd1837311/internal/commands/extension_test.go (about)

     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  }