Skip to content

Commit

Permalink
revert testutil package
Browse files Browse the repository at this point in the history
  • Loading branch information
tuunit committed Jan 22, 2024
1 parent a69c33b commit c6b7eee
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/apis/options/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"time"

. "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options/loadtest"
. "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options/testutil"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package loadtest
package testutil

import (
"errors"
Expand Down
70 changes: 70 additions & 0 deletions pkg/apis/options/testutil/options_matcher_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
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())
})
})

0 comments on commit c6b7eee

Please sign in to comment.