You've already forked oauth2-proxy
mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2025-08-10 22:51:31 +02:00
upgrading to go 1.21 (#2235)
* chore: bump go to version 1.21 update all depedencies as well * fix linting issues based on golang 1.20 deprecations * cleanup go depedencies * add custom gomega matcher for option intefaces * revert and upgrade golangci-lint to 1.55.2 * fix lint issues for v1.55.2 of golangci-lint * fix toml loading test * remove second runspecs call * update go.sum * revert testutil package
This commit is contained in:
62
pkg/apis/options/testutil/options_matcher.go
Normal file
62
pkg/apis/options/testutil/options_matcher.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package testutil
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
"github.com/onsi/gomega/format"
|
||||
"github.com/onsi/gomega/types"
|
||||
)
|
||||
|
||||
type optionsMatcher struct {
|
||||
Expected interface{}
|
||||
CompareOptions []cmp.Option
|
||||
}
|
||||
|
||||
func EqualOpts(expected interface{}) types.GomegaMatcher {
|
||||
ignoreUnexported := cmp.FilterPath(func(p cmp.Path) bool {
|
||||
sf, ok := p.Index(-1).(cmp.StructField)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
r, _ := utf8.DecodeRuneInString(sf.Name())
|
||||
return !unicode.IsUpper(r)
|
||||
}, cmp.Ignore())
|
||||
|
||||
return &optionsMatcher{
|
||||
Expected: expected,
|
||||
CompareOptions: []cmp.Option{ignoreUnexported, cmpopts.EquateEmpty()},
|
||||
}
|
||||
}
|
||||
|
||||
func (matcher *optionsMatcher) Match(actual interface{}) (success bool, err error) {
|
||||
if actual == nil && matcher.Expected == nil {
|
||||
return false, errors.New("trying to compare <nil> to <nil>")
|
||||
}
|
||||
return cmp.Equal(actual, matcher.Expected, matcher.CompareOptions...), nil
|
||||
}
|
||||
|
||||
func (matcher *optionsMatcher) FailureMessage(actual interface{}) (message string) {
|
||||
actualString, actualOK := actual.(string)
|
||||
expectedString, expectedOK := fmt.Sprintf("%v", matcher.Expected), true
|
||||
if actualOK && expectedOK {
|
||||
return format.MessageWithDiff(actualString, "to equal", expectedString)
|
||||
}
|
||||
|
||||
return format.Message(actual, "to equal", matcher.Expected) +
|
||||
"\n\nDiff:\n" + format.IndentString(matcher.getDiff(actual), 1)
|
||||
}
|
||||
|
||||
func (matcher *optionsMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
||||
|
||||
return format.Message(actual, "not to equal", matcher.Expected) +
|
||||
"\n\nDiff:\n" + format.IndentString(matcher.getDiff(actual), 1)
|
||||
}
|
||||
|
||||
func (matcher *optionsMatcher) getDiff(actual interface{}) string {
|
||||
return cmp.Diff(actual, matcher.Expected, matcher.CompareOptions...)
|
||||
}
|
Reference in New Issue
Block a user