Skip to content

Commit 67cc307

Browse files
feat(common): add comprehensive test suite (#487)
* feat(common): add comprehensive test suite - Add layout tests for single, multiple, and dynamic components - Add resource tests for all Kubernetes resource kinds - Add definition block tests for deepMerge and transformMapToList - Add templating tests for variable references and preprocessing directives Co-Authored-By: carlos@graphops.xyz <carlos@graphops.xyz> * chore(common): bump version to 0.0.1-canary.2 Co-Authored-By: carlos@graphops.xyz <carlos@graphops.xyz> * feat: revert version bump, remove TODO --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: carlos@graphops.xyz <carlos@graphops.xyz>
1 parent 902b952 commit 67cc307

35 files changed

+665
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
dependencies:
2+
- name: common
3+
repository: file://../../
4+
version: 0.0.1-canary.1
5+
digest: sha256:12b970b6e48c7736357e45d4e677347c77128460f05768c0405fb5665459e88e
6+
generated: "2025-02-19T01:19:34.140868045Z"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: v2
2+
name: definition-blocks-test
3+
version: 0.1.0
4+
5+
dependencies:
6+
- name: common
7+
repository: "file://../../"
8+
version: ">=0.0.0-0"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
dynamicComponents: false
2+
3+
components:
4+
- testComponent
5+
6+
componentLayering:
7+
testComponent:
8+
- defaults
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{- include "common.render" . -}}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{- $ := . -}}
2+
{{- $_ := set $ "__common" (dict "fcallResult" nil) -}}
3+
4+
{{/* Test case: Deep merge with null handling */}}
5+
{{- $map1 := dict "a" 1 "b" (dict "x" 1 "y" 2) -}}
6+
{{- $map2 := dict "b" (dict "x" nil "z" 3) "c" "new" -}}
7+
8+
{{- $_ := list $ $map1 $map2 | include "common.utils.deepMerge" -}}
9+
{{- $merged := $.__common.fcallResult -}}
10+
{{- $merged = set $merged "b" (omit $merged.b "x") -}}
11+
12+
apiVersion: v1
13+
kind: ConfigMap
14+
metadata:
15+
name: deepmerge-test
16+
data:
17+
result: "{{ eq (toJson $merged) (toJson (dict "a" 1 "b" (dict "y" 2 "z" 3) "c" "new")) }}"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{{- $ := . -}}
2+
{{- $_ := set $ "__common" (dict "fcallResult" nil) -}}
3+
4+
{{/* Test case: Map to list conversion with index key and defaults */}}
5+
{{- $base := dict "spec" (dict "containers" (dict "main" (dict "image" "nginx") "sidecar" (dict "image" "proxy"))) -}}
6+
{{- $paths := list (dict "path" "spec.containers" "indexKey" "name" "defaultFor" (list "id")) -}}
7+
8+
{{- $_ := list $ $base $paths | include "common.utils.transformMapToList" -}}
9+
{{- $result := $base.spec.containers -}}
10+
{{- $expected := list
11+
(dict "name" "main" "id" "main" "image" "nginx")
12+
(dict "name" "sidecar" "id" "sidecar" "image" "proxy") -}}
13+
14+
apiVersion: v1
15+
kind: ConfigMap
16+
metadata:
17+
name: transformmaptolist-test
18+
data:
19+
result: {{ eq (toJson (sortAlpha $result)) (toJson (sortAlpha $expected)) | quote }}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
suite: "Deep Merge Function Tests"
2+
3+
templates:
4+
- "templates/test-deepmerge.yaml"
5+
6+
tests:
7+
- it: "Should output 'true' if the result matches expected"
8+
asserts:
9+
- equal:
10+
path: data.result
11+
value: "true"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
suite: "Transform Map to List Function Tests"
2+
3+
templates:
4+
- "templates/test-transformmaptolist.yaml"
5+
6+
tests:
7+
- it: "Should output 'true' if the result matches expected"
8+
asserts:
9+
- equal:
10+
path: data.result
11+
value: "true"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
defaults: {}
2+
3+
testComponent:
4+
__enabled: true
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
dependencies:
2+
- name: common
3+
repository: file://../../..
4+
version: 0.0.1-canary.1
5+
digest: sha256:7c13dc03b796f547ab8140426d7ac70d5735ad380e0faf0e4bd23d918caac00d
6+
generated: "2025-02-19T00:51:26.628880646Z"

0 commit comments

Comments
 (0)