Repository: kubernetes/kubernetes
File: pkg/registry/networking/ipaddress/declarative_validation_test.go (Go)

Code before:
					apitesting.VerifyValidationEquivalence(
						t,
						ctx,
						&tc.input,
						Strategy.Validate,
						tc.expectedErrs,
					)
				})
			}
		})
	}
}

func TestDeclarativeValidateIPAddressUpdate(t *testing.T) {
	for _, apiVersion := range apiVersions {
		t.Run(apiVersion, func(t *testing.T) {
			testCases := map[string]struct {
				oldObj       networking.IPAddress
				updateObj    networking.IPAddress
				expectedErrs field.ErrorList
			}{
				"valid update": {
					oldObj:    mkValidIPAddress(withResourceVersion("1")),
					updateObj: mkValidIPAddress(withResourceVersion("1")),
				},
				"immutable parentRef": {
					oldObj: mkValidIPAddress(withResourceVersion("1")),
					updateObj: mkValidIPAddress(
						withResourceVersion("1"),
						withParentRefName("new-name"),
					),
					expectedErrs: field.ErrorList{
						func() *field.Error {
							e := field.Invalid(field.NewPath("spec", "parentRef"), &networking.ParentReference{
								Group:    "apps",
								Resource: "deployments",
								Name:     "new-name",
							}, "field is immutable")
							e.Origin = "immutable"
							return e
						}(),
					},
				},
				"unset parentRef": {
					oldObj: mkValidIPAddress(withResourceVersion("1")),
					updateObj: mkValidIPAddress(
						withResourceVersion("1"),
						withNilParentRef,
					),
					expectedErrs: field.ErrorList{
						field.Required(field.NewPath("spec", "parentRef"), ""),

Review comment (suggestion):
For immutable, there are 3 cases we care about - NoSet,NoUnset, and NoModify.   Currently we are missing a test for NoSet, can you add this as well?

NoSet:
"unset"/nil/zero-value -> set-value/non-zero-value -> immutable error

NoUnset:
(already tests)

NoModify :
(already tested)

Code after:
					apitesting.VerifyValidationEquivalence(
						t,
						ctx,
						&tc.input,
						Strategy.Validate,
						tc.expectedErrs,
					)
				})
			}
		})
	}
}

func TestDeclarativeValidateIPAddressUpdate(t *testing.T) {
	for _, apiVersion := range apiVersions {
		t.Run(apiVersion, func(t *testing.T) {
			testCases := map[string]struct {
				oldObj       networking.IPAddress
				updateObj    networking.IPAddress
				expectedErrs field.ErrorList
			}{
				"valid update": {
					oldObj:    mkValidIPAddress(withResourceVersion("1")),
					updateObj: mkValidIPAddress(withResourceVersion("1")),
				},
				"immutable parentRef": {
					oldObj: mkValidIPAddress(withResourceVersion("1")),
					updateObj: mkValidIPAddress(
						withResourceVersion("1"),
						withParentRefName("new-name"),
					),
					expectedErrs: field.ErrorList{
						func() *field.Error {
							e := field.Invalid(field.NewPath("spec", "parentRef"), &networking.ParentReference{
								Group:    "apps",
								Resource: "deployments",
								Name:     "new-name",
							}, "field is immutable")
							e.Origin = "immutable"
							return e
						}(),
					},
				},
				"set parentRef": {
					oldObj: mkValidIPAddress(withResourceVersion("1"), withNilParentRef),
					updateObj: mkValidIPAddress(
						withResourceVersion("2"),
						withParentRefName("new-name"),
					),
					expectedErrs: field.ErrorList{
						func() *field.Error {