diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 842b31be7..cb3756688 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -35,7 +35,7 @@ jobs: - name: Setup Go # https://github.com/actions/setup-go - uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0 + uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0 with: go-version: ${{ env.GO_VERSION }} @@ -62,7 +62,7 @@ jobs: - name: SonarCloud Scan # https://github.com/sonarsource/sonarcloud-github-action - uses: sonarsource/sonarcloud-github-action@383f7e52eae3ab0510c3cb0e7d9d150bbaeab838 # v3.1.0 + uses: sonarsource/sonarcloud-github-action@02ef91109b2d589e757aefcfb2854c2783fd7b19 # v4.0.0 if: matrix.os == 'ubuntu-latest' && env.SONAR_TOKEN != '' env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} @@ -95,7 +95,7 @@ jobs: - name: Setup go # https://github.com/actions/setup-go - uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0 + uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0 with: go-version: ${{ env.GO_VERSION }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 46b019ca8..e4bcbdaa2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -27,7 +27,7 @@ jobs: - name: setup go # https://github.com/actions/setup-go - uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0 + uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0 with: go-version: ${{ env.GO_VERSION }} @@ -37,7 +37,7 @@ jobs: - name: publish artifacts # https://github.com/softprops/action-gh-release - uses: softprops/action-gh-release@7b4da11513bf3f43f9999e90eabced41ab8bb048 # v2.2.0 + uses: softprops/action-gh-release@01570a1f39cb168c169c802c3bceb9e93fb10974 # v2.1.0 with: files: _dist/** @@ -98,7 +98,7 @@ jobs: - name: Set up Docker Buildx # https://github.com/docker/setup-buildx-action - uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1 + uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0 - name: Login to Docker Hub # https://github.com/docker/login-action @@ -110,7 +110,7 @@ jobs: - name: Build and push by digest id: build # https://github.com/docker/build-push-action - uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0 + uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 # v6.10.0 with: build-args: | HELM_VERSION=${{ matrix.helmVersion }} @@ -156,7 +156,7 @@ jobs: merge-multiple: true - name: Set up Docker Buildx - uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1 + uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0 - name: Docker meta id: meta diff --git a/CHANGELOG.md b/CHANGELOG.md index 75d8fce0a..ac0fbc10b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +0.7.1 / 2024-12-31 +================== +- Move custom MergeValues to HelmCharts MergeTables to align merging values with Helm (relates #471) +- Correct mix up test value with expectation in lessOrEqual and greaterOrEqual validators (resolves #515) +- Refactoring for improved modules update (credits @ivankatliarchuk, relates #501) +- Added extra tests for validation (credits @ivankatliarchuk) +- Update packages to latest patch versions +- Update documentation + 0.7.0 / 2024-11-25 ================== - Fix template path is translated differently (credits @ivankatliarchuk, resolves #300) diff --git a/pkg/unittest/validators/equal_or_greater_validator_test.go b/pkg/unittest/validators/equal_or_greater_validator_test.go index 5aec7fc99..9d344e768 100644 --- a/pkg/unittest/validators/equal_or_greater_validator_test.go +++ b/pkg/unittest/validators/equal_or_greater_validator_test.go @@ -21,14 +21,14 @@ func TestEqualOrGreaterValidatorOk(t *testing.T) { name: "test case 1: int values", doc: "spec: 4", path: "spec", - value: 5, + value: 3, expected: true, }, { name: "test case 2: float64 values", doc: "cpu: 0.6", path: "cpu", - value: 0.75, + value: 0.5, expected: true, }, { @@ -68,52 +68,52 @@ func TestEqualOrGreaterValidatorFail(t *testing.T) { name: "test case 1: int values", doc: "value: 25", path: "value", - value: 5, + value: 55, errorMsg: []string{ "DocumentIndex:\t0", "ValuesIndex:\t0", "Path:\tvalue", "Expected to be greater then or equal to, got:", - "\tthe expected '5' is not greater or equal to the actual '25'", + "\tthe actual '25' is not greater or equal to the expected '55'", }, }, { name: "test case 2: float64 values", doc: "cpu: 1.7", path: "cpu", - value: 1.31, + value: 1.91, errorMsg: []string{ "DocumentIndex:\t0", "ValuesIndex:\t0", "Path:\tcpu", "Expected to be greater then or equal to, got:", - "\tthe expected '1.31' is not greater or equal to the actual '1.7'", + "\tthe actual '1.7' is not greater or equal to the expected '1.91'", }, }, { name: "test case 3: float64 values", doc: "cpu: 1.341", path: "cpu", - value: 1.338, + value: 1.348, errorMsg: []string{ "DocumentIndex:\t0", "ValuesIndex:\t0", "Path:\tcpu", "Expected to be greater then or equal to, got:", - "\tthe expected '1.338' is not greater or equal to the actual '1.341'", + "\tthe actual '1.341' is not greater or equal to the expected '1.348'", }, }, { name: "test case 4: string values", doc: "cpu: 600m", path: "cpu", - value: "590m", + value: "690m", errorMsg: []string{ "DocumentIndex:\t0", "ValuesIndex:\t0", "Path:\tcpu", "Expected to be greater then or equal to, got:", - "\tthe expected '590m' is not greater or equal to the actual '600m'", + "\tthe actual '600m' is not greater or equal to the expected '690m'", }, }, } @@ -218,29 +218,6 @@ spec: assert.Equal(t, []string{}, diff) } -func TestEqualOrGreaterValidator_TODO(t *testing.T) { - var actual = ` -kind: PodDisruptionBudget -metadata: - name: 'greaterorequal-test-pdb' -spec: - minAvailable: 2 - unhealthyPodEvictionPolicy: AlwaysAllow -` - manifest := makeManifest(actual) - - v := EqualOrGreaterValidator{ - Path: "spec.minAvailable", - Value: 1, - } - pass, _ := v.Validate(&ValidateContext{ - Docs: []common.K8sManifest{manifest}, - Negative: false, - }) - - assert.False(t, pass) -} - func TestEqualOrGreaterValidatorWhenTypesDoNotMatch(t *testing.T) { tests := []struct { name, doc, path string diff --git a/pkg/unittest/validators/equal_or_less_validator_test.go b/pkg/unittest/validators/equal_or_less_validator_test.go index cf89466da..28da77e06 100644 --- a/pkg/unittest/validators/equal_or_less_validator_test.go +++ b/pkg/unittest/validators/equal_or_less_validator_test.go @@ -21,21 +21,21 @@ func TestEqualOrLessValidatorOk(t *testing.T) { name: "Test case 1: int ok", doc: "spec: 4", path: "spec", - value: 3, + value: 5, expected: true, }, { name: "Test case 2: float64 ok", doc: "cpu: 0.6", path: "cpu", - value: 0.54, + value: 0.7, expected: true, }, { name: "Test case 3: string ok", doc: "cpu: 600m", path: "cpu", - value: "580m", + value: "680m", expected: true, }, } @@ -68,39 +68,39 @@ func TestEqualOrLessValidatorFail(t *testing.T) { name: "Test case 1: int fail", doc: "value: 6", path: "value", - value: 7, + value: 5, errorMsg: []string{ "DocumentIndex:\t0", "ValuesIndex:\t0", "Path:\tvalue", "Expected to be less then or equal to, got:", - "\tthe expected '7' is not less or equal to the actual '6'", + "\tthe actual '6' is not less or equal to the expected '5'", }, }, { name: "Test case 2: float64 fail", doc: "cpu: 1.7", path: "cpu", - value: 1.71, + value: 1.69, errorMsg: []string{ "DocumentIndex:\t0", "ValuesIndex:\t0", "Path:\tcpu", "Expected to be less then or equal to, got:", - "\tthe expected '1.71' is not less or equal to the actual '1.7'", + "\tthe actual '1.7' is not less or equal to the expected '1.69'", }, }, { name: "Test case 3: float64 fail", doc: "cpu: 1.341", path: "cpu", - value: 1.342, + value: 1.34, errorMsg: []string{ "DocumentIndex:\t0", "ValuesIndex:\t0", "Path:\tcpu", "Expected to be less then or equal to, got:", - "\tthe expected '1.342' is not less or equal to the actual '1.341'", + "\tthe actual '1.341' is not less or equal to the expected '1.34'", }, }, } @@ -211,7 +211,7 @@ a: v := EqualOrLessValidator{ Path: "a.*", - Value: 2, + Value: 0, } pass, diff := v.Validate(&ValidateContext{ FailFast: true, @@ -224,7 +224,7 @@ a: "ValuesIndex:\t0", "Path:\ta.*", "Expected to be less then or equal to, got:", - "\tthe expected '2' is not less or equal to the actual '1'", + "\tthe actual '1' is not less or equal to the expected '0'", }, diff) } @@ -249,7 +249,7 @@ func TestEqualOrLessValidatorWhenNoManifestFail(t *testing.T) { func TestEqualOrLessValidatorWhenNoManifestNegativeOk(t *testing.T) { v := EqualOrLessValidator{ Path: "a.*", - Value: 2, + Value: 0, } pass, diff := v.Validate(&ValidateContext{ FailFast: true, diff --git a/pkg/unittest/validators/operator_validator.go b/pkg/unittest/validators/operator_validator.go index 885ac9af4..bab584646 100644 --- a/pkg/unittest/validators/operator_validator.go +++ b/pkg/unittest/validators/operator_validator.go @@ -50,28 +50,28 @@ func (o operatorValidator) compareValues(expected, actual interface{}, compariso } if !result { - return false, []string{fmt.Sprintf("the expected '%s' is not %s or equal to the actual '%s'", expStr, comparisonType, actStr)} + return false, []string{fmt.Sprintf("the actual '%s' is not %s or equal to the expected '%s'", actStr, comparisonType, expStr)} } return true, nil } func (o operatorValidator) compareStringValues(expected, actual string, comparisonType string, negative bool) bool { - if (comparisonType == "greater" && expected >= actual) || (comparisonType == "less" && expected <= actual) == negative { + if (comparisonType == "greater" && actual >= expected) || (comparisonType == "less" && actual <= expected) == negative { return true } return false } func (o operatorValidator) compareIntValues(expected, actual int, comparisonType string, negative bool) bool { - if (comparisonType == "greater" && expected >= actual) || (comparisonType == "less" && expected <= actual) == negative { + if (comparisonType == "greater" && actual >= expected) || (comparisonType == "less" && actual <= expected) == negative { return true } return false } func (o operatorValidator) compareFloatValues(expected, actual float64, comparisonType string, negative bool) bool { - if (comparisonType == "greater" && expected >= actual) || (comparisonType == "less" && expected <= actual) == negative { + if (comparisonType == "greater" && actual >= expected) || (comparisonType == "less" && actual <= expected) == negative { return true } return false diff --git a/plugin-dbg.yaml b/plugin-dbg.yaml index 7615d430b..538a54c2e 100644 --- a/plugin-dbg.yaml +++ b/plugin-dbg.yaml @@ -1,5 +1,5 @@ name: "unittest" -version: "0.7.0" +version: "0.7.1" 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 b857707ee..5773d36ec 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -1,5 +1,5 @@ name: "unittest" -version: "0.7.0" +version: "0.7.1" 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/test/data/v3/basic/tests/__snapshot__/deployment_test.yaml.snap b/test/data/v3/basic/tests/__snapshot__/deployment_test.yaml.snap index 6e095b87e..83ea1b585 100644 --- a/test/data/v3/basic/tests/__snapshot__/deployment_test.yaml.snap +++ b/test/data/v3/basic/tests/__snapshot__/deployment_test.yaml.snap @@ -1,6 +1,6 @@ should pass all kinds of assertion: 1: | - replicas: 1 + replicas: 2 template: metadata: labels: diff --git a/test/data/v3/basic/tests/deployment_test.yaml b/test/data/v3/basic/tests/deployment_test.yaml index 9ccb2a9c3..e280f5daa 100644 --- a/test/data/v3/basic/tests/deployment_test.yaml +++ b/test/data/v3/basic/tests/deployment_test.yaml @@ -91,16 +91,16 @@ tests: asserts: - greaterOrEqual: path: metadata.labels.appVersion - value: 2.0.0 + value: 0.0.1 - greaterOrEqual: path: spec.template.spec.securityContext.runAsUser - value: 1286 + value: 1000 - greaterOrEqual: path: spec.template.spec.containers[?(@.name == "basic")].resources.limits.cpu - value: "1540m" + value: "1440m" - greaterOrEqual: path: spec.template.spec.containers[?(@.name == "basic")].resources.requests.cpu - value: 1.11 + value: 1.0 - greaterOrEqual: path: spec.template.spec.containers[?(@.name == "basic")].resources.requests.cpu value: 1.1 @@ -125,25 +125,25 @@ tests: value: 10.0.0 - lessOrEqual: path: spec.template.spec.securityContext.runAsUser - value: 1281 + value: 1285 - lessOrEqual: path: spec.template.spec.containers[?(@.name == "basic")].resources.limits.cpu - value: "1280m" + value: "2000m" - lessOrEqual: path: spec.template.spec.containers[?(@.name == "basic")].resources.requests.cpu - value: 1.09 + value: 1.9 - lessOrEqual: path: spec.template.spec.containers[?(@.name == "basic")].resources.requests.cpu value: 1.1 - notLessOrEqual: path: spec.template.spec.containers[?(@.name == "basic")].resources.requests.cpu - value: 1.2 + value: 1.0 - notGreaterOrEqual: path: spec.template.spec.containers[?(@.name == "basic")].resources.requests.cpu - value: 11.0 + value: 1.0 - notGreaterOrEqual: path: spec.template.spec.containers[?(@.name == "basic")].resources.requests.cpu - value: 0.1 + value: 1.2 - notGreaterOrEqual: path: spec.template.spec.containers[?(@.name == "basic")].resources.requests.memory value: "1Mi" diff --git a/test/data/v3/basic/tests/pdp_test.yaml b/test/data/v3/basic/tests/pdp_test.yaml index 9311a2d2c..7e147363c 100644 --- a/test/data/v3/basic/tests/pdp_test.yaml +++ b/test/data/v3/basic/tests/pdp_test.yaml @@ -8,4 +8,4 @@ tests: path: spec.minAvailable - greaterOrEqual: path: spec.minAvailable - value: 2 + value: 1 diff --git a/test/data/v3/basic/tests_failed/__snapshot__/deployment_test.yaml.snap b/test/data/v3/basic/tests_failed/__snapshot__/deployment_test.yaml.snap index 6ede39455..b5f2f135d 100644 --- a/test/data/v3/basic/tests_failed/__snapshot__/deployment_test.yaml.snap +++ b/test/data/v3/basic/tests_failed/__snapshot__/deployment_test.yaml.snap @@ -1,6 +1,6 @@ should fail all kinds of assertion: 1: | - replicas: 1 + replicas: 2 template: metadata: labels: diff --git a/test/data/v3/basic/values.yaml b/test/data/v3/basic/values.yaml index 1703e3ef1..55202a5d8 100644 --- a/test/data/v3/basic/values.yaml +++ b/test/data/v3/basic/values.yaml @@ -1,7 +1,7 @@ # Default values for basic. # This is a YAML-formatted file. # Declare variables to be passed into your templates. -replicaCount: 1 +replicaCount: 2 image: repository: nginx tag: stable