diff --git a/CHANGELOG.md b/CHANGELOG.md
index d332a72d1..aa920507d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,9 +1,11 @@
-0.6.2 / 2024-09-30
+0.6.2 / 2024-10-02
==================
- Fix assertion does not match when using camelcase function (resolves #359)
- Fix templating multi document Helm file with trims break YAML parsing (resolves #403)
- Fix lookup of resources defined in kubernetesProvider without any objects (resolves #380)
-- Improvement support for linux x390x
+- Fix chart object cannot be overwritten in the test job (credits @ivankatliarchuk, resolves #412)
+- Fix capabilities.apiVersions cannot be unset (resolves #413)
+- Improvement support for linux x390x (credits @dandotimujahid)
- Update packages to latest patch versions
- Update documentation
diff --git a/DOCUMENT.md b/DOCUMENT.md
index 9702797c5..3d31bbab9 100644
--- a/DOCUMENT.md
+++ b/DOCUMENT.md
@@ -126,7 +126,7 @@ tests:
- **set**: *object of any, optional*. Set the values directly in suite file. The key is the value path with the format just like `--set` option of `helm install`, for example `image.pullPolicy`. The value is anything you want to set to the path specified by the key, which can be even an array or an object. This set will override values which are already set in the values file.
-- **template**: *string, optional*. **templates**: *array of string, optional*. The template file(s) which render the manifest to be tested, default to the list of template file defined in `templates` of suite file, unless template is defined in the assertion(s) (check [Assertion](#assertion)).
+- **template**: *string, optional*.
**templates**: *array of string, optional*. The template file(s) which render the manifest to be tested, default to the list of template file defined in `templates` of suite file, unless template is defined in the assertion(s) (check [Assertion](#assertion)).
- **documentIndex**: *int, optional*. The index of rendered documents (divided by `---`) to be tested, default to -1, which results in asserting all documents (see Assertion). Generally you can ignored this field if the template file render only one document.
@@ -151,6 +151,10 @@ tests:
- **version**: *string, optional*. The semantic version of the chart, default to the version set in the Chart.
- **appVersion**: *string, optional*. The app-version of the chart, default to the app-version set in the Chart.
+- **kubernetesProvider**: *object, optional*. Define Kubernetes resources to fake.
+ - **scheme**: *object, optional*. Define the Kubernetes schema to fake
+ - **objects**: *array of objects*. Define the Kubernetes objects to fake
+
- **asserts**: *array of assertion, required*. The assertions to validate the rendered chart, check [Assertion](#assertion).
## Assertion
diff --git a/pkg/unittest/.snapshots/TestV3RunnerOkWithFakeK8sClient b/pkg/unittest/.snapshots/TestV3RunnerOkWithFakeK8sClient
index 6e14f778e..026afeafd 100644
--- a/pkg/unittest/.snapshots/TestV3RunnerOkWithFakeK8sClient
+++ b/pkg/unittest/.snapshots/TestV3RunnerOkWithFakeK8sClient
@@ -10,7 +10,7 @@
Charts: 1 passed, 1 total
Test Suites: 4 passed, 4 total
-Tests: 4 passed, 4 total
+Tests: 5 passed, 5 total
Snapshot: 4 passed, 4 total
Time: XX.XXXms
diff --git a/pkg/unittest/test_job.go b/pkg/unittest/test_job.go
index 9690aa157..7baae9d18 100644
--- a/pkg/unittest/test_job.go
+++ b/pkg/unittest/test_job.go
@@ -410,13 +410,13 @@ func (t *TestJob) releaseV3Option() *v3util.ReleaseOptions {
func (t *TestJob) capabilitiesV3() *v3util.Capabilities {
capabilities := v3util.DefaultCapabilities
- // Override the version, when set.
- if t.Capabilities.MajorVersion != "" || t.Capabilities.MinorVersion != "" {
- capabilities.KubeVersion = v3util.KubeVersion{
- Version: fmt.Sprintf("v%s.%s.0", t.Capabilities.MajorVersion, t.Capabilities.MinorVersion),
- Major: cmp.Or(t.Capabilities.MajorVersion, capabilities.KubeVersion.Major),
- Minor: cmp.Or(t.Capabilities.MinorVersion, capabilities.KubeVersion.Minor),
- }
+ majorVersion := cmp.Or(t.Capabilities.MajorVersion, capabilities.KubeVersion.Major)
+ minorVersion := cmp.Or(t.Capabilities.MinorVersion, capabilities.KubeVersion.Minor)
+
+ capabilities.KubeVersion = v3util.KubeVersion{
+ Version: fmt.Sprintf("v%s.%s.0", majorVersion, minorVersion),
+ Major: majorVersion,
+ Minor: minorVersion,
}
capabilities.APIVersions = v3util.VersionSet(t.Capabilities.APIVersions)
diff --git a/pkg/unittest/test_suite.go b/pkg/unittest/test_suite.go
index a7b13676f..1b71da68a 100644
--- a/pkg/unittest/test_suite.go
+++ b/pkg/unittest/test_suite.go
@@ -270,29 +270,12 @@ func (s *TestSuite) polishTestJobsPathInfo() {
// override release settings in testjobs when defined in testsuite
func (s *TestSuite) polishReleaseSettings(test *TestJob) {
- if s.Release.Name != "" {
- if test.Release.Name == "" {
- test.Release.Name = s.Release.Name
- }
- }
-
- if s.Release.Namespace != "" {
- if test.Release.Namespace == "" {
- test.Release.Namespace = s.Release.Namespace
- }
- }
-
- if s.Release.Revision > 0 {
- if test.Release.Revision == 0 {
- test.Release.Revision = s.Release.Revision
- }
- }
- if s.Release.IsUpgrade {
- if !test.Release.IsUpgrade {
- test.Release.IsUpgrade = s.Release.IsUpgrade
- }
- }
+ test.Release.Name = cmp.Or(test.Release.Name, s.Release.Name)
+ test.Release.Namespace = cmp.Or(test.Release.Namespace, s.Release.Namespace)
+ test.Release.Revision = cmp.Or(test.Release.Revision, s.Release.Revision)
+ test.Release.IsUpgrade = cmp.Or(test.Release.IsUpgrade, s.Release.IsUpgrade)
+ log.WithField(common.LOG_TEST_SUITE, "polish-release-settings").Debug("test.release '", test.Release)
}
// override capabilities settings in testjobs when defined in testsuite
@@ -310,9 +293,9 @@ func (s *TestSuite) polishCapabilitiesSettings(test *TestJob) {
}
func (s *TestSuite) polishKubernetesProviderSettings(test *TestJob) {
- if len(s.KubernetesProvider.Objects) > 0 {
- test.KubernetesProvider.Objects = append(test.KubernetesProvider.Objects, s.KubernetesProvider.Objects...)
- }
+
+ test.KubernetesProvider.Objects = append(test.KubernetesProvider.Objects, s.KubernetesProvider.Objects...)
+
if len(s.KubernetesProvider.Scheme) > 0 {
if test.KubernetesProvider.Scheme == nil {
test.KubernetesProvider.Scheme = map[string]KubernetesFakeKindProps{}
@@ -325,12 +308,10 @@ func (s *TestSuite) polishKubernetesProviderSettings(test *TestJob) {
// override chart settings in testjobs when defined in testsuite
func (s *TestSuite) polishChartSettings(test *TestJob) {
- if test.Chart.Version == "" && s.Chart.Version != "" {
- test.Chart.Version = s.Chart.Version
- }
- if test.Chart.AppVersion == "" && s.Chart.AppVersion != "" {
- test.Chart.AppVersion = s.Chart.AppVersion
- }
+
+ test.Chart.Version = cmp.Or(test.Chart.Version, s.Chart.Version)
+ test.Chart.AppVersion = cmp.Or(test.Chart.AppVersion, s.Chart.AppVersion)
+ log.WithField(common.LOG_TEST_SUITE, "polish-chart-settings").Debug("test.chart '", test.Chart)
}
func (s *TestSuite) runV3TestJobs(
diff --git a/plugin-dbg.yaml b/plugin-dbg.yaml
index 2fd367f65..54d63be2a 100644
--- a/plugin-dbg.yaml
+++ b/plugin-dbg.yaml
@@ -1,5 +1,5 @@
name: "unittest"
-version: "0.6.1"
+version: "0.6.2"
usage: "unittest for helm charts"
description: "Unit test for helm chart in YAML with ease to keep your chart functional and robust."
ignoreFlags: false
diff --git a/plugin.yaml b/plugin.yaml
index 9bd053e89..ed46115c9 100644
--- a/plugin.yaml
+++ b/plugin.yaml
@@ -1,5 +1,5 @@
name: "unittest"
-version: "0.6.1"
+version: "0.6.2"
usage: "unittest for helm charts"
description: "Unit test for helm chart in YAML with ease to keep your chart functional and robust."
ignoreFlags: false
diff --git a/schema/helm-testsuite.json b/schema/helm-testsuite.json
index 7c4bf6386..e822f1d4d 100644
--- a/schema/helm-testsuite.json
+++ b/schema/helm-testsuite.json
@@ -82,6 +82,9 @@
"chart": {
"$ref": "#/definitions/chart"
},
+ "kubernetesProvider": {
+ "$ref": "#/definitions/kubernetesProvider"
+ },
"asserts": {
"type": "array",
"description": "The assertions to validate the rendered chart.",
@@ -1021,7 +1024,10 @@
"markdownDescription": "**minorVersion** (integer) _optional_\n\nThe kubernetes minor version, default to the minor version which is set by helm."
},
"apiVersions": {
- "type": ["array", "null"],
+ "type": [
+ "array",
+ "null"
+ ],
"description": "A set of versions, default to the versionset used by the defined kubernetes version.",
"markdownDescription": "**apiVersions** (array) _optional_\n\nA set of versions, default to the versionset used by the defined kubernetes version.",
"items": {
@@ -1113,7 +1119,6 @@
}
},
"required": [
- "scheme",
"objects"
],
"additionalProperties": false
@@ -1169,4 +1174,4 @@
}
}
}
-}
+}
\ No newline at end of file
diff --git a/test/data/v3/basic/tests/deployment_test.yaml b/test/data/v3/basic/tests/deployment_test.yaml
index 64c75a588..cb2e57432 100644
--- a/test/data/v3/basic/tests/deployment_test.yaml
+++ b/test/data/v3/basic/tests/deployment_test.yaml
@@ -81,9 +81,14 @@ tests:
limits:
memory: "128Mi"
cpu: "1500m"
+ chart:
+ appVersion: 0.1.0
template: templates/deployment.yaml
documentIndex: 0
asserts:
+ - greaterOrEqual:
+ path: metadata.labels.appVersion
+ value: 2.0.0
- greaterOrEqual:
path: spec.template.spec.securityContext.runAsUser
value: 1286
@@ -107,9 +112,14 @@ tests:
limits:
memory: "128Mi"
cpu: "1500m"
+ chart:
+ appVersion: 10.0.0
template: templates/deployment.yaml
documentIndex: 0
asserts:
+ - lessOrEqual:
+ path: metadata.labels.appVersion
+ value: 10.0.0
- lessOrEqual:
path: spec.template.spec.securityContext.runAsUser
value: 1281
diff --git a/test/data/v3/basic/tests/servicemonitor_test.yaml b/test/data/v3/basic/tests/servicemonitor_test.yaml
index 43fe773f0..70d267d1d 100644
--- a/test/data/v3/basic/tests/servicemonitor_test.yaml
+++ b/test/data/v3/basic/tests/servicemonitor_test.yaml
@@ -5,7 +5,6 @@ capabilities:
apiVersions:
- monitoring.coreos.com/v1
tests:
-
- it: with monitoring disabled, ServiceMonitor not created
capabilities:
apiVersions:
@@ -15,6 +14,7 @@ tests:
- it: with monitoring, ServiceMonitor is created
capabilities:
+ apiVersions: []
minorVersion: 20
asserts:
- hasDocuments:
@@ -24,4 +24,3 @@ tests:
- equal:
path: metadata.labels["kubeVersion.minor"]
value: "20"
-
diff --git a/test/data/v3/with-k8s-fake-client/tests/lookup_test.yaml b/test/data/v3/with-k8s-fake-client/tests/lookup_test.yaml
index be1c974f6..7bc4805ca 100644
--- a/test/data/v3/with-k8s-fake-client/tests/lookup_test.yaml
+++ b/test/data/v3/with-k8s-fake-client/tests/lookup_test.yaml
@@ -68,3 +68,26 @@ tests:
- lengthEqual:
path: namespaces.items
count: 2
+ - it: manifest should validate pod_not_exists due to additional object add in testjob
+ kubernetesProvider:
+ objects:
+ - kind: Pod
+ apiVersion: v1
+ metadata:
+ name: not-exists
+ namespace: default
+ asserts:
+ - isNotNullOrEmpty:
+ path: pod_not_exists
+ - equal:
+ path: pod_not_exists.kind
+ value: Pod
+ - equal:
+ path: pod_not_exists.apiVersion
+ value: v1
+ - equal:
+ path: pod_not_exists.metadata.name
+ value: not-exists
+ - equal:
+ path: pod_not_exists.metadata.namespace
+ value: default