Skip to content

Commit f3feda8

Browse files
author
Tomasz Czekajlo
authored
Merge pull request #118 from RasaHQ/fix/dbMigrationService_args
Fix args for the db migration service
2 parents 45bbec8 + d86da0f commit f3feda8

File tree

4 files changed

+84
-3
lines changed

4 files changed

+84
-3
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ jobs:
3737
command: lint
3838
config: ct.yaml
3939

40+
test:
41+
name: Unit tests
42+
runs-on: ubuntu-latest
43+
steps:
44+
- name: Checkout
45+
uses: actions/checkout@v2
46+
47+
- name: Install dependencies
48+
run: |
49+
helm dependency update ${CHART}
50+
cd ./tests && go get -t || true
51+
52+
- name: Run tests
53+
working-directory: ./tests
54+
run: go test -v
55+
4056
deploy_chart:
4157
name: Test the deployment of the chart
4258
runs-on: ubuntu-latest

charts/rasa-x/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
apiVersion: v2
33

4-
version: "1.7.11"
4+
version: "1.7.12"
55

66
appVersion: "0.33.0"
77

charts/rasa-x/templates/db-migration-service-deployment.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ spec:
3838
{{- toYaml .Values.dbMigrationService.command | nindent 10 }}
3939
{{- end }}
4040
args:
41+
{{- if .Values.dbMigrationService.args }}
42+
{{- toYaml .Values.dbMigrationService.args | nindent 10 }}
43+
{{- else }}
4144
- python
4245
- -m
4346
- rasax.community.services.db_migration_service
44-
{{- if .Values.dbMigrationService.args }}
45-
{{- toYaml .Values.dbMigrationService.args | nindent 10 }}
4647
{{- end }}
4748
ports:
4849
- name: "http"

tests/db_migration_service_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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

Comments
 (0)