diff --git a/tests/defaults_test.go b/tests/defaults_test.go index edee1998..b6a88f2a 100644 --- a/tests/defaults_test.go +++ b/tests/defaults_test.go @@ -5,6 +5,8 @@ import ( "github.com/stretchr/testify/require" "helm.sh/helm/v3/pkg/chart/loader" + appsv1 "k8s.io/api/apps/v1" + "k8s.io/utils/pointer" ) // TestDefault loads the chart and checks metadata. @@ -25,5 +27,45 @@ func TestDefault(t *testing.T) { require.NoError(t, err, "converted map to coder values") require.NotNil(t, values, "values must be non-nil") coderd := values.Coderd - require.Equal(t, 1, *coderd.Replicas, "expected 1 replica by default") + require.Equal(t, int32(1), *coderd.Replicas, "expected 1 replica by default") +} + +func TestOverwriteReplica(t *testing.T) { + t.Parallel() + + // Given + // The default helm chart + chart, err := loader.LoadDir("..") + require.NoError(t, err, "loaded chart successfully") + require.NotNil(t, chart, "chart must be non-nil") + + // When + // We overwrite the replicas value and render the chart + var ValuesToOverwrite = &CoderValues{ + Coderd: &CoderdValues{ + Replicas: pointer.Int32(3), + }, + } + + objs, err := RenderChart(chart, ValuesToOverwrite, nil, nil) + // TODO@jsjoeio - getting an error here + // error deserializing "coder/templates/coderd.yaml": yaml: line 9: mapping values are not allowed in this context + require.NoError(t, err, "failed to render chart") + + // Find the coderd Deployment + var found bool + for _, obj := range objs { + deployment, ok := obj.(*appsv1.Deployment) + if ok && deployment.Name == "coderd" { + found = true + + // Then + // We expect the rendered chart to have the values we overwrote + expected := ValuesToOverwrite.Coderd.Replicas + actual := deployment.Spec.Replicas + require.Equal(t, expected, actual, "expected matching PodSecurityContext") + break + } + require.True(t, found, "expected coderd deployment in manifests") + } } diff --git a/tests/values.go b/tests/values.go index 0357ad29..a26499f6 100644 --- a/tests/values.go +++ b/tests/values.go @@ -34,7 +34,7 @@ type CoderValues struct { // CoderdValues are values that apply to coderd. type CoderdValues struct { Image *string `json:"image" yaml:"image"` - Replicas *int `json:"replicas" yaml:"replicas"` + Replicas *int32 `json:"replicas" yaml:"replicas"` ServiceSpec *CoderdServiceSpecValues `json:"serviceSpec" yaml:"serviceSpec"` PodSecurityContext *CoderdPodSecurityContext `json:"podSecurityContext" yaml:"podSecurityContext"` SecurityContext *CoderdSecurityContext `json:"securityContext" yaml:"securityContext"`