mirror of https://github.com/k3s-io/k3s
Pointer receiver support for MarshalQueryParameter()
parent
01e961b380
commit
0fe4911744
|
@ -34,3 +34,21 @@ func TestUnstructuredList(t *testing.T) {
|
||||||
t.Fatalf("unexpected fields: %#v", items[0])
|
t.Fatalf("unexpected fields: %#v", items[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNilDeletionTimestamp(t *testing.T) {
|
||||||
|
var u Unstructured
|
||||||
|
del := u.GetDeletionTimestamp()
|
||||||
|
if del != nil {
|
||||||
|
t.Errorf("unexpected non-nil deletion timestamp: %v", del)
|
||||||
|
}
|
||||||
|
u.SetDeletionTimestamp(u.GetDeletionTimestamp())
|
||||||
|
del = u.GetDeletionTimestamp()
|
||||||
|
if del != nil {
|
||||||
|
t.Errorf("unexpected non-nil deletion timestamp: %v", del)
|
||||||
|
}
|
||||||
|
metadata := u.Object["metadata"].(map[string]interface{})
|
||||||
|
deletionTimestamp := metadata["deletionTimestamp"]
|
||||||
|
if deletionTimestamp != nil {
|
||||||
|
t.Errorf("unexpected deletion timestamp field: %q", deletionTimestamp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -90,7 +90,14 @@ func customMarshalValue(value reflect.Value) (reflect.Value, bool) {
|
||||||
|
|
||||||
marshaler, ok := value.Interface().(Marshaler)
|
marshaler, ok := value.Interface().(Marshaler)
|
||||||
if !ok {
|
if !ok {
|
||||||
return reflect.Value{}, false
|
if !isPointerKind(value.Kind()) && value.CanAddr() {
|
||||||
|
marshaler, ok = value.Addr().Interface().(Marshaler)
|
||||||
|
if !ok {
|
||||||
|
return reflect.Value{}, false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return reflect.Value{}, false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't invoke functions on nil pointers
|
// Don't invoke functions on nil pointers
|
||||||
|
|
|
@ -66,12 +66,13 @@ func (obj *baz) GetObjectKind() schema.ObjectKind { return schema.EmptyObjectKin
|
||||||
// childStructs tests some of the types we serialize to query params for log API calls
|
// childStructs tests some of the types we serialize to query params for log API calls
|
||||||
// notably, the nested time struct
|
// notably, the nested time struct
|
||||||
type childStructs struct {
|
type childStructs struct {
|
||||||
Container string `json:"container,omitempty"`
|
Container string `json:"container,omitempty"`
|
||||||
Follow bool `json:"follow,omitempty"`
|
Follow bool `json:"follow,omitempty"`
|
||||||
Previous bool `json:"previous,omitempty"`
|
Previous bool `json:"previous,omitempty"`
|
||||||
SinceSeconds *int64 `json:"sinceSeconds,omitempty"`
|
SinceSeconds *int64 `json:"sinceSeconds,omitempty"`
|
||||||
SinceTime *metav1.Time `json:"sinceTime,omitempty"`
|
SinceTime *metav1.Time `json:"sinceTime,omitempty"`
|
||||||
EmptyTime *metav1.Time `json:"emptyTime"`
|
EmptyTime *metav1.Time `json:"emptyTime"`
|
||||||
|
NonPointerTime metav1.Time `json:"nonPointerTime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (obj *childStructs) GetObjectKind() schema.ObjectKind { return schema.EmptyObjectKind }
|
func (obj *childStructs) GetObjectKind() schema.ObjectKind { return schema.EmptyObjectKind }
|
||||||
|
@ -177,24 +178,26 @@ func TestConvert(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
input: &childStructs{
|
input: &childStructs{
|
||||||
Container: "mycontainer",
|
Container: "mycontainer",
|
||||||
Follow: true,
|
Follow: true,
|
||||||
Previous: true,
|
Previous: true,
|
||||||
SinceSeconds: &sinceSeconds,
|
SinceSeconds: &sinceSeconds,
|
||||||
SinceTime: &sinceTime, // test a custom marshaller
|
SinceTime: &sinceTime, // test a custom marshaller
|
||||||
EmptyTime: nil, // test a nil custom marshaller without omitempty
|
EmptyTime: nil, // test a nil custom marshaller without omitempty
|
||||||
|
NonPointerTime: sinceTime,
|
||||||
},
|
},
|
||||||
expected: url.Values{"container": {"mycontainer"}, "follow": {"true"}, "previous": {"true"}, "sinceSeconds": {"123"}, "sinceTime": {"2000-01-01T12:34:56Z"}, "emptyTime": {""}},
|
expected: url.Values{"container": {"mycontainer"}, "follow": {"true"}, "previous": {"true"}, "sinceSeconds": {"123"}, "sinceTime": {"2000-01-01T12:34:56Z"}, "emptyTime": {""}, "nonPointerTime": {"2000-01-01T12:34:56Z"}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
input: &childStructs{
|
input: &childStructs{
|
||||||
Container: "mycontainer",
|
Container: "mycontainer",
|
||||||
Follow: true,
|
Follow: true,
|
||||||
Previous: true,
|
Previous: true,
|
||||||
SinceSeconds: &sinceSeconds,
|
SinceSeconds: &sinceSeconds,
|
||||||
SinceTime: nil, // test a nil custom marshaller with omitempty
|
SinceTime: nil, // test a nil custom marshaller with omitempty
|
||||||
|
NonPointerTime: sinceTime,
|
||||||
},
|
},
|
||||||
expected: url.Values{"container": {"mycontainer"}, "follow": {"true"}, "previous": {"true"}, "sinceSeconds": {"123"}, "emptyTime": {""}},
|
expected: url.Values{"container": {"mycontainer"}, "follow": {"true"}, "previous": {"true"}, "sinceSeconds": {"123"}, "emptyTime": {""}, "nonPointerTime": {"2000-01-01T12:34:56Z"}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue