...
1
16
17 package openapi_test
18
19 import (
20 "path/filepath"
21
22 . "github.com/onsi/ginkgo/v2"
23 . "github.com/onsi/gomega"
24
25 "k8s.io/apimachinery/pkg/runtime/schema"
26 "k8s.io/kube-openapi/pkg/util/proto"
27 "k8s.io/kube-openapi/pkg/util/proto/testing"
28 "k8s.io/kubectl/pkg/util/openapi"
29 )
30
31 var fakeSchema = testing.Fake{Path: filepath.Join("..", "..", "..", "testdata", "openapi", "swagger.json")}
32
33 var _ = Describe("Reading apps/v1/Deployment from openAPIData", func() {
34 var resources openapi.Resources
35 BeforeEach(func() {
36 s, err := fakeSchema.OpenAPISchema()
37 Expect(err).ToNot(HaveOccurred())
38 resources, err = openapi.NewOpenAPIData(s)
39 Expect(err).ToNot(HaveOccurred())
40 })
41
42 gvk := schema.GroupVersionKind{
43 Kind: "Deployment",
44 Version: "v1",
45 Group: "apps",
46 }
47
48 var schema proto.Schema
49 It("should lookup the Schema by its GroupVersionKind", func() {
50 schema = resources.LookupResource(gvk)
51 Expect(schema).ToNot(BeNil())
52 Expect(schema.(*proto.Kind)).ToNot(BeNil())
53 consumes := resources.GetConsumes(gvk, "PATCH")
54 Expect(consumes).ToNot(BeNil())
55 Expect(consumes).To(HaveLen(4))
56 })
57 })
58
59 var _ = Describe("Reading authorization.k8s.io/v1/SubjectAccessReview from openAPIData", func() {
60 var resources openapi.Resources
61 BeforeEach(func() {
62 s, err := fakeSchema.OpenAPISchema()
63 Expect(err).ToNot(HaveOccurred())
64 resources, err = openapi.NewOpenAPIData(s)
65 Expect(err).ToNot(HaveOccurred())
66 })
67
68 gvk := schema.GroupVersionKind{
69 Kind: "SubjectAccessReview",
70 Version: "v1",
71 Group: "authorization.k8s.io",
72 }
73
74 var schema proto.Schema
75 It("should lookup the Schema by its GroupVersionKind", func() {
76 schema = resources.LookupResource(gvk)
77 Expect(schema).ToNot(BeNil())
78 sar := schema.(*proto.Kind)
79 Expect(sar).ToNot(BeNil())
80 Expect(sar.Fields).To(HaveKey("spec"))
81 specRef := sar.Fields["spec"].(proto.Reference)
82 Expect(specRef).ToNot(BeNil())
83 Expect(specRef.Reference()).To(Equal("io.k8s.api.authorization.v1.SubjectAccessReviewSpec"))
84 Expect(specRef.SubSchema().(*proto.Kind)).ToNot(BeNil())
85 })
86 })
87
View as plain text