mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 12:07:47 +00:00
implement code review changes and add basic test
This commit is contained in:
parent
742447f8ce
commit
8eef335dec
@ -510,8 +510,8 @@ func (t *thirdPartyResourceDataEncoder) Encode(obj runtime.Object, stream io.Wri
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprint(stream, string(encBytes))
|
_, err = stream.Write(encBytes)
|
||||||
return nil
|
return err
|
||||||
case *versioned.InternalEvent:
|
case *versioned.InternalEvent:
|
||||||
event := &versioned.Event{}
|
event := &versioned.Event{}
|
||||||
err := versioned.Convert_versioned_InternalEvent_to_versioned_Event(obj, event, nil)
|
err := versioned.Convert_versioned_InternalEvent_to_versioned_Event(obj, event, nil)
|
||||||
|
@ -246,3 +246,41 @@ func TestEncodeToStreamForInternalEvent(t *testing.T) {
|
|||||||
t.Errorf("unexpected error encoding: %v", err)
|
t.Errorf("unexpected error encoding: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestThirdPartyResourceDataListEncoding(t *testing.T) {
|
||||||
|
gv := unversioned.GroupVersion{Group: "stable.foo.faz", Version: "v1"}
|
||||||
|
gvk := gv.WithKind("Bar")
|
||||||
|
e := &thirdPartyResourceDataEncoder{delegate: testapi.Extensions.Codec(), gvk: gvk}
|
||||||
|
subject := &extensions.ThirdPartyResourceDataList{}
|
||||||
|
|
||||||
|
buf := bytes.NewBuffer([]byte{})
|
||||||
|
err := e.Encode(subject, buf)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("encoding unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
targetOutput := struct {
|
||||||
|
Kind string `json:"kind,omitempty"`
|
||||||
|
Items []json.RawMessage `json:"items"`
|
||||||
|
Metadata unversioned.ListMeta `json:"metadata,omitempty"`
|
||||||
|
APIVersion string `json:"apiVersion,omitempty"`
|
||||||
|
}{}
|
||||||
|
err = json.Unmarshal(buf.Bytes(), &targetOutput)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("unmarshal unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if expectedKind := gvk.Kind + "List"; expectedKind != targetOutput.Kind {
|
||||||
|
t.Errorf("unexpected kind on list got %s expected %s", targetOutput.Kind, expectedKind)
|
||||||
|
}
|
||||||
|
|
||||||
|
if targetOutput.Metadata != subject.ListMeta {
|
||||||
|
t.Errorf("metadata mismatch %v != %v", targetOutput.Metadata, subject.ListMeta)
|
||||||
|
}
|
||||||
|
|
||||||
|
if targetOutput.APIVersion != gv.String() {
|
||||||
|
t.Errorf("apiversion mismatch %v != %v", targetOutput.APIVersion, gv.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user