|
| 1 | +package template_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "path/filepath" |
| 5 | + "strings" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/stretchr/testify/require" |
| 9 | + appsv1 "k8s.io/api/apps/v1" |
| 10 | + |
| 11 | + "github.com/gruntwork-io/terratest/modules/helm" |
| 12 | + "github.com/gruntwork-io/terratest/modules/k8s" |
| 13 | + "github.com/gruntwork-io/terratest/modules/random" |
| 14 | +) |
| 15 | + |
| 16 | +func TestChartTemplateEnableConvertersEnabled(t *testing.T) { |
| 17 | + |
| 18 | + // Path to the helm chart we will test |
| 19 | + helmChartPath, err := filepath.Abs("../../charts") |
| 20 | + releaseName := "marklogic-container-env-test" |
| 21 | + t.Log(helmChartPath, releaseName) |
| 22 | + require.NoError(t, err) |
| 23 | + |
| 24 | + // Set up the namespace; confirm that the template renders the expected value for the namespace. |
| 25 | + namespaceName := "marklogic-" + strings.ToLower(random.UniqueId()) |
| 26 | + t.Logf("Namespace: %s\n", namespaceName) |
| 27 | + |
| 28 | + // Setup the args for helm install |
| 29 | + options := &helm.Options{ |
| 30 | + SetValues: map[string]string{ |
| 31 | + "image.repository": "marklogicdb/marklogic-db", |
| 32 | + "image.tag": "latest", |
| 33 | + "persistence.enabled": "false", |
| 34 | + "enableConverters": "true", |
| 35 | + }, |
| 36 | + KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), |
| 37 | + } |
| 38 | + |
| 39 | + // render the tempate |
| 40 | + output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/statefulset.yaml"}) |
| 41 | + |
| 42 | + var statefulset appsv1.StatefulSet |
| 43 | + helm.UnmarshalK8SYaml(t, output, &statefulset) |
| 44 | + |
| 45 | + // Verify the name and namespace matches |
| 46 | + require.Equal(t, namespaceName, statefulset.Namespace) |
| 47 | + |
| 48 | + // Verify the value of enableConverters parameter |
| 49 | + expectedEnableConverters := "true" |
| 50 | + actualEnableConverters := statefulset.Spec.Template.Spec.Containers[0].Env[3].Value |
| 51 | + require.Equal(t, expectedEnableConverters, actualEnableConverters) |
| 52 | +} |
| 53 | + |
| 54 | +func TestChartTemplateEnableConvertersDisabled(t *testing.T) { |
| 55 | + |
| 56 | + // Path to the helm chart we will test |
| 57 | + helmChartPath, err := filepath.Abs("../../charts") |
| 58 | + releaseName := "marklogic-container-env-test" |
| 59 | + t.Log(helmChartPath, releaseName) |
| 60 | + require.NoError(t, err) |
| 61 | + |
| 62 | + // Set up the namespace; confirm that the template renders the expected value for the namespace. |
| 63 | + namespaceName := "marklogic-" + strings.ToLower(random.UniqueId()) |
| 64 | + t.Logf("Namespace: %s\n", namespaceName) |
| 65 | + |
| 66 | + // Setup the args for helm install |
| 67 | + options := &helm.Options{ |
| 68 | + SetValues: map[string]string{ |
| 69 | + "image.repository": "marklogicdb/marklogic-db", |
| 70 | + "image.tag": "latest", |
| 71 | + "persistence.enabled": "false", |
| 72 | + "enableConverters": "false", |
| 73 | + }, |
| 74 | + KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), |
| 75 | + } |
| 76 | + |
| 77 | + // render the tempate |
| 78 | + output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/statefulset.yaml"}) |
| 79 | + |
| 80 | + var statefulset appsv1.StatefulSet |
| 81 | + helm.UnmarshalK8SYaml(t, output, &statefulset) |
| 82 | + |
| 83 | + // Verify the name and namespace matches |
| 84 | + require.Equal(t, namespaceName, statefulset.Namespace) |
| 85 | + |
| 86 | + // Verify the value of enableConverters parameter |
| 87 | + expectedEnableConverters := "false" |
| 88 | + actualEnableConverters := statefulset.Spec.Template.Spec.Containers[0].Env[3].Value |
| 89 | + require.Equal(t, actualEnableConverters, expectedEnableConverters) |
| 90 | + |
| 91 | +} |
| 92 | + |
| 93 | +func TestChartTemplateLicenseValues(t *testing.T) { |
| 94 | + |
| 95 | + // Path to the helm chart we will test |
| 96 | + helmChartPath, err := filepath.Abs("../../charts") |
| 97 | + releaseName := "marklogic-container-env-test" |
| 98 | + t.Log(helmChartPath, releaseName) |
| 99 | + require.NoError(t, err) |
| 100 | + |
| 101 | + // Set up the namespace; confirm that the template renders the expected value for the namespace. |
| 102 | + namespaceName := "marklogic-" + strings.ToLower(random.UniqueId()) |
| 103 | + t.Logf("Namespace: %s\n", namespaceName) |
| 104 | + |
| 105 | + // Setup the args for helm install |
| 106 | + options := &helm.Options{ |
| 107 | + SetValues: map[string]string{ |
| 108 | + "image.repository": "marklogicdb/marklogic-db", |
| 109 | + "image.tag": "latest", |
| 110 | + "persistence.enabled": "false", |
| 111 | + "license.key": "Test License Key", |
| 112 | + "license.licensee": "Test Licensee", |
| 113 | + }, |
| 114 | + KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), |
| 115 | + } |
| 116 | + |
| 117 | + // render the tempate |
| 118 | + output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/statefulset.yaml"}) |
| 119 | + |
| 120 | + var statefulset appsv1.StatefulSet |
| 121 | + helm.UnmarshalK8SYaml(t, output, &statefulset) |
| 122 | + |
| 123 | + // Verify the name and namespace matches |
| 124 | + require.Equal(t, namespaceName, statefulset.Namespace) |
| 125 | + |
| 126 | + // Verify the value of licenseKey and licensee parameters |
| 127 | + expectedLicenseKey := "Test License Key" |
| 128 | + expectedLicensee := "Test Licensee" |
| 129 | + actualLicenseKey := statefulset.Spec.Template.Spec.Containers[0].Env[4].Value |
| 130 | + actualLicensee := statefulset.Spec.Template.Spec.Containers[0].Env[5].Value |
| 131 | + |
| 132 | + require.Equal(t, actualLicenseKey, expectedLicenseKey) |
| 133 | + require.Equal(t, actualLicensee, expectedLicensee) |
| 134 | +} |
0 commit comments