diff --git a/pkg/api/validation/validation_test.go b/pkg/api/validation/validation_test.go index d0d51354ae0..70168696b8f 100644 --- a/pkg/api/validation/validation_test.go +++ b/pkg/api/validation/validation_test.go @@ -5910,8 +5910,8 @@ func TestValidatePodUpdate(t *testing.T) { ) tests := []struct { - a api.Pod - b api.Pod + new api.Pod + old api.Pod err string test string }{ @@ -5993,6 +5993,35 @@ func TestValidatePodUpdate(t *testing.T) { }, }, "may not add or remove containers", + "less containers", + }, + { + api.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + }, + Spec: api.PodSpec{ + Containers: []api.Container{ + { + Image: "foo:V1", + }, + { + Image: "bar:V2", + }, + }, + }, + }, + api.Pod{ + ObjectMeta: metav1.ObjectMeta{Name: "foo"}, + Spec: api.PodSpec{ + Containers: []api.Container{ + { + Image: "foo:V2", + }, + }, + }, + }, + "may not add or remove containers", "more containers", }, { @@ -6034,7 +6063,19 @@ func TestValidatePodUpdate(t *testing.T) { Spec: api.PodSpec{Containers: []api.Container{{Image: "foo:V1"}}}, }, "", - "deletion timestamp filled out", + "deletion timestamp removed", + }, + { + api.Pod{ + ObjectMeta: metav1.ObjectMeta{Name: "foo", DeletionTimestamp: &now}, + Spec: api.PodSpec{Containers: []api.Container{{Image: "foo:V1"}}}, + }, + api.Pod{ + ObjectMeta: metav1.ObjectMeta{Name: "foo"}, + Spec: api.PodSpec{Containers: []api.Container{{Image: "foo:V1"}}}, + }, + "metadata.deletionTimestamp", + "deletion timestamp added", }, { api.Pod{ @@ -6046,7 +6087,7 @@ func TestValidatePodUpdate(t *testing.T) { Spec: api.PodSpec{Containers: []api.Container{{Image: "foo:V1"}}}, }, "metadata.deletionGracePeriodSeconds", - "deletion grace period seconds cleared", + "deletion grace period seconds changed", }, { api.Pod{ @@ -6502,13 +6543,13 @@ func TestValidatePodUpdate(t *testing.T) { api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo", Annotations: map[string]string{api.MirrorPodAnnotationKey: ""}}, Spec: api.PodSpec{NodeName: "foo"}}, api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}, Spec: api.PodSpec{NodeName: "foo"}}, "metadata.annotations[kubernetes.io/config.mirror]", - "removed mirror pod annotation", + "added mirror pod annotation", }, { api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}, Spec: api.PodSpec{NodeName: "foo"}}, api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo", Annotations: map[string]string{api.MirrorPodAnnotationKey: ""}}, Spec: api.PodSpec{NodeName: "foo"}}, "metadata.annotations[kubernetes.io/config.mirror]", - "added mirror pod annotation", + "removed mirror pod annotation", }, { api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo", Annotations: map[string]string{api.MirrorPodAnnotationKey: "foo"}}, Spec: api.PodSpec{NodeName: "foo"}}, @@ -6563,16 +6604,16 @@ func TestValidatePodUpdate(t *testing.T) { } for _, test := range tests { - test.a.ObjectMeta.ResourceVersion = "1" - test.b.ObjectMeta.ResourceVersion = "1" - errs := ValidatePodUpdate(&test.a, &test.b) + test.new.ObjectMeta.ResourceVersion = "1" + test.old.ObjectMeta.ResourceVersion = "1" + errs := ValidatePodUpdate(&test.new, &test.old) if test.err == "" { if len(errs) != 0 { - t.Errorf("unexpected invalid: %s (%+v)\nA: %+v\nB: %+v", test.test, errs, test.a, test.b) + t.Errorf("unexpected invalid: %s (%+v)\nA: %+v\nB: %+v", test.test, errs, test.new, test.old) } } else { if len(errs) == 0 { - t.Errorf("unexpected valid: %s\nA: %+v\nB: %+v", test.test, test.a, test.b) + t.Errorf("unexpected valid: %s\nA: %+v\nB: %+v", test.test, test.new, test.old) } else if actualErr := errs.ToAggregate().Error(); !strings.Contains(actualErr, test.err) { t.Errorf("unexpected error message: %s\nExpected error: %s\nActual error: %s", test.test, test.err, actualErr) }