@@ -85,6 +85,24 @@ func (m gitRepoPointerMatcher) String() string {
8585 return ""
8686}
8787
88+ // errorMatcher implements a gomock matcher on error message strings.
89+ type errorMatcher struct {
90+ errMsg string
91+ }
92+
93+ func (m errorMatcher ) Matches (x interface {}) bool {
94+ err , ok := x .(error )
95+ if ! ok {
96+ return false
97+ }
98+
99+ return err .Error () == m .errMsg
100+ }
101+
102+ func (m errorMatcher ) String () string {
103+ return fmt .Sprintf ("matches error %q" , m .errMsg )
104+ }
105+
88106func TestReconcile_Error_WhenGitrepoRestrictionsAreNotMet (t * testing.T ) {
89107 mockCtrl := gomock .NewController (t )
90108 defer mockCtrl .Finish ()
@@ -135,7 +153,8 @@ func TestReconcile_Error_WhenGitrepoRestrictionsAreNotMet(t *testing.T) {
135153 corev1 .EventTypeWarning ,
136154 "FailedToApplyRestrictions" ,
137155 "ApplyGitRepoRestrictions" ,
138- "empty targetNamespace denied, because allowedTargetNamespaces restriction is present" ,
156+ "%v" ,
157+ errorMatcher {"empty targetNamespace denied, because allowedTargetNamespaces restriction is present" },
139158 )
140159
141160 r := GitJobReconciler {
@@ -212,7 +231,8 @@ func TestReconcile_Error_WhenGetGitJobErrors(t *testing.T) {
212231 corev1 .EventTypeWarning ,
213232 "FailedToGetGitJob" ,
214233 "GetGitJob" ,
215- "error retrieving git job: GITJOB ERROR" ,
234+ "%v" ,
235+ errorMatcher {"error retrieving git job: GITJOB ERROR" },
216236 )
217237
218238 r := GitJobReconciler {
@@ -285,7 +305,8 @@ func TestReconcile_Error_WhenSecretDoesNotExist(t *testing.T) {
285305 corev1 .EventTypeWarning ,
286306 "FailedValidatingSecret" ,
287307 "ValidateSecret" ,
288- "failed to look up HelmSecretNameForPaths, error: SECRET ERROR" ,
308+ "%v" ,
309+ errorMatcher {"failed to look up HelmSecretNameForPaths, error: SECRET ERROR" },
289310 )
290311
291312 statusClient := mocks .NewMockStatusWriter (mockCtrl )
0 commit comments