Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add test for overwriting replica values #166

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion tests/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
jsjoeio marked this conversation as resolved.
Show resolved Hide resolved
)

// TestDefault loads the chart and checks metadata.
Expand All @@ -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")
Comment on lines +50 to +53
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jawnsy I feel like I'm so close. I'm doing something wrong though and getting this error. Any ideas?

image


// 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")
}
}
2 changes: 1 addition & 1 deletion tests/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down