...
1 package runtime
2
3 import (
4 "fmt"
5 "testing"
6
7 "gotest.tools/v3/assert"
8 "k8s.io/apimachinery/pkg/api/errors"
9 "k8s.io/apimachinery/pkg/runtime/schema"
10 )
11
12 func TestIsImmutableError(t *testing.T) {
13 tcs := map[string]struct {
14 err error
15 exp bool
16 }{
17 "KCC admission webhook error": {
18 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`),
19 exp: true,
20 },
21 "KCC admission webhook error 2": {
22 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`),
23 exp: true,
24 },
25 "CEL immutability error": {
26 err: fmt.Errorf(`Invalid value: \"object\": Value is immutable`),
27 exp: true,
28 },
29 "not immutability error": {
30 err: fmt.Errorf("i am simply error, so sad"),
31 },
32 "NotFound error is not an immutability error": {
33 err: errors.NewNotFound(
34 schema.GroupResource{Group: "fake.asf.io", Resource: "muscles"},
35 "bicep",
36 ),
37 },
38 "nil error is not an immutability error": {
39 err: nil,
40 },
41 }
42
43 for name, tc := range tcs {
44 t.Run(name, func(t *testing.T) {
45 assert.Equal(t, IsImmutableError(tc.err), tc.exp)
46 })
47 }
48 }
49
View as plain text