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

     1  package commands_test
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  
     7  	"github.com/sclevine/spec"
     8  	"github.com/sclevine/spec/report"
     9  	"github.com/spf13/cobra"
    10  
    11  	"github.com/buildpacks/pack/internal/commands"
    12  	"github.com/buildpacks/pack/pkg/logging"
    13  	h "github.com/buildpacks/pack/testhelpers"
    14  )
    15  
    16  func TestVersionCommand(t *testing.T) {
    17  	spec.Run(t, "Commands", testVersionCommand, spec.Parallel(), spec.Report(report.Terminal{}))
    18  }
    19  
    20  func testVersionCommand(t *testing.T, when spec.G, it spec.S) {
    21  	var (
    22  		command     *cobra.Command
    23  		outBuf      bytes.Buffer
    24  		testVersion = "1.3.4"
    25  	)
    26  
    27  	it.Before(func() {
    28  		command = commands.Version(logging.NewLogWithWriters(&outBuf, &outBuf), testVersion)
    29  	})
    30  
    31  	when("#Version", func() {
    32  		it("returns version", func() {
    33  			command.SetArgs([]string{})
    34  			h.AssertNil(t, command.Execute())
    35  			h.AssertEq(t, outBuf.String(), testVersion+"\n")
    36  		})
    37  	})
    38  }