-
Notifications
You must be signed in to change notification settings - Fork 17
feat: add test for overwriting replica values #166
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
Draft
jsjoeio
wants to merge
6
commits into
main
Choose a base branch
from
jsjoeio/add-helm-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,18 +5,22 @@ 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. | ||
func TestDefault(t *testing.T) { | ||
t.Parallel() | ||
|
||
// load default chart | ||
jsjoeio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
chart, err := loader.LoadDir("..") | ||
require.NoError(t, err, "loaded chart successfully") | ||
require.NotNil(t, chart, "chart must be non-nil") | ||
require.True(t, chart.IsRoot(), "chart must be a root chart") | ||
require.NoError(t, chart.Validate(), "chart has valid metadata") | ||
|
||
// assert metadata | ||
jsjoeio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
metadata := chart.Metadata | ||
require.Equal(t, "coder", metadata.Name, "unexpected chart name") | ||
require.False(t, metadata.Deprecated, "chart should not be deprecated") | ||
|
@@ -25,5 +29,74 @@ 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") | ||
|
||
jsjoeio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
|
||
// 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") | ||
} | ||
} | ||
|
||
/* | ||
|
||
Notes | ||
|
||
1. load chart | ||
2. change something: i.e. replicas to be more than 1 | ||
3. app | ||
|
||
given: chart loaded | ||
when: set replicas = 3 | ||
then: should see in deployments 3. | ||
|
||
Values: &CoderValues{ | ||
Coderd: &CoderdValues{ | ||
Replicas: pointer.Int32(3), | ||
}, | ||
}, | ||
we ran make lint to generate the /build dir | ||
which is what you would get from helm running/using the templates. | ||
|
||
|
||
objs, err := RenderChart(chart, test.Values, nil, nil) | ||
but instead of test.Values, you're going to do your own struct literal | ||
|
||
Test overriding replicas | ||
|
||
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.