github.com/verrazzano/verrazzano@v1.7.0/tools/charts-manager/vcm/cmd/root/root_test.go (about) 1 // Copyright (c) 2023, 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 root 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 "github.com/verrazzano/verrazzano/tools/charts-manager/vcm/cmd/diff" 11 "github.com/verrazzano/verrazzano/tools/charts-manager/vcm/cmd/patch" 12 "github.com/verrazzano/verrazzano/tools/charts-manager/vcm/cmd/pull" 13 "github.com/verrazzano/verrazzano/tools/charts-manager/vcm/tests/pkg/fakes" 14 vcmtesthelpers "github.com/verrazzano/verrazzano/tools/charts-manager/vcm/tests/pkg/helpers" 15 ) 16 17 // TestNewRootCmd tests that function TestNewRootCmd creates root cmd with correct sub commands 18 // GIVEN a call to TestNewRootCmd 19 // 20 // WHEN correct arguments are passed 21 // THEN the root cmd instance created contains all the required flags. 22 func TestNewRootCmd(t *testing.T) { 23 rc, cleanup, err := vcmtesthelpers.ContextSetup() 24 assert.NoError(t, err) 25 defer cleanup() 26 cmd := NewRootCmd(rc, fakes.FakeHelmChartFileSystem{}, fakes.FakeHelmConfig{}) 27 assert.NotNil(t, cmd, "command is nil") 28 pullCmdFound := false 29 diffCmdFound := false 30 patchCmdFound := false 31 for _, command := range cmd.Commands() { 32 if command.Name() == pull.CommandName { 33 pullCmdFound = true 34 } 35 36 if command.Name() == diff.CommandName { 37 diffCmdFound = true 38 } 39 40 if command.Name() == patch.CommandName { 41 patchCmdFound = true 42 } 43 } 44 assert.True(t, pullCmdFound, "pull command not added,") 45 assert.True(t, diffCmdFound, "diff command not added,") 46 assert.True(t, patchCmdFound, "patch command not added,") 47 }