get.porter.sh/porter@v1.3.0/cmd/porter/version_test.go (about) 1 package main 2 3 import ( 4 "bytes" 5 "os" 6 "testing" 7 8 "get.porter.sh/porter/pkg" 9 "github.com/stretchr/testify/assert" 10 "github.com/stretchr/testify/require" 11 ) 12 13 func TestVersion(t *testing.T) { 14 pkg.Version = "v1.0.0" 15 pkg.Commit = "abc123" 16 17 t.Run("command", func(t *testing.T) { 18 p := buildRootCommand() 19 20 // Capture output 21 var out bytes.Buffer 22 p.SetOut(&out) 23 24 // Set the command to run 25 os.Args = []string{"porter", "version"} 26 27 err := p.Execute() 28 require.NoError(t, err) 29 assert.Contains(t, out.String(), "porter v1.0.0 (abc123)") 30 }) 31 32 t.Run("flag", func(t *testing.T) { 33 p := buildRootCommand() 34 35 // Capture output 36 var out bytes.Buffer 37 p.SetOut(&out) 38 39 // Set the command to run 40 os.Args = []string{"porter", "--version"} 41 42 err := p.Execute() 43 require.NoError(t, err) 44 assert.Contains(t, out.String(), "porter v1.0.0 (abc123)") 45 }) 46 }