...

Source file src/github.com/cert-manager/issuer-lib/internal/tests/errormatch/error_match.go

Documentation: github.com/cert-manager/issuer-lib/internal/tests/errormatch

     1  /*
     2  Copyright 2023 The cert-manager Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package errormatch
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/stretchr/testify/assert"
    23  	"k8s.io/utils/ptr"
    24  )
    25  
    26  type Matcher func(t testing.TB, err error) bool
    27  
    28  func newMatcherPtr(matcher Matcher) *Matcher {
    29  	return ptr.To(matcher)
    30  }
    31  
    32  func NoError() *Matcher {
    33  	return newMatcherPtr(func(tb testing.TB, err error) bool {
    34  		tb.Helper()
    35  
    36  		return assert.NoError(tb, err)
    37  	})
    38  }
    39  
    40  func ErrorContains(contains string) *Matcher {
    41  	return newMatcherPtr(func(tb testing.TB, err error) bool {
    42  		tb.Helper()
    43  
    44  		return assert.ErrorContains(tb, err, contains)
    45  	})
    46  }
    47  

View as plain text