Repository: kubernetes/kubernetes
File: pkg/registry/storage/storageclass/declarative_validation_test.go (Go)

Code before:
		})
	}
}

func testDeclarativeValidateUpdate(t *testing.T, apiVersion string) {
	testCases := map[string]struct {
		oldObj       storage.StorageClass
		updateObj    storage.StorageClass
		expectedErrs field.ErrorList
	}{
		"valid update": {
			oldObj:    mkValidStorageClass(),
			updateObj: mkValidStorageClass(),
		},
		"invalid update provisioner changed": {
			oldObj:    mkValidStorageClass(),
			updateObj: mkValidStorageClass(TweakProvisioner("kubernetes.io/aws-ebs")),
			expectedErrs: field.ErrorList{
				field.Invalid(field.NewPath("provisioner"), "kubernetes.io/aws-ebs", "field is immutable").WithOrigin("immutable"),
			},
		},
		"invalid update parameters changed": {
			oldObj:    mkValidStorageClass(),
			updateObj: mkValidStorageClass(TweakParameters(map[string]string{"new": "value"})),
			expectedErrs: field.ErrorList{
				field.Invalid(field.NewPath("parameters"), map[string]string{"new": "value"}, "field is immutable").WithOrigin("immutable"),
			},
		},
	}
	for k, tc := range testCases {
		t.Run(k, func(t *testing.T) {
			tc.oldObj.ResourceVersion = "1"
			tc.updateObj.ResourceVersion = "2"
			ctx := genericapirequest.WithRequestInfo(genericapirequest.NewDefaultContext(), &genericapirequest.RequestInfo{
				APIPrefix:         "apis",
				APIGroup:          "storage.k8s.io",
				APIVersion:        apiVersion,
				Resource:          "storageclasses",
				Name:              "valid-storage-class",
				IsResourceRequest: true,
				Verb:              "update",
			})
			apitesting.VerifyUpdateValidationEquivalence(t, ctx, &tc.updateObj, &tc.oldObj, Strategy.ValidateUpdate, tc.expectedErrs)
		})
	}
}

func mkValidStorageClass(tweaks ...func(obj *storage.StorageClass)) storage.StorageClass {
	reclaimPolicy := api.PersistentVolumeReclaimDelete
	volumeBindingMode := storage.VolumeBindingImmediate
	obj := storage.StorageClass{

Review comment (suggestion):
for all of these you do not need the value or details arg -- the origin is sufficient.  Just the then to `nil` and `""` respectively

Code after:
		})
	}
}

func testDeclarativeValidateUpdate(t *testing.T, apiVersion string) {
	testCases := map[string]struct {
		oldObj       storage.StorageClass
		updateObj    storage.StorageClass
		expectedErrs field.ErrorList
	}{
		"valid update": {
			oldObj:    mkValidStorageClass(),
			updateObj: mkValidStorageClass(),
		},
		"invalid update provisioner changed": {
			oldObj:    mkValidStorageClass(),
			updateObj: mkValidStorageClass(TweakProvisioner("kubernetes.io/aws-ebs")),
			expectedErrs: field.ErrorList{
				field.Invalid(field.NewPath("provisioner"), "", "").WithOrigin("immutable"),
			},
		},
		"invalid update provisioner unset to set": {
			oldObj:    mkValidStorageClass(TweakProvisioner("")),
			updateObj: mkValidStorageClass(),
			expectedErrs: field.ErrorList{
				field.Invalid(field.NewPath("provisioner"), "", "").WithOrigin("immutable"),
			},
		},
		"invalid update provisioner set to unset": {
			oldObj:    mkValidStorageClass(),
			updateObj: mkValidStorageClass(TweakProvisioner("")),
			expectedErrs: field.ErrorList{
				field.Invalid(field.NewPath("provisioner"), "", "").WithOrigin("immutable"),
				field.Required(field.NewPath("provisioner"), ""),
			},
		},
		"invalid update parameters changed": {
			oldObj:    mkValidStorageClass(),
			updateObj: mkValidStorageClass(TweakParameters(map[string]string{"new": "value"})),
			expectedErrs: field.ErrorList{
				field.Invalid(field.NewPath("parameters"), nil, "").WithOrigin("immutable"),
			},
		},
		"invalid update parameters unset to set": {
			oldObj:    mkValidStorageClass(),
			updateObj: mkValidStorageClass(TweakParameters(map[string]string{"foo": "bar"})),
			expectedErrs: field.ErrorList{
				field.Invalid(field.NewPath("parameters"), nil, "").WithOrigin("immutable"),
			},
		},
		"invalid update parameters set to unset": {