1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00
kyverno/pkg/engine/operator/operator_test.go
yinka fcf27bb035
fix: change inrange operator regexs (#5962)
* fix inrange operator regexs

Signed-off-by: damilola olayinka <holayinkajr@gmail.com>

* add support for + sign

Signed-off-by: damilola olayinka <holayinkajr@gmail.com>

* add support for leftEndpoint + sign

Signed-off-by: damilola olayinka <holayinkajr@gmail.com>

* update regexs

Signed-off-by: damilola olayinka <holayinkajr@gmail.com>

* add range operator tests in client code

Signed-off-by: damilola olayinka <holayinkajr@gmail.com>

* extract range values

Signed-off-by: damilola olayinka <holayinkajr@gmail.com>

* add cases

Signed-off-by: damilola olayinka <holayinkajr@gmail.com>

* add test

Signed-off-by: damilola olayinka <holayinkajr@gmail.com>

* fix test

Signed-off-by: damilola olayinka <holayinkajr@gmail.com>

* add cli test

Signed-off-by: damilola olayinka <holayinkajr@gmail.com>

* clean up code

Signed-off-by: damilola olayinka <holayinkajr@gmail.com>

* fix lint error

Signed-off-by: damilola olayinka <holayinkajr@gmail.com>

* fix kuttl test

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

* regex nits

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>

* fix

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

Signed-off-by: damilola olayinka <holayinkajr@gmail.com>
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
Co-authored-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-01-16 16:23:36 +01:00

54 lines
2 KiB
Go

package operator
import (
"testing"
"gotest.tools/assert"
)
func TestGetOperatorFromStringPattern_OneChar(t *testing.T) {
assert.Equal(t, GetOperatorFromStringPattern("f"), Equal)
}
func TestGetOperatorFromStringPattern_EmptyString(t *testing.T) {
assert.Equal(t, GetOperatorFromStringPattern(""), Equal)
}
func TestGetOperatorFromStringPattern_OnlyOperator(t *testing.T) {
assert.Equal(t, GetOperatorFromStringPattern(">="), MoreEqual)
}
func TestGetOperatorFromStringPattern_RangeOperator(t *testing.T) {
assert.Equal(t, GetOperatorFromStringPattern("0-1"), InRange)
assert.Equal(t, GetOperatorFromStringPattern("0Mi-1024Mi"), InRange)
assert.Equal(t, GetOperatorFromStringPattern("0!-1"), NotInRange)
assert.Equal(t, GetOperatorFromStringPattern("0Mi!-1024Mi"), NotInRange)
assert.Equal(t, GetOperatorFromStringPattern("text1024Mi-2048Mi"), Equal)
assert.Equal(t, GetOperatorFromStringPattern("test-value"), Equal)
assert.Equal(t, GetOperatorFromStringPattern("value-*"), Equal)
assert.Equal(t, GetOperatorFromStringPattern("text1024Mi!-2048Mi"), Equal)
assert.Equal(t, GetOperatorFromStringPattern("test!-value"), Equal)
assert.Equal(t, GetOperatorFromStringPattern("value!-*"), Equal)
assert.Equal(t, GetOperatorFromStringPattern("-10--8"), InRange)
assert.Equal(t, GetOperatorFromStringPattern("-10Mi--8Mi"), InRange)
assert.Equal(t, GetOperatorFromStringPattern("-10!--8"), NotInRange)
assert.Equal(t, GetOperatorFromStringPattern("-10Mi!--8Mi"), NotInRange)
assert.Equal(t, GetOperatorFromStringPattern("-10-+8"), InRange)
assert.Equal(t, GetOperatorFromStringPattern("-10Mi-+8Mi"), InRange)
assert.Equal(t, GetOperatorFromStringPattern("-10!-+8"), NotInRange)
assert.Equal(t, GetOperatorFromStringPattern("-10Mi!-+8Mi"), NotInRange)
assert.Equal(t, GetOperatorFromStringPattern("+0-+1"), InRange)
assert.Equal(t, GetOperatorFromStringPattern("+0Mi-+1024Mi"), InRange)
assert.Equal(t, GetOperatorFromStringPattern("+0!-+1"), NotInRange)
assert.Equal(t, GetOperatorFromStringPattern("+0Mi!-+1024Mi"), NotInRange)
}