github.com/olli-ai/jx/v2@v2.0.400-0.20210921045218-14731b4dd448/pkg/cmd/step/verify/step_verify_values_test.go (about) 1 // +build unit 2 3 package verify_test 4 5 import ( 6 "os" 7 "path" 8 "testing" 9 10 "github.com/olli-ai/jx/v2/pkg/cmd/opts" 11 "github.com/olli-ai/jx/v2/pkg/cmd/step/verify" 12 "github.com/olli-ai/jx/v2/pkg/secreturl/fakevault" 13 "github.com/stretchr/testify/assert" 14 "github.com/stretchr/testify/require" 15 ) 16 17 func createStepVerifyValuesOptions(test string) *verify.StepVerifyValuesOptions { 18 dir := path.Join("test_data", "verify_values", test) 19 options := verify.StepVerifyValuesOptions{ 20 SchemaFile: path.Join(dir, "schema.json"), 21 RequirementsDir: dir, 22 ValuesFile: path.Join(dir, "values.yaml"), 23 SecretClient: fakevault.NewFakeClient(), 24 } 25 commonOpts := opts.NewCommonOptionsWithFactory(nil) 26 commonOpts.Out = os.Stdout 27 commonOpts.Err = os.Stderr 28 options.CommonOptions = &commonOpts 29 return &options 30 } 31 32 func TestStepVerifyValuesWithValidValues(t *testing.T) { 33 t.Parallel() 34 35 options := createStepVerifyValuesOptions("valid_values") 36 err := options.Run() 37 38 assert.NoError(t, err, "Command failed: %v", options) 39 } 40 41 func TestStepVerifyValuesWithErrorValues(t *testing.T) { 42 t.Parallel() 43 44 options := createStepVerifyValuesOptions("error_values") 45 err := options.Run() 46 47 assert.Error(t, err, "Command didn't fail: %v", options) 48 } 49 50 func TestStepVerifyValuesWithValidSecretValues(t *testing.T) { 51 t.Parallel() 52 53 options := createStepVerifyValuesOptions("secret_values") 54 55 _, err := options.SecretClient.Write("cluster/adminUser", map[string]interface{}{"password": "test"}) 56 require.NoError(t, err) 57 _, err = options.SecretClient.Write("cluster/pipelineUser", map[string]interface{}{"token": "aaaaa12345bbbbb12345ccccc12345ddddd12345"}) 58 require.NoError(t, err) 59 60 err = options.Run() 61 62 assert.NoError(t, err, "Command failed: %v", options) 63 } 64 65 func TestStepVerifyValuesWithMissingSecretValues(t *testing.T) { 66 t.Parallel() 67 68 options := createStepVerifyValuesOptions("secret_values") 69 70 _, err := options.SecretClient.Write("cluster/adminUser", map[string]interface{}{"password": "test"}) 71 require.NoError(t, err) 72 73 err = options.Run() 74 75 assert.Error(t, err, "Command didn't fail: %v", options) 76 } 77 78 func TestStepVerifyValuesWithErrorSecretValues(t *testing.T) { 79 t.Parallel() 80 81 options := createStepVerifyValuesOptions("secret_values") 82 83 _, err := options.SecretClient.Write("cluster/adminUser", map[string]interface{}{"password": "test"}) 84 require.NoError(t, err) 85 _, err = options.SecretClient.Write("cluster/pipelineUser", map[string]interface{}{"token": "123"}) 86 require.NoError(t, err) 87 88 err = options.Run() 89 90 assert.Error(t, err, "Command didn't fail: %v", options) 91 }