Skip to content

Commit 19b6fab

Browse files
committed
Improve coverage quick wins
1 parent 20ecb9e commit 19b6fab

6 files changed

Lines changed: 549 additions & 1 deletion

File tree

.github/codecov.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,11 @@ comment:
3636

3737
ignore:
3838
- "test/**/*" # ignore folders and all its contents
39-
- "**/zz_generated.*.go" # api generated files
39+
- "hack/**/*" # developer tooling
40+
- "marketplaces/**/*" # marketplace packaging/release tooling
41+
- "examples/**/*" # sample manifests
42+
- "docs/**/*" # documentation and generated docs
43+
- "config/**/*" # generated/deployment manifests
44+
- "bundle/**/*" # generated OLM bundle manifests
45+
- "api/datadoghq/**/*_types.go" # CRD schema type declarations
46+
- "**/zz_generated.*.go" # api generated files

cmd/yaml-mapper/utils/maps_test.go

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed
2+
// under the Apache License Version 2.0.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
// Copyright 2025-present Datadog, Inc.
5+
6+
package utils
7+
8+
import (
9+
"testing"
10+
11+
"github.com/stretchr/testify/require"
12+
"helm.sh/helm/v3/pkg/chartutil"
13+
)
14+
15+
func TestInsertAtPath(t *testing.T) {
16+
values := map[string]any{
17+
"datadog": map[string]any{
18+
"apiKey": "existing",
19+
},
20+
}
21+
22+
InsertAtPath("datadog.logs.enabled", true, values)
23+
24+
require.Equal(t, "existing", values["datadog"].(map[string]any)["apiKey"])
25+
require.Equal(t, true, values["datadog"].(map[string]any)["logs"].(map[string]any)["enabled"])
26+
}
27+
28+
func TestMergeMapDeep(t *testing.T) {
29+
t.Run("deep merges nested maps", func(t *testing.T) {
30+
left := map[string]any{
31+
"datadog": map[string]any{
32+
"apiKey": "existing",
33+
},
34+
}
35+
right := map[string]any{
36+
"datadog": map[string]any{
37+
"logs": map[string]any{"enabled": true},
38+
},
39+
}
40+
41+
got := MergeMapDeep(left, right)
42+
43+
require.Equal(t, "existing", got["datadog"].(map[string]any)["apiKey"])
44+
require.Equal(t, true, got["datadog"].(map[string]any)["logs"].(map[string]any)["enabled"])
45+
})
46+
47+
t.Run("overwrites scalars and ignores nil values", func(t *testing.T) {
48+
got := MergeMapDeep(
49+
map[string]any{"logs": false, "apm": true},
50+
map[string]any{"logs": true, "apm": nil},
51+
)
52+
53+
require.Equal(t, true, got["logs"])
54+
require.Equal(t, true, got["apm"])
55+
})
56+
}
57+
58+
func TestMergeOrSet(t *testing.T) {
59+
t.Run("merges map values", func(t *testing.T) {
60+
values := map[string]any{
61+
"datadog": map[string]any{"apiKey": "existing"},
62+
}
63+
64+
MergeOrSet(values, "datadog", chartutil.Values{"logs": map[string]any{"enabled": true}})
65+
66+
require.Equal(t, "existing", values["datadog"].(map[string]any)["apiKey"])
67+
require.Equal(t, true, values["datadog"].(map[string]any)["logs"].(map[string]any)["enabled"])
68+
})
69+
70+
t.Run("does not write nil values", func(t *testing.T) {
71+
values := map[string]any{}
72+
73+
MergeOrSet(values, "datadog", nil)
74+
75+
require.Empty(t, values)
76+
})
77+
}
78+
79+
func TestGetPathHelpers(t *testing.T) {
80+
values := chartutil.Values{
81+
"datadog": map[string]any{
82+
"apiKey": "abc",
83+
"logs": map[string]any{
84+
"enabled": true,
85+
"items": []any{"first"},
86+
},
87+
},
88+
}
89+
90+
stringValue, ok := GetPathString(values, "datadog", "apiKey")
91+
require.True(t, ok)
92+
require.Equal(t, "abc", stringValue)
93+
94+
boolValue, ok := GetPathBool(values, "datadog", "logs", "enabled")
95+
require.True(t, ok)
96+
require.True(t, boolValue)
97+
98+
sliceValue, ok := GetPathSlice(values, "datadog", "logs", "items")
99+
require.True(t, ok)
100+
require.Equal(t, []any{"first"}, sliceValue)
101+
102+
mapValue, ok := GetPathMap(values, "datadog", "logs")
103+
require.True(t, ok)
104+
require.Equal(t, true, mapValue["enabled"])
105+
106+
_, ok = GetPathString(values, "datadog", "logs", "enabled")
107+
require.False(t, ok)
108+
109+
_, ok = GetPathVal(values, "datadog", "missing")
110+
require.False(t, ok)
111+
}
112+
113+
func TestApplyDeprecationRules(t *testing.T) {
114+
t.Run("moves deprecated boolean aliases to their standard key", func(t *testing.T) {
115+
values := chartutil.Values{
116+
"datadog": map[string]any{
117+
"apm": map[string]any{
118+
"enabled": false,
119+
},
120+
},
121+
}
122+
123+
got := ApplyDeprecationRules(values)
124+
125+
portEnabled, ok := GetPathBool(got, "datadog", "apm", "portEnabled")
126+
require.True(t, ok)
127+
require.False(t, portEnabled)
128+
129+
_, ok = GetPathBool(got, "datadog", "apm", "enabled")
130+
require.False(t, ok)
131+
})
132+
133+
t.Run("standard key participates in boolean OR mapping", func(t *testing.T) {
134+
values := chartutil.Values{
135+
"datadog": map[string]any{
136+
"apm": map[string]any{
137+
"enabled": false,
138+
"portEnabled": true,
139+
},
140+
},
141+
}
142+
143+
got := ApplyDeprecationRules(values)
144+
145+
portEnabled, ok := GetPathBool(got, "datadog", "apm", "portEnabled")
146+
require.True(t, ok)
147+
require.True(t, portEnabled)
148+
})
149+
150+
t.Run("negates deprecated inverse keys unless the standard key is present", func(t *testing.T) {
151+
values := chartutil.Values{
152+
"datadog": map[string]any{
153+
"systemProbe": map[string]any{
154+
"enableDefaultOsReleasePaths": false,
155+
},
156+
},
157+
}
158+
159+
got := ApplyDeprecationRules(values)
160+
161+
disableDefaultPaths, ok := GetPathBool(got, "datadog", "disableDefaultOsReleasePaths")
162+
require.True(t, ok)
163+
require.True(t, disableDefaultPaths)
164+
165+
_, ok = GetPathBool(got, "datadog", "systemProbe", "enableDefaultOsReleasePaths")
166+
require.False(t, ok)
167+
})
168+
}

