2020-01-07 17:06:17 -08:00
|
|
|
package utils
|
|
|
|
|
2020-01-24 09:37:12 -08:00
|
|
|
import (
|
2020-01-07 17:06:17 -08:00
|
|
|
"encoding/json"
|
2020-01-24 09:37:12 -08:00
|
|
|
"testing"
|
2020-07-29 21:41:58 +05:30
|
|
|
|
|
|
|
"gotest.tools/assert"
|
2020-01-07 17:06:17 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetAnchorsFromMap_ThereAreNoAnchors(t *testing.T) {
|
|
|
|
rawMap := []byte(`{
|
|
|
|
"name":"nirmata-*",
|
|
|
|
"notAnchor1":123,
|
|
|
|
"namespace":"kube-?olicy",
|
|
|
|
"notAnchor2":"sample-text",
|
|
|
|
"object":{
|
|
|
|
"key1":"value1",
|
|
|
|
"(key2)":"value2"
|
|
|
|
}
|
|
|
|
}`)
|
|
|
|
|
|
|
|
var unmarshalled map[string]interface{}
|
2020-01-24 09:37:12 -08:00
|
|
|
err := json.Unmarshal(rawMap, &unmarshalled)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2020-01-07 17:06:17 -08:00
|
|
|
actualMap := GetAnchorsFromMap(unmarshalled)
|
|
|
|
assert.Assert(t, len(actualMap) == 0)
|
2020-01-24 09:37:12 -08:00
|
|
|
}
|