1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-10 09:56:55 +00:00
kyverno/test/e2e/framework/resource/resource.go
Charles-Edouard Brétéché e1db7c9814
feat: add e2e framework and verify image new test (#4094)
Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
2022-06-09 21:58:07 +08:00

32 lines
922 B
Go

package resource
import (
"github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/yaml"
)
type Resource struct {
gvr schema.GroupVersionResource
ns string
data []byte
}
func (r *Resource) Gvr() schema.GroupVersionResource { return r.gvr }
func (r *Resource) Namespace() string { return r.ns }
func (r *Resource) Data() []byte { return r.data }
func (r *Resource) IsClustered() bool { return r.ns == "" }
func (r *Resource) IsNamespaced() bool { return !r.IsClustered() }
func (r *Resource) Unstructured() *unstructured.Unstructured {
var u unstructured.Unstructured
gomega.Expect(yaml.Unmarshal(r.data, &u)).To(gomega.Succeed())
// TODO: set namespace ?
// TODO: ensure GV(R/K) ?
return &u
}
func Resources(resources ...Resource) []Resource {
return resources
}