code-coverage.datadog.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
schema-version: v1
22
ignore:
33
- "test/"
4+
- "hack/"
5+
- "marketplaces/"
6+
- "examples/"
7+
- "docs/"
8+
- "config/"
9+
- "bundle/"
10+
- "api/datadoghq/**/*_types.go"
411
- "**/zz_generated.*.go"
512
gates:
613
- type: patch_coverage_percentage

pkg/cilium/v1/function_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed
2+
// under the Apache License Version 2.0.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
// Copyright 2016-present Datadog, Inc.
5+
6+
package cilium
7+
8+
import (
9+
"testing"
10+
11+
"github.com/stretchr/testify/require"
12+
)
13+
14+
func TestCiliumGroupVersionKinds(t *testing.T) {
15+
t.Run("returns the CiliumNetworkPolicy kind", func(t *testing.T) {
16+
gvk := GroupVersionCiliumNetworkPolicyKind()
17+
18+
require.Equal(t, "cilium.io", gvk.Group)
19+
require.Equal(t, "v2", gvk.Version)
20+
require.Equal(t, "CiliumNetworkPolicy", gvk.Kind)
21+
})
22+
23+
t.Run("returns the CiliumNetworkPolicyList kind", func(t *testing.T) {
24+
gvk := GroupVersionCiliumNetworkPolicyListKind()
25+
26+
require.Equal(t, "cilium.io", gvk.Group)
27+
require.Equal(t, "v2", gvk.Version)
28+
require.Equal(t, "CiliumNetworkPolicyList", gvk.Kind)
29+
})
30+
}
31+
32+
func TestEmptyCiliumUnstructuredPolicy(t *testing.T) {
33+
policy := EmptyCiliumUnstructuredPolicy()
34+
35+
require.Empty(t, policy.GetName())
36+
require.Empty(t, policy.GetNamespace())
37+
require.Equal(t, GroupVersionCiliumNetworkPolicyKind(), policy.GroupVersionKind())
38+
}
39+
40+
func TestEmptyCiliumUnstructuredListPolicy(t *testing.T) {
41+
policyList := EmptyCiliumUnstructuredListPolicy()
42+
43+
require.Empty(t, policyList.Items)
44+
require.Equal(t, GroupVersionCiliumNetworkPolicyListKind(), policyList.GroupVersionKind())
45+
}

0 commit comments

Comments
 (0)