mirror of https://github.com/k3s-io/k3s
defaults_tests: verify defaults when converting to an API object
This change verifies that defaults are applied after decoding an versioned object into an API object.pull/6/head
parent
e2dcf29878
commit
7b0e45a5f5
|
@ -1507,7 +1507,8 @@ type ContainerManifest struct {
|
||||||
Containers []Container `json:"containers"`
|
Containers []Container `json:"containers"`
|
||||||
RestartPolicy RestartPolicy `json:"restartPolicy,omitempty"`
|
RestartPolicy RestartPolicy `json:"restartPolicy,omitempty"`
|
||||||
// Required: Set DNS policy.
|
// Required: Set DNS policy.
|
||||||
DNSPolicy DNSPolicy `json:"dnsPolicy"`
|
DNSPolicy DNSPolicy `json:"dnsPolicy"`
|
||||||
|
HostNetwork bool `json:"hostNetwork,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainerManifestList is used to communicate container manifests to kubelet.
|
// ContainerManifestList is used to communicate container manifests to kubelet.
|
||||||
|
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
current "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
|
current "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
)
|
)
|
||||||
|
@ -30,13 +31,18 @@ func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
|
||||||
t.Errorf("%v\n %#v", err, obj)
|
t.Errorf("%v\n %#v", err, obj)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
obj2 := reflect.New(reflect.TypeOf(obj).Elem()).Interface().(runtime.Object)
|
obj2, err := newer.Codec.Decode(data)
|
||||||
err = current.Codec.DecodeInto(data, obj2)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%v\nData: %s\nSource: %#v", err, string(data), obj)
|
t.Errorf("%v\nData: %s\nSource: %#v", err, string(data), obj)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return obj2
|
obj3 := reflect.New(reflect.TypeOf(obj).Elem()).Interface().(runtime.Object)
|
||||||
|
err = newer.Scheme.Convert(obj2, obj3)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%v\nSource: %#v", err, obj2)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return obj3
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetDefaultService(t *testing.T) {
|
func TestSetDefaultService(t *testing.T) {
|
||||||
|
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
current "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta2"
|
current "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta2"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
)
|
)
|
||||||
|
@ -30,13 +31,18 @@ func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
|
||||||
t.Errorf("%v\n %#v", err, obj)
|
t.Errorf("%v\n %#v", err, obj)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
obj2 := reflect.New(reflect.TypeOf(obj).Elem()).Interface().(runtime.Object)
|
obj2, err := newer.Codec.Decode(data)
|
||||||
err = current.Codec.DecodeInto(data, obj2)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%v\nData: %s\nSource: %#v", err, string(data), obj)
|
t.Errorf("%v\nData: %s\nSource: %#v", err, string(data), obj)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return obj2
|
obj3 := reflect.New(reflect.TypeOf(obj).Elem()).Interface().(runtime.Object)
|
||||||
|
err = newer.Scheme.Convert(obj2, obj3)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%v\nSource: %#v", err, obj2)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return obj3
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetDefaultService(t *testing.T) {
|
func TestSetDefaultService(t *testing.T) {
|
||||||
|
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
current "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3"
|
current "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
|
@ -31,13 +32,18 @@ func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
|
||||||
t.Errorf("%v\n %#v", err, obj)
|
t.Errorf("%v\n %#v", err, obj)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
obj2 := reflect.New(reflect.TypeOf(obj).Elem()).Interface().(runtime.Object)
|
obj2, err := newer.Codec.Decode(data)
|
||||||
err = current.Codec.DecodeInto(data, obj2)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%v\nData: %s\nSource: %#v", err, string(data), obj)
|
t.Errorf("%v\nData: %s\nSource: %#v", err, string(data), obj)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return obj2
|
obj3 := reflect.New(reflect.TypeOf(obj).Elem()).Interface().(runtime.Object)
|
||||||
|
err = newer.Scheme.Convert(obj2, obj3)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%v\nSource: %#v", err, obj2)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return obj3
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetDefaultService(t *testing.T) {
|
func TestSetDefaultService(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue