Skip to content

Commit

Permalink
Merge branch 'main' into issue-488
Browse files Browse the repository at this point in the history
* main:
  Rollback to working version.
  Correct lessOrEqual and greateOrEqual validators.
  build(deps): bump actions/setup-go from 5.1.0 to 5.2.0
  build(deps): bump docker/setup-buildx-action from 3.7.1 to 3.8.0
  build(deps): bump docker/build-push-action from 6.9.0 to 6.10.0
  build(deps): bump sonarsource/sonarcloud-github-action
  • Loading branch information
ivankatliarchuk committed Jan 1, 2025
2 parents 34b9fa6 + c128def commit 647232e
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 73 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand All @@ -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 }}
Expand Down Expand Up @@ -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 }}

Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand All @@ -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/**

Expand Down Expand Up @@ -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
Expand All @@ -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 }}
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
43 changes: 10 additions & 33 deletions pkg/unittest/validators/equal_or_greater_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
{
Expand Down Expand Up @@ -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'",
},
},
}
Expand Down Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions pkg/unittest/validators/equal_or_less_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
Expand Down Expand Up @@ -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'",
},
},
}
Expand Down Expand Up @@ -211,7 +211,7 @@ a:

v := EqualOrLessValidator{
Path: "a.*",
Value: 2,
Value: 0,
}
pass, diff := v.Validate(&ValidateContext{
FailFast: true,
Expand All @@ -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)
}

Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions pkg/unittest/validators/operator_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion plugin-dbg.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion plugin.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
should pass all kinds of assertion:
1: |
replicas: 1
replicas: 2
template:
metadata:
labels:
Expand Down
20 changes: 10 additions & 10 deletions test/data/v3/basic/tests/deployment_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
Loading

0 comments on commit 647232e

Please sign in to comment.