1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00
kyverno/pkg/utils/kube/version_test.go
Charles-Edouard Brétéché 94abfaf13e
refactor: move util funcs in sub packages (#5754)
* refactor: move util func in sub packages

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* Update pkg/utils/kube/crd.go

Signed-off-by: shuting <shutting06@gmail.com>

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
Signed-off-by: shuting <shutting06@gmail.com>
Co-authored-by: shuting <shutting06@gmail.com>
2022-12-22 06:39:54 +00:00

42 lines
1.1 KiB
Go

package kube
import (
"testing"
"gotest.tools/assert"
)
func Test_higherVersion(t *testing.T) {
v, err := isVersionHigher("invalid.version", 1, 1, 1)
assert.Assert(t, v == false && err != nil)
v, err = isVersionHigher("invalid-version", 0, 0, 0)
assert.Assert(t, v == false && err != nil)
v, err = isVersionHigher("v1.1.1", 1, 1, 1)
assert.Assert(t, v == false && err == nil)
v, err = isVersionHigher("v1.0.0", 1, 1, 1)
assert.Assert(t, v == false && err == nil)
v, err = isVersionHigher("v1.5.9", 1, 5, 8)
assert.Assert(t, v == true && err == nil)
v, err = isVersionHigher("v1.5.9+distro", 1, 5, 8)
assert.Assert(t, v == true && err == nil)
v, err = isVersionHigher("v1.5.9+distro", 1, 5, 8)
assert.Assert(t, v == true && err == nil)
v, err = isVersionHigher("v1.5.9-rc2", 1, 5, 9)
assert.Assert(t, v == false && err == nil)
v, err = isVersionHigher("v1.5.9", 2, 1, 0)
assert.Assert(t, v == false && err == nil)
v, err = isVersionHigher("v2.1.0", 1, 5, 9)
assert.Assert(t, v == true && err == nil)
v, err = isVersionHigher("v1.5.9-x-v1.5.9.x", 1, 5, 8)
assert.Assert(t, v == true && err == nil)
}