...
1
16
17 package testing
18
19 import (
20 "k8s.io/apimachinery/pkg/runtime/schema"
21 "k8s.io/kube-openapi/pkg/util/proto"
22 "k8s.io/kube-openapi/pkg/util/proto/testing"
23 "k8s.io/kubectl/pkg/util/openapi"
24 )
25
26
27
28
29 type FakeResources struct {
30 fake testing.Fake
31 }
32
33 var _ openapi.Resources = &FakeResources{}
34
35
36 func NewFakeResources(path string) *FakeResources {
37 return &FakeResources{
38 fake: testing.Fake{Path: path},
39 }
40 }
41
42
43
44 func (f *FakeResources) LookupResource(gvk schema.GroupVersionKind) proto.Schema {
45 s, err := f.fake.OpenAPISchema()
46 if err != nil {
47 panic(err)
48 }
49 resources, err := openapi.NewOpenAPIData(s)
50 if err != nil {
51 panic(err)
52 }
53 return resources.LookupResource(gvk)
54 }
55
56 func (f *FakeResources) GetConsumes(gvk schema.GroupVersionKind, operation string) []string {
57 s, err := f.fake.OpenAPISchema()
58 if err != nil {
59 panic(err)
60 }
61
62 resources, err := openapi.NewOpenAPIData(s)
63 if err != nil {
64 panic(err)
65 }
66 return resources.GetConsumes(gvk, operation)
67 }
68
69
70 type EmptyResources struct{}
71
72 var _ openapi.Resources = EmptyResources{}
73
74
75 func (f EmptyResources) LookupResource(gvk schema.GroupVersionKind) proto.Schema {
76 return nil
77 }
78
79 func (f EmptyResources) GetConsumes(gvk schema.GroupVersionKind, operation string) []string {
80 return nil
81 }
82
83
84 func CreateOpenAPISchemaFunc(path string) func() (openapi.Resources, error) {
85 return func() (openapi.Resources, error) {
86 return NewFakeResources(path), nil
87 }
88 }
89
View as plain text