1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-15 17:51:20 +00:00
kyverno/pkg/engine/apiPath_test.go
Joshua Snider b0fd2403e8 Add unit test
Signed-off-by: Joshua Snider <jsnider@mtu.edu>
2021-03-08 22:56:14 -05:00

51 lines
1.6 KiB
Go

package engine
import (
"testing"
)
func Test_Paths(t *testing.T) {
f := func(path, expected string) {
p, err := NewAPIPath(path)
if err != nil {
t.Error(err)
return
}
if p.String() != expected {
t.Errorf("expected %s got %s", expected, p.String())
}
}
f("/api/v1/namespace/{{ request.namespace }}", "/api/v1/namespace/{{ request.namespace }}")
f("/api/v1/namespace/{{ request.namespace }}/", "/api/v1/namespace/{{ request.namespace }}")
f("/api/v1/namespace/{{ request.namespace }}/ ", "/api/v1/namespace/{{ request.namespace }}")
f(" /api/v1/namespace/{{ request.namespace }}", "/api/v1/namespace/{{ request.namespace }}")
f("/apis/gloo.solo.io/v1/namespaces/gloo-system/upstreams", "/apis/gloo.solo.io/v1/namespaces/gloo-system/upstreams")
f("/apis/gloo.solo.io/v1/namespaces/gloo-system/upstreams/", "/apis/gloo.solo.io/v1/namespaces/gloo-system/upstreams")
f("/apis/gloo.solo.io/v1/namespaces/gloo-system/upstreams/ ", "/apis/gloo.solo.io/v1/namespaces/gloo-system/upstreams")
f(" /apis/gloo.solo.io/v1/namespaces/gloo-system/upstreams", "/apis/gloo.solo.io/v1/namespaces/gloo-system/upstreams")
}
func Test_GroupVersions(t *testing.T) {
f := func(path, expected string) {
p, err := NewAPIPath(path)
if err != nil {
t.Error(err)
return
}
if p.Root == "api" {
if p.Group != expected {
t.Errorf("expected %s got %s", expected, p.Group)
}
} else {
if p.Version != expected {
t.Errorf("expected %s got %s", expected, p.Version)
}
}
}
f("/api/v1/namespace/{{ request.namespace }}", "v1")
f("/apis/extensions/v1beta1/namespaces/example/ingresses", "extensions/v1beta1")
}