mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-06 07:57:07 +00:00
28 lines
935 B
Go
28 lines
935 B
Go
|
package wildcards
|
||
|
|
||
|
import (
|
||
|
"reflect"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestExpandInMetadata(t *testing.T) {
|
||
|
//testExpand(t, map[string]string{"test/*": "*"}, map[string]string{},
|
||
|
// map[string]string{"test/0": "0"})
|
||
|
|
||
|
testExpand(t, map[string]string{"test/*": "*"}, map[string]string{"test/test": "test"},
|
||
|
map[string]interface{}{"test/test": "*"})
|
||
|
|
||
|
testExpand(t, map[string]string{"=(test/*)": "test"}, map[string]string{"test/test": "test"},
|
||
|
map[string]interface{}{"=(test/test)": "test"})
|
||
|
|
||
|
testExpand(t, map[string]string{"test/*": "*"}, map[string]string{"test/test1": "test1", "test/test2": "test2"},
|
||
|
map[string]interface{}{"test/test1": "*"})
|
||
|
}
|
||
|
|
||
|
func testExpand(t *testing.T, patternMap, resourceMap map[string]string, expectedMap map[string]interface{}) {
|
||
|
result := replaceWildcardsInMapKeys(patternMap, resourceMap)
|
||
|
if !reflect.DeepEqual(expectedMap, result) {
|
||
|
t.Errorf("expected %v but received %v", expectedMap, result)
|
||
|
}
|
||
|
}
|