|
| 1 | +package 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/logger" |
| 14 | + "github.com/gruntwork-io/terratest/modules/random" |
| 15 | +) |
| 16 | + |
| 17 | +var ( |
| 18 | + chart string = "../charts/rasa-x" |
| 19 | + releaseName string = "rasa-x" |
| 20 | + namespaceName string = "test-" + strings.ToLower(random.UniqueId()) |
| 21 | +) |
| 22 | + |
| 23 | +func TestArgsDeployment(t *testing.T) { |
| 24 | + t.Parallel() |
| 25 | + |
| 26 | + // Path to the helm chart we will test |
| 27 | + helmChartPath, err := filepath.Abs(chart) |
| 28 | + require.NoError(t, err) |
| 29 | + |
| 30 | + // Set up the namespace; confirm that the template renders the expected value for the namespace. |
| 31 | + logger.Logf(t, "Namespace: %s\n", namespaceName) |
| 32 | + |
| 33 | + // Setup the args. For this test, we will set the following input values: |
| 34 | + // - dbMigrationService.args[0]=test |
| 35 | + optionsWithValues := &helm.Options{ |
| 36 | + SetValues: map[string]string{ |
| 37 | + "dbMigrationService.args[0]": "test", |
| 38 | + }, |
| 39 | + KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), |
| 40 | + } |
| 41 | + |
| 42 | + optionsWithoutValues := &helm.Options{ |
| 43 | + KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), |
| 44 | + } |
| 45 | + |
| 46 | + outputWithOptions := helm.RenderTemplate(t, optionsWithValues, helmChartPath, releaseName, []string{"templates/db-migration-service-deployment.yaml"}) |
| 47 | + outputWithoutOptions := helm.RenderTemplate(t, optionsWithoutValues, helmChartPath, releaseName, []string{"templates/db-migration-service-deployment.yaml"}) |
| 48 | + |
| 49 | + var deploymentWithOptions appsv1.Deployment |
| 50 | + var deploymentWithoutOptions appsv1.Deployment |
| 51 | + helm.UnmarshalK8SYaml(t, outputWithOptions, &deploymentWithOptions) |
| 52 | + helm.UnmarshalK8SYaml(t, outputWithoutOptions, &deploymentWithoutOptions) |
| 53 | + |
| 54 | + // Verify the deployment pod template spec is set to the expected values |
| 55 | + |
| 56 | + renderedDeploymentWithOptions := deploymentWithOptions |
| 57 | + renderedDeploymentWithoutOptions := deploymentWithoutOptions |
| 58 | + |
| 59 | + require.Equal(t, len(renderedDeploymentWithOptions.Spec.Template.Spec.Containers), 1) |
| 60 | + require.Equal(t, len(renderedDeploymentWithoutOptions.Spec.Template.Spec.Containers), 1) |
| 61 | + |
| 62 | + require.Equal(t, renderedDeploymentWithOptions.Spec.Template.Spec.Containers[0].Args, []string{"test"}) |
| 63 | + require.Equal(t, renderedDeploymentWithoutOptions.Spec.Template.Spec.Containers[0].Args, []string{"python", "-m", "rasax.community.services.db_migration_service"}) |
| 64 | +} |
0 commit comments