github.com/verrazzano/verrazzano@v1.7.1/tools/vz/cmd/version/version_test.go (about)

     1  // Copyright (c) 2022, 2024, 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  	"os"
     8  	"strings"
     9  	"testing"
    10  
    11  	"github.com/stretchr/testify/assert"
    12  	"github.com/verrazzano/verrazzano/tools/vz/test/helpers"
    13  )
    14  
    15  // TestVersionCmd - check that command reports not implemented yet
    16  func TestVersionCmd(t *testing.T) {
    17  
    18  	cliVersion = "1.2.3"
    19  	buildDate = "2022-06-10T13:57:03Z"
    20  	gitCommit = "9dbc916b58ab9781f7b4c25e51748fb31ec940f8"
    21  
    22  	// Send the command output to a byte buffer
    23  	rc := helpers.NewFakeRootCmdContextWithFiles(t)
    24  	defer helpers.CleanUpNewFakeRootCmdContextWithFiles(rc)
    25  	versionCmd := NewCmdVersion(rc)
    26  	assert.NotNil(t, versionCmd)
    27  
    28  	// Run version command, check for the expected status results to be displayed
    29  	err := versionCmd.Execute()
    30  	assert.NoError(t, err)
    31  	result, err := os.ReadFile(rc.Out.Name())
    32  	assert.Nil(t, err)
    33  	results := strings.Split(string(result), "\n")
    34  	version, build, commit := results[1], results[2], results[3]
    35  	assert.Regexp(t, `^(Version: )?(v)?(\d+\.)?(\d+\.)?(\d+)$`, version)
    36  	assert.Regexp(t, `^(BuildDate: )?(\d+\-)?(\d+\-)?(\d+T)?(\d+\:)?(\d+\:)?(\d+Z)$`, build)
    37  	assert.Regexp(t, `^(GitCommit: )?(\w{40})$`, commit)
    38  }
    39  
    40  func TestGetEffectiveDocsVersionWhenDocStageEnabled(t *testing.T) {
    41  	cliVersion = "1.2.3"
    42  
    43  	useV8oDoc := os.Getenv("USE_V8O_DOC_STAGE")
    44  	if useV8oDoc == "true" {
    45  		assert.True(t, GetEffectiveDocsVersion() == "devel")
    46  	} else {
    47  		assert.True(t, GetEffectiveDocsVersion() == "v1.2")
    48  	}
    49  }