...
1
16
17 package explain
18
19 import (
20 "testing"
21
22 "k8s.io/apimachinery/pkg/runtime/schema"
23 tst "k8s.io/kubectl/pkg/util/openapi/testing"
24 )
25
26 var resources = tst.NewFakeResources("test-swagger.json")
27
28 func TestReferenceTypename(t *testing.T) {
29 schema := resources.LookupResource(schema.GroupVersionKind{
30 Group: "",
31 Version: "v1",
32 Kind: "OneKind",
33 })
34 if schema == nil {
35 t.Fatal("Couldn't find schema v1.OneKind")
36 }
37
38 tests := []struct {
39 name string
40 path []string
41 expected string
42 }{
43 {
44
45 name: "test1",
46 path: []string{},
47 expected: "Object",
48 },
49 {
50
51 name: "test2",
52 path: []string{"field1"},
53 expected: "Object",
54 },
55 {
56
57 name: "test3",
58 path: []string{"field1", "primitive"},
59 expected: "string",
60 },
61 {
62
63 name: "test4",
64 path: []string{"field2"},
65 expected: "[]map[string]string",
66 },
67 {
68
69 name: "test5",
70 path: []string{"field1", "array"},
71 expected: "[]integer",
72 },
73 }
74
75 for _, tt := range tests {
76 t.Run(tt.name, func(t *testing.T) {
77 s, err := LookupSchemaForField(schema, tt.path)
78 if err != nil {
79 t.Fatalf("Invalid tt.path %v: %v", tt.path, err)
80 }
81 got := GetTypeName(s)
82 if got != tt.expected {
83 t.Errorf("Got %q, expected %q", got, tt.expected)
84 }
85 })
86 }
87
88 }
89
View as plain text