openapi_test.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. Copyright 2017 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package openapi_test
  14. import (
  15. "path/filepath"
  16. . "github.com/onsi/ginkgo"
  17. . "github.com/onsi/gomega"
  18. "k8s.io/apimachinery/pkg/runtime/schema"
  19. "k8s.io/kube-openapi/pkg/util/proto"
  20. "k8s.io/kube-openapi/pkg/util/proto/testing"
  21. "k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
  22. )
  23. var fakeSchema = testing.Fake{Path: filepath.Join("..", "..", "..", "..", "..", "api", "openapi-spec", "swagger.json")}
  24. var _ = Describe("Reading apps/v1beta1/Deployment from openAPIData", func() {
  25. var resources openapi.Resources
  26. BeforeEach(func() {
  27. s, err := fakeSchema.OpenAPISchema()
  28. Expect(err).To(BeNil())
  29. resources, err = openapi.NewOpenAPIData(s)
  30. Expect(err).To(BeNil())
  31. })
  32. gvk := schema.GroupVersionKind{
  33. Kind: "Deployment",
  34. Version: "v1beta1",
  35. Group: "apps",
  36. }
  37. var schema proto.Schema
  38. It("should lookup the Schema by its GroupVersionKind", func() {
  39. schema = resources.LookupResource(gvk)
  40. Expect(schema).ToNot(BeNil())
  41. })
  42. var deployment *proto.Kind
  43. It("should be a Kind", func() {
  44. deployment = schema.(*proto.Kind)
  45. Expect(deployment).ToNot(BeNil())
  46. })
  47. })
  48. var _ = Describe("Reading authorization.k8s.io/v1/SubjectAccessReview from openAPIData", func() {
  49. var resources openapi.Resources
  50. BeforeEach(func() {
  51. s, err := fakeSchema.OpenAPISchema()
  52. Expect(err).To(BeNil())
  53. resources, err = openapi.NewOpenAPIData(s)
  54. Expect(err).To(BeNil())
  55. })
  56. gvk := schema.GroupVersionKind{
  57. Kind: "SubjectAccessReview",
  58. Version: "v1",
  59. Group: "authorization.k8s.io",
  60. }
  61. var schema proto.Schema
  62. It("should lookup the Schema by its GroupVersionKind", func() {
  63. schema = resources.LookupResource(gvk)
  64. Expect(schema).ToNot(BeNil())
  65. })
  66. var sarspec *proto.Kind
  67. It("should be a Kind and have a spec", func() {
  68. sar := schema.(*proto.Kind)
  69. Expect(sar).ToNot(BeNil())
  70. Expect(sar.Fields).To(HaveKey("spec"))
  71. specRef := sar.Fields["spec"].(proto.Reference)
  72. Expect(specRef).ToNot(BeNil())
  73. Expect(specRef.Reference()).To(Equal("io.k8s.api.authorization.v1.SubjectAccessReviewSpec"))
  74. sarspec = specRef.SubSchema().(*proto.Kind)
  75. Expect(sarspec).ToNot(BeNil())
  76. })
  77. })