-
Notifications
You must be signed in to change notification settings - Fork 144
Improve coverage quick wins #3020
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
Open
tbavelier
wants to merge
3
commits into
main
Choose a base branch
from
tbavelier/improve-coverage-quick-wins
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.
Open
Changes from all commits
Commits
Show all changes
3 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
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 |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| // Unless explicitly stated otherwise all files in this repository are licensed | ||
| // under the Apache License Version 2.0. | ||
| // This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
| // Copyright 2025-present Datadog, Inc. | ||
|
|
||
| package utils | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| "helm.sh/helm/v3/pkg/chartutil" | ||
| ) | ||
|
|
||
| func TestInsertAtPath(t *testing.T) { | ||
| values := map[string]any{ | ||
| "datadog": map[string]any{ | ||
| "apiKey": "existing", | ||
| }, | ||
| } | ||
|
|
||
| InsertAtPath("datadog.logs.enabled", true, values) | ||
|
|
||
| require.Equal(t, "existing", values["datadog"].(map[string]any)["apiKey"]) | ||
| require.Equal(t, true, values["datadog"].(map[string]any)["logs"].(map[string]any)["enabled"]) | ||
| } | ||
|
|
||
| func TestMergeMapDeep(t *testing.T) { | ||
| t.Run("deep merges nested maps", func(t *testing.T) { | ||
| left := map[string]any{ | ||
| "datadog": map[string]any{ | ||
| "apiKey": "existing", | ||
| }, | ||
| } | ||
| right := map[string]any{ | ||
| "datadog": map[string]any{ | ||
| "logs": map[string]any{"enabled": true}, | ||
| }, | ||
| } | ||
|
|
||
| got := MergeMapDeep(left, right) | ||
|
|
||
| require.Equal(t, "existing", got["datadog"].(map[string]any)["apiKey"]) | ||
| require.Equal(t, true, got["datadog"].(map[string]any)["logs"].(map[string]any)["enabled"]) | ||
| }) | ||
|
|
||
| t.Run("overwrites scalars and ignores nil values", func(t *testing.T) { | ||
| got := MergeMapDeep( | ||
| map[string]any{"logs": false, "apm": true}, | ||
| map[string]any{"logs": true, "apm": nil}, | ||
| ) | ||
|
|
||
| require.Equal(t, true, got["logs"]) | ||
| require.Equal(t, true, got["apm"]) | ||
| }) | ||
| } | ||
|
|
||
| func TestMergeOrSet(t *testing.T) { | ||
| t.Run("merges map values", func(t *testing.T) { | ||
| values := map[string]any{ | ||
| "datadog": map[string]any{"apiKey": "existing"}, | ||
| } | ||
|
|
||
| MergeOrSet(values, "datadog", chartutil.Values{"logs": map[string]any{"enabled": true}}) | ||
|
|
||
| require.Equal(t, "existing", values["datadog"].(map[string]any)["apiKey"]) | ||
| require.Equal(t, true, values["datadog"].(map[string]any)["logs"].(map[string]any)["enabled"]) | ||
| }) | ||
|
|
||
| t.Run("does not write nil values", func(t *testing.T) { | ||
| values := map[string]any{} | ||
|
|
||
| MergeOrSet(values, "datadog", nil) | ||
|
|
||
| require.Empty(t, values) | ||
| }) | ||
| } | ||
|
|
||
| func TestGetPathHelpers(t *testing.T) { | ||
| values := chartutil.Values{ | ||
| "datadog": map[string]any{ | ||
| "apiKey": "abc", | ||
| "logs": map[string]any{ | ||
| "enabled": true, | ||
| "items": []any{"first"}, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| stringValue, ok := GetPathString(values, "datadog", "apiKey") | ||
| require.True(t, ok) | ||
| require.Equal(t, "abc", stringValue) | ||
|
|
||
| boolValue, ok := GetPathBool(values, "datadog", "logs", "enabled") | ||
| require.True(t, ok) | ||
| require.True(t, boolValue) | ||
|
|
||
| sliceValue, ok := GetPathSlice(values, "datadog", "logs", "items") | ||
| require.True(t, ok) | ||
| require.Equal(t, []any{"first"}, sliceValue) | ||
|
|
||
| mapValue, ok := GetPathMap(values, "datadog", "logs") | ||
| require.True(t, ok) | ||
| require.Equal(t, true, mapValue["enabled"]) | ||
|
|
||
| _, ok = GetPathString(values, "datadog", "logs", "enabled") | ||
| require.False(t, ok) | ||
|
|
||
| _, ok = GetPathVal(values, "datadog", "missing") | ||
| require.False(t, ok) | ||
| } | ||
|
|
||
| func TestApplyDeprecationRules(t *testing.T) { | ||
| t.Run("moves deprecated boolean aliases to their standard key", func(t *testing.T) { | ||
| values := chartutil.Values{ | ||
| "datadog": map[string]any{ | ||
| "apm": map[string]any{ | ||
| "enabled": false, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| got := ApplyDeprecationRules(values) | ||
|
|
||
| portEnabled, ok := GetPathBool(got, "datadog", "apm", "portEnabled") | ||
| require.True(t, ok) | ||
| require.False(t, portEnabled) | ||
|
|
||
| _, ok = GetPathBool(got, "datadog", "apm", "enabled") | ||
| require.False(t, ok) | ||
| }) | ||
|
|
||
| t.Run("standard key participates in boolean OR mapping", func(t *testing.T) { | ||
| values := chartutil.Values{ | ||
| "datadog": map[string]any{ | ||
| "apm": map[string]any{ | ||
| "enabled": false, | ||
| "portEnabled": true, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| got := ApplyDeprecationRules(values) | ||
|
|
||
| portEnabled, ok := GetPathBool(got, "datadog", "apm", "portEnabled") | ||
| require.True(t, ok) | ||
| require.True(t, portEnabled) | ||
| }) | ||
|
|
||
| t.Run("negates deprecated inverse keys unless the standard key is present", func(t *testing.T) { | ||
| values := chartutil.Values{ | ||
| "datadog": map[string]any{ | ||
| "systemProbe": map[string]any{ | ||
| "enableDefaultOsReleasePaths": false, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| got := ApplyDeprecationRules(values) | ||
|
|
||
| disableDefaultPaths, ok := GetPathBool(got, "datadog", "disableDefaultOsReleasePaths") | ||
| require.True(t, ok) | ||
| require.True(t, disableDefaultPaths) | ||
|
|
||
| _, ok = GetPathBool(got, "datadog", "systemProbe", "enableDefaultOsReleasePaths") | ||
| require.False(t, ok) | ||
| }) | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When hand-written helpers live in API type files, this new ignore removes real product logic from the coverage gates, not just schema declarations. For example,
api/datadoghq/v1alpha1/datadogslo_types.gocontains the executableDatadogSLOType.IsValid()helper, and the same broadapi/datadoghq/**/*_types.gopattern was also added to the Datadog coverage config, so changes in these helpers can be reported as fully covered/ignored by both systems. Consider excluding only generated schema files or moving such helpers out of ignored files.Useful? React with 👍 / 👎.