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/wildcard_test.go
Charles-Edouard Brétéché 5313f0e46f
chore: add a couple unit tests (#5834)
* chore: add LabelSelectorContainsWildcard unit tests

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

* tombstone tests

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

* ConvertToUnstructured tests

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

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-01-03 09:56:57 +01:00

50 lines
1.6 KiB
Go

package kube
import (
"testing"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestLabelSelectorContainsWildcardPositive(t *testing.T) {
// Test that the LabelSelectorContainsWildcard function returns true when a wildcard is present in the MatchLabels map
selector := &metav1.LabelSelector{
MatchLabels: map[string]string{
"key": "val*",
},
}
result := LabelSelectorContainsWildcard(selector)
if !result {
t.Errorf("Expected LabelSelectorContainsWildcard to return true, got %v", result)
}
}
func TestLabelSelectorContainsWildcardNegative(t *testing.T) {
// Test that the LabelSelectorContainsWildcard function returns false when no wildcards are present in the MatchLabels map
selector := &metav1.LabelSelector{
MatchLabels: map[string]string{
"key": "val",
},
}
result := LabelSelectorContainsWildcard(selector)
if result {
t.Errorf("Expected LabelSelectorContainsWildcard to return false, got %v", result)
}
}
func TestLabelSelectorContainsWildcardEmptySelector(t *testing.T) {
// Test that the LabelSelectorContainsWildcard function returns false when given an empty LabelSelector
var selector metav1.LabelSelector
result := LabelSelectorContainsWildcard(&selector)
if result {
t.Errorf("Expected LabelSelectorContainsWildcard to return false, got %v", result)
}
}
func TestLabelSelectorContainsWildcardNilSelector(t *testing.T) {
// Test that the LabelSelectorContainsWildcard function returns false when given a nil LabelSelector
result := LabelSelectorContainsWildcard(nil)
if result {
t.Errorf("Expected LabelSelectorContainsWildcard to return false, got %v", result)
}
}