github.com/jenkins-x/jx/v2@v2.1.155/pkg/cmd/step/step_values_schema_template_test.go (about) 1 // +build unit 2 3 package step 4 5 import ( 6 "testing" 7 8 "github.com/jenkins-x/jx/v2/pkg/cmd/opts/step" 9 "github.com/jenkins-x/jx/v2/pkg/cmd/testhelpers" 10 11 "github.com/google/uuid" 12 v1 "k8s.io/api/core/v1" 13 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 14 15 "github.com/stretchr/testify/assert" 16 17 gits_test "github.com/jenkins-x/jx/v2/pkg/gits/mocks" 18 helm_test "github.com/jenkins-x/jx/v2/pkg/helm/mocks" 19 20 "github.com/jenkins-x/jx/v2/pkg/cmd/opts" 21 ) 22 23 func TestStepValuesSchemaTemplate(t *testing.T) { 24 cmName := uuid.New().String() 25 o := StepValuesSchemaTemplateOptions{ 26 StepOptions: step.StepOptions{ 27 CommonOptions: &opts.CommonOptions{}, 28 }, 29 ConfigMapName: cmName, 30 Set: []string{ 31 "defaultName=def", 32 }, 33 } 34 testhelpers.ConfigureTestOptions(o.CommonOptions, gits_test.NewMockGitter(), helm_test.NewMockHelmer()) 35 36 schemaTemplate := `{ 37 "$id": "https:/jenkins-x.io/tests/basicTypes.schema.json", 38 "$schema": "http://json-schema.org/draft-07/schema#", 39 "description": "test values.yaml", 40 "type": "object", 41 "properties": { 42 "name": { 43 "type": "string", 44 "default": "{{ .Values.defaultName }}" 45 } 46 } 47 }` 48 49 configMap := v1.ConfigMap{ 50 ObjectMeta: metav1.ObjectMeta{ 51 Name: cmName, 52 }, 53 Data: map[string]string{ 54 "values.schema.json": schemaTemplate, 55 }, 56 } 57 kubeClient, ns, err := o.KubeClientAndNamespace() 58 assert.NoError(t, err) 59 _, err = kubeClient.CoreV1().ConfigMaps(ns).Create(&configMap) 60 assert.NoError(t, err) 61 62 err = o.Run() 63 assert.NoError(t, err) 64 cm, err := kubeClient.CoreV1().ConfigMaps(ns).Get(cmName, metav1.GetOptions{}) 65 assert.NoError(t, err) 66 assert.Equal(t, `{ 67 "$id": "https:/jenkins-x.io/tests/basicTypes.schema.json", 68 "$schema": "http://json-schema.org/draft-07/schema#", 69 "description": "test values.yaml", 70 "type": "object", 71 "properties": { 72 "name": { 73 "type": "string", 74 "default": "def" 75 } 76 } 77 }`, cm.Data["values.schema.json"]) 78 }