github.com/verrazzano/verrazzano@v1.7.0/tools/psr/psrctl/cmd/version/version_test.go (about) 1 // Copyright (c) 2022, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package version 5 6 import ( 7 "bytes" 8 "os" 9 "strings" 10 "testing" 11 12 "github.com/stretchr/testify/assert" 13 "github.com/verrazzano/verrazzano/tools/vz/test/helpers" 14 "k8s.io/cli-runtime/pkg/genericclioptions" 15 ) 16 17 // TestVersionCmd - check that command reports not implemented yet 18 func TestVersionCmd(t *testing.T) { 19 20 cliVersion = "1.2.3" 21 buildDate = "2022-06-10T13:57:03Z" 22 gitCommit = "9dbc916b58ab9781f7b4c25e51748fb31ec940f8" 23 24 // Send the command output to a byte buffer 25 buf := new(bytes.Buffer) 26 errBuf := new(bytes.Buffer) 27 rc := helpers.NewFakeRootCmdContext(genericclioptions.IOStreams{In: os.Stdin, Out: buf, ErrOut: errBuf}) 28 versionCmd := NewCmdVersion(rc) 29 assert.NotNil(t, versionCmd) 30 31 // Run version command, check for the expected status results to be displayed 32 err := versionCmd.Execute() 33 assert.NoError(t, err) 34 result := buf.String() 35 results := strings.Split(result, "\n") 36 version, build, commit := results[1], results[2], results[3] 37 assert.Regexp(t, `^(Version: )?(v)?(\d+\.)?(\d+\.)?(\d+)$`, version) 38 assert.Regexp(t, `^(BuildDate: )?(\d+\-)?(\d+\-)?(\d+T)?(\d+\:)?(\d+\:)?(\d+Z)$`, build) 39 assert.Regexp(t, `^(GitCommit: )?(\w{40})$`, commit) 40 } 41 42 func TestGetEffectiveDocsVersionWhenDocStageEnabled(t *testing.T) { 43 cliVersion = "1.2.3" 44 45 useV8oDoc := os.Getenv("USE_V8O_DOC_STAGE") 46 if useV8oDoc == "true" { 47 assert.True(t, GetEffectiveDocsVersion() == "devel") 48 } else { 49 assert.True(t, GetEffectiveDocsVersion() == "v1.2") 50 } 51 }