Remaining refactor for PodTemplateSpec and fixing test cases
This commit is contained in:
@@ -90,6 +90,23 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
|
||||
statuses := []api.PodCondition{api.PodPending, api.PodRunning, api.PodFailed}
|
||||
*j = statuses[c.Rand.Intn(len(statuses))]
|
||||
},
|
||||
func(j *api.ReplicationControllerSpec, c fuzz.Continue) {
|
||||
// TemplateRef must be nil for round trip
|
||||
c.Fuzz(&j.Template)
|
||||
if j.Template == nil {
|
||||
// TODO: v1beta1/2 can't round trip a nil template correctly, fix by having v1beta1/2
|
||||
// conversion compare converted object to nil via DeepEqual
|
||||
j.Template = &api.PodTemplateSpec{}
|
||||
}
|
||||
j.Template.ObjectMeta = api.ObjectMeta{Labels: j.Template.ObjectMeta.Labels}
|
||||
j.Template.Spec.NodeSelector = nil
|
||||
c.Fuzz(&j.Selector)
|
||||
j.Replicas = int(c.RandUint64())
|
||||
},
|
||||
func(j *api.ReplicationControllerStatus, c fuzz.Continue) {
|
||||
// only replicas round trips
|
||||
j.Replicas = int(c.RandUint64())
|
||||
},
|
||||
func(intstr *util.IntOrString, c fuzz.Continue) {
|
||||
// util.IntOrString will panic if its kind is set wrong.
|
||||
if c.RandBool() {
|
||||
@@ -176,18 +193,21 @@ func TestSpecificKind(t *testing.T) {
|
||||
api.Scheme.Log(nil)
|
||||
}
|
||||
|
||||
func TestTypes(t *testing.T) {
|
||||
var nonRoundTrippableTypes = util.NewStringSet("ContainerManifest")
|
||||
|
||||
func TestRoundTripTypes(t *testing.T) {
|
||||
for kind := range api.Scheme.KnownTypes("") {
|
||||
if nonRoundTrippableTypes.Has(kind) {
|
||||
continue
|
||||
}
|
||||
// Try a few times, since runTest uses random values.
|
||||
for i := 0; i < *fuzzIters; i++ {
|
||||
item, err := api.Scheme.New("", kind)
|
||||
if err != nil {
|
||||
t.Errorf("Couldn't make a %v? %v", kind, err)
|
||||
continue
|
||||
t.Fatalf("Couldn't make a %v? %v", kind, err)
|
||||
}
|
||||
if _, err := meta.Accessor(item); err != nil {
|
||||
t.Logf("%s is not a TypeMeta and cannot be round tripped: %v", kind, err)
|
||||
continue
|
||||
t.Fatalf("%q is not a TypeMeta and cannot be tested - add it to nonRoundTrippableTypes: %v", kind, err)
|
||||
}
|
||||
runTest(t, v1beta1.Codec, item)
|
||||
runTest(t, v1beta2.Codec, item)
|
||||
|
Reference in New Issue
Block a user