1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-09 01:16:55 +00:00
kyverno/pkg/utils/kube/wildcard_test.go

51 lines
1.6 KiB
Go
Raw Normal View History

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)
}
}