@@ -22,37 +22,17 @@ import (
22
22
23
23
"k8s.io/apimachinery/pkg/runtime"
24
24
"k8s.io/apimachinery/pkg/runtime/schema"
25
+ runtimetesting "k8s.io/apimachinery/pkg/runtime/testing"
25
26
)
26
27
27
- type InternalComplex struct {
28
- runtime.TypeMeta
29
- String string
30
- Integer int
31
- Integer64 int64
32
- Int64 int64
33
- Bool bool
34
- }
35
-
36
- type ExternalComplex struct {
37
- runtime.TypeMeta `json:",inline"`
38
- String string `json:"string" description:"testing"`
39
- Integer int `json:"int"`
40
- Integer64 int64 `json:",omitempty"`
41
- Int64 int64
42
- Bool bool `json:"bool"`
43
- }
44
-
45
- func (obj * InternalComplex ) GetObjectKind () schema.ObjectKind { return & obj .TypeMeta }
46
- func (obj * ExternalComplex ) GetObjectKind () schema.ObjectKind { return & obj .TypeMeta }
47
-
48
28
func TestStringMapConversion (t * testing.T ) {
49
29
internalGV := schema.GroupVersion {Group : "test.group" , Version : runtime .APIVersionInternal }
50
30
externalGV := schema.GroupVersion {Group : "test.group" , Version : "external" }
51
31
52
32
scheme := runtime .NewScheme ()
53
33
scheme .Log (t )
54
- scheme .AddKnownTypeWithName (internalGV .WithKind ("Complex" ), & InternalComplex {})
55
- scheme .AddKnownTypeWithName (externalGV .WithKind ("Complex" ), & ExternalComplex {})
34
+ scheme .AddKnownTypeWithName (internalGV .WithKind ("Complex" ), & runtimetesting. InternalComplex {})
35
+ scheme .AddKnownTypeWithName (externalGV .WithKind ("Complex" ), & runtimetesting. ExternalComplex {})
56
36
57
37
testCases := map [string ]struct {
58
38
input map [string ][]string
@@ -66,62 +46,62 @@ func TestStringMapConversion(t *testing.T) {
66
46
"int" : {"1" },
67
47
"Integer64" : {"2" },
68
48
},
69
- expected : & ExternalComplex {String : "value" , Integer : 1 },
49
+ expected : & runtimetesting. ExternalComplex {String : "value" , Integer : 1 },
70
50
},
71
51
"returns error on bad int" : {
72
52
input : map [string ][]string {
73
53
"int" : {"a" },
74
54
},
75
55
errFn : func (err error ) bool { return err != nil },
76
- expected : & ExternalComplex {},
56
+ expected : & runtimetesting. ExternalComplex {},
77
57
},
78
58
"parses int64" : {
79
59
input : map [string ][]string {
80
60
"Int64" : {"-1" },
81
61
},
82
- expected : & ExternalComplex {Int64 : - 1 },
62
+ expected : & runtimetesting. ExternalComplex {Int64 : - 1 },
83
63
},
84
64
"returns error on bad int64" : {
85
65
input : map [string ][]string {
86
66
"Int64" : {"a" },
87
67
},
88
68
errFn : func (err error ) bool { return err != nil },
89
- expected : & ExternalComplex {},
69
+ expected : & runtimetesting. ExternalComplex {},
90
70
},
91
71
"parses boolean true" : {
92
72
input : map [string ][]string {
93
73
"bool" : {"true" },
94
74
},
95
- expected : & ExternalComplex {Bool : true },
75
+ expected : & runtimetesting. ExternalComplex {Bool : true },
96
76
},
97
77
"parses boolean any value" : {
98
78
input : map [string ][]string {
99
79
"bool" : {"foo" },
100
80
},
101
- expected : & ExternalComplex {Bool : true },
81
+ expected : & runtimetesting. ExternalComplex {Bool : true },
102
82
},
103
83
"parses boolean false" : {
104
84
input : map [string ][]string {
105
85
"bool" : {"false" },
106
86
},
107
- expected : & ExternalComplex {Bool : false },
87
+ expected : & runtimetesting. ExternalComplex {Bool : false },
108
88
},
109
89
"parses boolean empty value" : {
110
90
input : map [string ][]string {
111
91
"bool" : {"" },
112
92
},
113
- expected : & ExternalComplex {Bool : true },
93
+ expected : & runtimetesting. ExternalComplex {Bool : true },
114
94
},
115
95
"parses boolean no value" : {
116
96
input : map [string ][]string {
117
97
"bool" : {},
118
98
},
119
- expected : & ExternalComplex {Bool : false },
99
+ expected : & runtimetesting. ExternalComplex {Bool : false },
120
100
},
121
101
}
122
102
123
103
for k , tc := range testCases {
124
- out := & ExternalComplex {}
104
+ out := & runtimetesting. ExternalComplex {}
125
105
if err := scheme .Convert (& tc .input , out , nil ); (tc .errFn == nil && err != nil ) || (tc .errFn != nil && ! tc .errFn (err )) {
126
106
t .Errorf ("%s: unexpected error: %v" , k , err )
127
107
continue
0 commit comments