@@ -209,38 +209,38 @@ func TestEncode(t *testing.T) {
209
209
},
210
210
},
211
211
{
212
- name : "unsupported marshaler" ,
212
+ name : "text marshaler" ,
213
213
in : & textMarshalerObject {},
214
214
assertOnWriter : func () (io.Writer , func (* testing.T )) {
215
215
var b bytes.Buffer
216
216
return & b , func (t * testing.T ) {
217
- if b . Len () != 0 {
218
- t .Errorf ("expected no bytes to be written, got %d " , b . Len () )
217
+ if diff := cmp . Diff ( b . Bytes (), [] byte { 0xd9 , 0xd9 , 0xf7 , 0x64 , 't' , 'e' , 's' , 't' }); diff != "" {
218
+ t .Errorf ("unexpected diff: \n %s " , diff )
219
219
}
220
220
}
221
221
},
222
222
assertOnError : func (t * testing.T , err error ) {
223
- if want := "unable to serialize *cbor.textMarshalerObject: *cbor.textMarshalerObject implements encoding.TextMarshaler without corresponding cbor interface" ; err == nil || err . Error () != want {
224
- t .Errorf ("expected error %q , got: %v" , want , err )
223
+ if err != nil {
224
+ t .Errorf ("expected nil error , got: %v" , err )
225
225
}
226
226
},
227
227
},
228
228
{
229
- name : "unsupported marshaler within unstructured content" ,
229
+ name : "text marshaler within unstructured content" ,
230
230
in : & unstructured.Unstructured {
231
231
Object : map [string ]interface {}{"" : textMarshalerObject {}},
232
232
},
233
233
assertOnWriter : func () (io.Writer , func (* testing.T )) {
234
234
var b bytes.Buffer
235
235
return & b , func (t * testing.T ) {
236
- if b . Len () != 0 {
237
- t .Errorf ("expected no bytes to be written, got %d " , b . Len () )
236
+ if diff := cmp . Diff ( b . Bytes (), [] byte { 0xd9 , 0xd9 , 0xf7 , 0xa1 , 0x40 , 0x64 , 't' , 'e' , 's' , 't' }); diff != "" {
237
+ t .Errorf ("unexpected diff: \n %s " , diff )
238
238
}
239
239
}
240
240
},
241
241
assertOnError : func (t * testing.T , err error ) {
242
- if want := "unable to serialize map[string]interface {}: cbor.textMarshalerObject implements encoding.TextMarshaler without corresponding cbor interface" ; err == nil || err . Error () != want {
243
- t .Errorf ("expected error %q , got: %v" , want , err )
242
+ if err != nil {
243
+ t .Errorf ("expected nil error , got: %v" , err )
244
244
}
245
245
},
246
246
},
@@ -689,19 +689,6 @@ func TestDecode(t *testing.T) {
689
689
}
690
690
},
691
691
},
692
- {
693
- name : "into unsupported marshaler" ,
694
- data : []byte ("\xa0 " ),
695
- into : & textMarshalerObject {},
696
- metaFactory : stubMetaFactory {gvk : & schema.GroupVersionKind {}},
697
- typer : stubTyper {gvks : []schema.GroupVersionKind {{Version : "v" , Kind : "k" }}},
698
- expectedGVK : & schema.GroupVersionKind {Version : "v" , Kind : "k" },
699
- assertOnError : func (t * testing.T , err error ) {
700
- if want := "unable to serialize *cbor.textMarshalerObject: *cbor.textMarshalerObject implements encoding.TextMarshaler without corresponding cbor interface" ; err == nil || err .Error () != want {
701
- t .Errorf ("expected error %q, got: %v" , want , err )
702
- }
703
- },
704
- },
705
692
} {
706
693
t .Run (tc .name , func (t * testing.T ) {
707
694
s := newSerializer (tc .metaFactory , tc .creater , tc .typer , tc .options ... )
@@ -731,7 +718,7 @@ func (textMarshalerObject) DeepCopyObject() runtime.Object {
731
718
}
732
719
733
720
func (textMarshalerObject ) MarshalText () ([]byte , error ) {
734
- return nil , nil
721
+ return [] byte ( "test" ) , nil
735
722
}
736
723
737
724
func TestMetaFactoryInterpret (t * testing.T ) {
0 commit comments