@@ -102,6 +102,28 @@ func TestNestedEncode(t *testing.T) {
102
102
}
103
103
}
104
104
105
+ func TestNestedEncodeError (t * testing.T ) {
106
+ n := & testNestedDecodable {nestedErr : fmt .Errorf ("unable to encode" )}
107
+ gvk1 := schema.GroupVersionKind {Kind : "test" , Group : "other" , Version : "v1" }
108
+ gvk2 := schema.GroupVersionKind {Kind : "test" , Group : "other" , Version : "v2" }
109
+ n .SetGroupVersionKind (gvk1 )
110
+ codec := NewCodec (
111
+ nil , nil ,
112
+ & mockConvertor {},
113
+ nil ,
114
+ & mockTyper {gvks : []schema.GroupVersionKind {gvk1 , gvk2 }},
115
+ nil ,
116
+ schema.GroupVersion {Group : "other" , Version : "v2" }, nil ,
117
+ "TestNestedEncodeError" ,
118
+ )
119
+ if err := codec .Encode (n , ioutil .Discard ); err != n .nestedErr {
120
+ t .Errorf ("unexpected error: %v" , err )
121
+ }
122
+ if n .GroupVersionKind () != gvk1 {
123
+ t .Errorf ("unexpected gvk of input object: %v" , n .GroupVersionKind ())
124
+ }
125
+ }
126
+
105
127
func TestDecode (t * testing.T ) {
106
128
gvk1 := & schema.GroupVersionKind {Kind : "Test" , Group : "other" , Version : "blah" }
107
129
decodable1 := & testDecodable {}
@@ -311,6 +333,28 @@ func (c *checkConvertor) ConvertFieldLabel(gvk schema.GroupVersionKind, label, v
311
333
return "" , "" , fmt .Errorf ("unexpected call to ConvertFieldLabel" )
312
334
}
313
335
336
+ type mockConvertor struct {
337
+ }
338
+
339
+ func (c * mockConvertor ) Convert (in , out , context interface {}) error {
340
+ return fmt .Errorf ("unexpect call to Convert" )
341
+ }
342
+
343
+ func (c * mockConvertor ) ConvertToVersion (in runtime.Object , outVersion runtime.GroupVersioner ) (out runtime.Object , err error ) {
344
+ objectKind := in .GetObjectKind ()
345
+ inGVK := objectKind .GroupVersionKind ()
346
+ if out , ok := outVersion .KindForGroupVersionKinds ([]schema.GroupVersionKind {inGVK }); ok {
347
+ objectKind .SetGroupVersionKind (out )
348
+ } else {
349
+ return nil , fmt .Errorf ("unexpected conversion" )
350
+ }
351
+ return in , nil
352
+ }
353
+
354
+ func (c * mockConvertor ) ConvertFieldLabel (gvk schema.GroupVersionKind , label , value string ) (string , string , error ) {
355
+ return "" , "" , fmt .Errorf ("unexpected call to ConvertFieldLabel" )
356
+ }
357
+
314
358
type mockSerializer struct {
315
359
err error
316
360
obj runtime.Object
0 commit comments