package runtime import ( "fmt" "testing" "gotest.tools/v3/assert" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime/schema" ) func TestIsImmutableError(t *testing.T) { tcs := map[string]struct { err error exp bool }{ "KCC admission webhook error": { err: fmt.Errorf(`LoggingLogSink/namepace/foo dry-run failed, error: admission webhook "deny-immutable-field-updates.cnrm.cloud.google.com" denied the request: cannot make changes to immutable field(s): [uniqueWriterIdentity]; please refer to our troubleshooting doc: https://cloud.google.com/config-connector/docs/troubleshooting`), exp: true, }, "KCC admission webhook error 2": { err: fmt.Errorf(`reason: the IAMPolicyMember's spec is immutable, error: admission webhook "deny-immutable-field-updates.cnrm.cloud.google.com" denied the request: the IAMPolicyMember's spec is immutable`), exp: true, }, "CEL immutability error": { err: fmt.Errorf(`Invalid value: \"object\": Value is immutable`), exp: true, }, "not immutability error": { err: fmt.Errorf("i am simply error, so sad"), }, "NotFound error is not an immutability error": { err: errors.NewNotFound( schema.GroupResource{Group: "fake.asf.io", Resource: "muscles"}, "bicep", ), }, "nil error is not an immutability error": { err: nil, }, } for name, tc := range tcs { t.Run(name, func(t *testing.T) { assert.Equal(t, IsImmutableError(tc.err), tc.exp) }) } }