func TestDecodeToMetadataOnlyObject(t *testing.T) { data := getPodJson(t) cf := serializer.DirectCodecFactory{CodecFactory: NewMetadataCodecFactory()} serializer, ok := cf.SerializerForMediaType(runtime.ContentTypeJSON, nil) if !ok { t.Fatalf("expected to get a JSON serializer") } codec := cf.DecoderToVersion(serializer, unversioned.GroupVersion{Group: "SOMEGROUP", Version: "SOMEVERSION"}) // decode with into into := &MetadataOnlyObject{} ret, _, err := codec.Decode(data, nil, into) if err != nil { t.Fatal(err) } metaOnly, ok := ret.(*MetadataOnlyObject) if !ok { t.Fatalf("expected ret to be *runtime.MetadataOnlyObject") } verfiyMetadata("check returned metaonly with into", t, metaOnly) verfiyMetadata("check into", t, into) // decode without into ret, _, err = codec.Decode(data, nil, nil) if err != nil { t.Fatal(err) } metaOnly, ok = ret.(*MetadataOnlyObject) if !ok { t.Fatalf("expected ret to be *runtime.MetadataOnlyObject") } verfiyMetadata("check returned metaonly without into", t, metaOnly) }
func TestDecodeToMetadataOnlyObjectList(t *testing.T) { data := getPodListJson(t) cf := serializer.DirectCodecFactory{CodecFactory: NewMetadataCodecFactory()} info, ok := runtime.SerializerInfoForMediaType(cf.SupportedMediaTypes(), runtime.ContentTypeJSON) if !ok { t.Fatalf("expected to get a JSON serializer") } codec := cf.DecoderToVersion(info.Serializer, unversioned.GroupVersion{Group: "SOMEGROUP", Version: "SOMEVERSION"}) // decode with into into := &MetadataOnlyObjectList{} ret, _, err := codec.Decode(data, nil, into) if err != nil { t.Fatal(err) } metaOnlyList, ok := ret.(*MetadataOnlyObjectList) if !ok { t.Fatalf("expected ret to be *runtime.UnstructuredList") } verifyListMetadata(t, metaOnlyList) verifyListMetadata(t, into) // decode without into ret, _, err = codec.Decode(data, nil, nil) if err != nil { t.Fatal(err) } metaOnlyList, ok = ret.(*MetadataOnlyObjectList) if !ok { t.Fatalf("expected ret to be *runtime.UnstructuredList") } verifyListMetadata(t, metaOnlyList) }