diff --git a/internal/certmanager/sync_test.go b/internal/certmanager/sync_test.go index b3b662fd14..0fb827ad29 100644 --- a/internal/certmanager/sync_test.go +++ b/internal/certmanager/sync_test.go @@ -519,7 +519,7 @@ func TestSync(t *testing.T) { t.Errorf("Not all expected reactors were called: %v", err) } if err := b.AllActionsExecuted(); err != nil { - t.Errorf(err.Error()) + t.Error(err.Error()) } } } diff --git a/internal/certmanager/test_files/context_builder.go b/internal/certmanager/test_files/context_builder.go index b055b288fd..461a3e17a3 100644 --- a/internal/certmanager/test_files/context_builder.go +++ b/internal/certmanager/test_files/context_builder.go @@ -174,10 +174,10 @@ func (b *Builder) CheckAndFinish(args ...interface{}) { b.T.Errorf("Not all expected reactors were called: %v", err) } if err := b.AllActionsExecuted(); err != nil { - b.T.Errorf(err.Error()) + b.T.Error(err.Error()) } if err := b.AllEventsCalled(); err != nil { - b.T.Errorf(err.Error()) + b.T.Error(err.Error()) } // resync listers before running checks diff --git a/internal/configs/virtualserver_test.go b/internal/configs/virtualserver_test.go index bb1741cbda..664aeaa06e 100644 --- a/internal/configs/virtualserver_test.go +++ b/internal/configs/virtualserver_test.go @@ -1479,7 +1479,7 @@ func TestGenerateVirtualServerConfigWithBackupForNGINXPlus(t *testing.T) { got, warnings := vsc.GenerateVirtualServerConfig(&virtualServerEx, nil, nil) if !cmp.Equal(want, got) { - t.Errorf(cmp.Diff(want, got)) + t.Error(cmp.Diff(want, got)) } if len(warnings) != 0 { t.Errorf("GenerateVirtualServerConfig returned warnings: %v", vsc.warnings) @@ -1786,7 +1786,7 @@ func TestGenerateVirtualServerConfig_DoesNotGenerateBackupOnMissingBackupNameFor got, warnings := vsc.GenerateVirtualServerConfig(&virtualServerEx, nil, nil) if !cmp.Equal(want, got) { - t.Errorf(cmp.Diff(want, got)) + t.Error(cmp.Diff(want, got)) } if len(warnings) != 0 { t.Errorf("GenerateVirtualServerConfig returned warnings: %v", vsc.warnings) @@ -2092,7 +2092,7 @@ func TestGenerateVirtualServerConfig_DoesNotGenerateBackupOnMissingBackupPortFor got, warnings := vsc.GenerateVirtualServerConfig(&virtualServerEx, nil, nil) if !cmp.Equal(want, got) { - t.Errorf(cmp.Diff(want, got)) + t.Error(cmp.Diff(want, got)) } if len(warnings) != 0 { t.Errorf("GenerateVirtualServerConfig returned warnings: %v", vsc.warnings) @@ -2396,7 +2396,7 @@ func TestGenerateVirtualServerConfig_DoesNotGenerateBackupOnMissingBackupPortAnd got, warnings := vsc.GenerateVirtualServerConfig(&virtualServerEx, nil, nil) if !cmp.Equal(want, got) { - t.Errorf(cmp.Diff(want, got)) + t.Error(cmp.Diff(want, got)) } if len(warnings) != 0 { t.Errorf("GenerateVirtualServerConfig returned warnings: %v", vsc.warnings) @@ -6347,19 +6347,19 @@ func TestGenerateVirtualServerConfigAPIKeyClientMaps(t *testing.T) { }) if !cmp.Equal(tc.expectedSpecAPIKey, vsConf.Server.APIKey) { - t.Errorf(cmp.Diff(tc.expectedSpecAPIKey, vsConf.Server.APIKey)) + t.Error(cmp.Diff(tc.expectedSpecAPIKey, vsConf.Server.APIKey)) } if !cmp.Equal(tc.expectedRoute1APIKey, vsConf.Server.Locations[0].APIKey) { - t.Errorf(cmp.Diff(tc.expectedRoute1APIKey, vsConf.Server.Locations[0].APIKey)) + t.Error(cmp.Diff(tc.expectedRoute1APIKey, vsConf.Server.Locations[0].APIKey)) } if !cmp.Equal(tc.expectedRoute2APIKey, vsConf.Server.Locations[1].APIKey) { - t.Errorf(cmp.Diff(tc.expectedRoute2APIKey, vsConf.Server.Locations[1].APIKey)) + t.Error(cmp.Diff(tc.expectedRoute2APIKey, vsConf.Server.Locations[1].APIKey)) } if !cmp.Equal(tc.expectedMapList, vsConf.Maps) { - t.Errorf(cmp.Diff(tc.expectedMapList, vsConf.Maps)) + t.Error(cmp.Diff(tc.expectedMapList, vsConf.Maps)) } if len(warnings) != 0 { @@ -7161,7 +7161,7 @@ func TestGeneratePolicies(t *testing.T) { result.BundleValidator = nil if !cmp.Equal(tc.expected, result) { - t.Errorf(cmp.Diff(tc.expected, result)) + t.Error(cmp.Diff(tc.expected, result)) } if len(vsc.warnings) > 0 { t.Errorf("generatePolicies() returned unexpected warnings %v for the case of %s", vsc.warnings, tc.msg) @@ -15803,7 +15803,7 @@ func TestRFC1123ToSnake(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if !cmp.Equal(rfc1123ToSnake(tt.input), tt.expected) { - t.Errorf(cmp.Diff(rfc1123ToSnake(tt.input), tt.expected)) + t.Error(cmp.Diff(rfc1123ToSnake(tt.input), tt.expected)) } }) } diff --git a/internal/externaldns/sync_test.go b/internal/externaldns/sync_test.go index 812e4a2e66..666d1c52cb 100644 --- a/internal/externaldns/sync_test.go +++ b/internal/externaldns/sync_test.go @@ -82,10 +82,10 @@ func TestGetValidTargets(t *testing.T) { t.Fatal(err) } if !cmp.Equal(tc.wantTargets, targets) { - t.Errorf(cmp.Diff(tc.wantTargets, targets)) + t.Error(cmp.Diff(tc.wantTargets, targets)) } if recordType != tc.wantRecord { - t.Errorf(cmp.Diff(tc.wantRecord, recordType)) + t.Error(cmp.Diff(tc.wantRecord, recordType)) } }) } diff --git a/internal/k8s/appprotect/app_protect_configuration.go b/internal/k8s/appprotect/app_protect_configuration.go index 304ffeae10..97142f8d10 100644 --- a/internal/k8s/appprotect/app_protect_configuration.go +++ b/internal/k8s/appprotect/app_protect_configuration.go @@ -1,6 +1,7 @@ package appprotect import ( + "errors" "fmt" "sort" "time" @@ -208,14 +209,14 @@ func createAppProtectPolicyEx(policyObj *unstructured.Unstructured) (*PolicyEx, err := validation.ValidateAppProtectPolicy(policyObj) if err != nil { errMsg := fmt.Sprintf("Error validating policy %s: %v", policyObj.GetName(), err) - return &PolicyEx{Obj: policyObj, IsValid: false, ErrorMsg: failedValidationErrorMsg}, fmt.Errorf(errMsg) + return &PolicyEx{Obj: policyObj, IsValid: false, ErrorMsg: failedValidationErrorMsg}, errors.New(errMsg) } sigReqs := []SignatureReq{} // Check if policy has signature requirement (revision timestamp) and map them to tags list, found, err := unstructured.NestedSlice(policyObj.Object, "spec", "policy", "signature-requirements") if err != nil { errMsg := fmt.Sprintf("Error retrieving Signature requirements from %s: %v", policyObj.GetName(), err) - return &PolicyEx{Obj: policyObj, IsValid: false, ErrorMsg: failedValidationErrorMsg}, fmt.Errorf(errMsg) + return &PolicyEx{Obj: policyObj, IsValid: false, ErrorMsg: failedValidationErrorMsg}, errors.New(errMsg) } if found { for _, req := range list { @@ -224,7 +225,7 @@ func createAppProtectPolicyEx(policyObj *unstructured.Unstructured) (*PolicyEx, timeReq, err := buildRevTimes(requirement) if err != nil { errMsg := fmt.Sprintf("Error creating time requirements from %s: %v", policyObj.GetName(), err) - return &PolicyEx{Obj: policyObj, IsValid: false, ErrorMsg: invalidTimestampErrorMsg}, fmt.Errorf(errMsg) + return &PolicyEx{Obj: policyObj, IsValid: false, ErrorMsg: invalidTimestampErrorMsg}, errors.New(errMsg) } sigReqs = append(sigReqs, SignatureReq{Tag: reqTag.(string), RevTimes: &timeReq}) } @@ -243,7 +244,7 @@ func buildRevTimes(requirement map[string]interface{}) (RevTimes, error) { minRevTime, err := time.Parse(timeLayout, minRev.(string)) if err != nil { errMsg := fmt.Sprintf("Error Parsing time from minRevisionDatetime %v", err) - return timeReq, fmt.Errorf(errMsg) + return timeReq, errors.New(errMsg) } timeReq.MinRevTime = &minRevTime } @@ -251,7 +252,7 @@ func buildRevTimes(requirement map[string]interface{}) (RevTimes, error) { maxRevTime, err := time.Parse(timeLayout, maxRev.(string)) if err != nil { errMsg := fmt.Sprintf("Error Parsing time from maxRevisionDatetime %v", err) - return timeReq, fmt.Errorf(errMsg) + return timeReq, errors.New(errMsg) } timeReq.MaxRevTime = &maxRevTime } @@ -278,7 +279,7 @@ func createAppProtectUserSigEx(userSigObj *unstructured.Unstructured) (*UserSigE err := validation.ValidateAppProtectUserSig(userSigObj) if err != nil { errMsg := failedValidationErrorMsg - return &UserSigEx{Obj: userSigObj, IsValid: false, Tag: sTag, ErrorMsg: errMsg}, fmt.Errorf(errMsg) + return &UserSigEx{Obj: userSigObj, IsValid: false, Tag: sTag, ErrorMsg: errMsg}, errors.New(errMsg) } // Previous validation ensures there will be no errors tag, found, _ := unstructured.NestedString(userSigObj.Object, "spec", "tag") @@ -290,7 +291,7 @@ func createAppProtectUserSigEx(userSigObj *unstructured.Unstructured) (*UserSigE revTime, err := time.Parse(timeLayout, revTimeString) if err != nil { errMsg := invalidTimestampErrorMsg - return &UserSigEx{Obj: userSigObj, IsValid: false, ErrorMsg: errMsg}, fmt.Errorf(errMsg) + return &UserSigEx{Obj: userSigObj, IsValid: false, ErrorMsg: errMsg}, errors.New(errMsg) } return &UserSigEx{ Obj: userSigObj, diff --git a/internal/k8s/validation.go b/internal/k8s/validation.go index 153677c983..b7324f8bc7 100644 --- a/internal/k8s/validation.go +++ b/internal/k8s/validation.go @@ -968,7 +968,7 @@ var escapedStringsFmtRegexp = regexp.MustCompile("^" + escapedStringsFmt + "$") func ValidateEscapedString(body string, examples ...string) error { if !escapedStringsFmtRegexp.MatchString(body) { msg := validation.RegexError(escapedStringsErrMsg, escapedStringsFmt, examples...) - return fmt.Errorf(msg) + return errors.New(msg) } return nil } diff --git a/pkg/apis/configuration/validation/common.go b/pkg/apis/configuration/validation/common.go index b66fcdaaa4..d93837c58a 100644 --- a/pkg/apis/configuration/validation/common.go +++ b/pkg/apis/configuration/validation/common.go @@ -1,6 +1,7 @@ package validation import ( + "errors" "fmt" "regexp" "strings" @@ -21,7 +22,7 @@ var escapedStringsFmtRegexp = regexp.MustCompile("^" + escapedStringsFmt + "$") func ValidateEscapedString(body string, examples ...string) error { if !escapedStringsFmtRegexp.MatchString(body) { msg := validation.RegexError(escapedStringsErrMsg, escapedStringsFmt, examples...) - return fmt.Errorf(msg) + return errors.New(msg) } return nil }