mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2025-04-23 12:18:50 +02:00
* 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
71 lines
2.1 KiB
Go
71 lines
2.1 KiB
Go
package testutil
|
|
|
|
import (
|
|
. "github.com/onsi/ginkgo"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("Options Gomega Matcher", func() {
|
|
type TestOptions struct {
|
|
Foo string
|
|
Bar int
|
|
List []string
|
|
|
|
// unexported fields should be ignored
|
|
unexported string
|
|
another string
|
|
}
|
|
|
|
Context("two empty option structs are equal", func() {
|
|
Expect(EqualOpts(TestOptions{}).Match(TestOptions{})).To(BeTrue())
|
|
})
|
|
|
|
Context("two options with the same content should be equal", func() {
|
|
opt1 := TestOptions{Foo: "foo", Bar: 1}
|
|
opt2 := TestOptions{Foo: "foo", Bar: 1}
|
|
Expect(EqualOpts(opt1).Match(opt2)).To(BeTrue())
|
|
})
|
|
|
|
Context("when two options have different content", func() {
|
|
opt1 := TestOptions{Foo: "foo", Bar: 1}
|
|
opt2 := TestOptions{Foo: "foo", Bar: 2}
|
|
Expect(EqualOpts(opt1).Match(opt2)).To(BeFalse())
|
|
})
|
|
|
|
Context("when two options have different types they are not equal", func() {
|
|
opt1 := TestOptions{Foo: "foo", Bar: 1}
|
|
opt2 := struct {
|
|
Foo string
|
|
Bar int
|
|
}{
|
|
Foo: "foo",
|
|
Bar: 1,
|
|
}
|
|
Expect(EqualOpts(opt1).Match(opt2)).To(BeFalse())
|
|
})
|
|
|
|
Context("when two options have different unexported fields they are equal", func() {
|
|
opts1 := TestOptions{Foo: "foo", Bar: 1, unexported: "unexported", another: "another"}
|
|
opts2 := TestOptions{Foo: "foo", Bar: 1, unexported: "unexported2"}
|
|
Expect(EqualOpts(opts1).Match(opts2)).To(BeTrue())
|
|
})
|
|
|
|
Context("when two options have different list content they are not equal", func() {
|
|
opt1 := TestOptions{List: []string{"foo", "bar"}}
|
|
opt2 := TestOptions{List: []string{"foo", "baz"}}
|
|
Expect(EqualOpts(opt1).Match(opt2)).To(BeFalse())
|
|
})
|
|
|
|
Context("when two options have different list lengths they are not equal", func() {
|
|
opt1 := TestOptions{List: []string{"foo", "bar"}}
|
|
opt2 := TestOptions{List: []string{"foo", "bar", "baz"}}
|
|
Expect(EqualOpts(opt1).Match(opt2)).To(BeFalse())
|
|
})
|
|
|
|
Context("when one options has a list of length 0 and the other is nil they are equal", func() {
|
|
otp1 := TestOptions{List: []string{}}
|
|
opt2 := TestOptions{}
|
|
Expect(EqualOpts(otp1).Match(opt2)).To(BeTrue())
|
|
})
|
|
})
|