7
"github.com/onsi/gomega/types"
11
Fail types.GomegaFailHandler
13
DurationBundle DurationBundle
16
func NewGomega(bundle DurationBundle) *Gomega {
20
DurationBundle: bundle,
24
func (g *Gomega) IsConfigured() bool {
25
return g.Fail != nil && g.THelper != nil
28
func (g *Gomega) ConfigureWithFailHandler(fail types.GomegaFailHandler) *Gomega {
34
func (g *Gomega) ConfigureWithT(t types.GomegaTestingT) *Gomega {
35
g.Fail = func(message string, _ ...int) {
37
t.Fatalf("\n%s", message)
43
func (g *Gomega) Ω(actual interface{}, extra ...interface{}) types.Assertion {
44
return g.ExpectWithOffset(0, actual, extra...)
47
func (g *Gomega) Expect(actual interface{}, extra ...interface{}) types.Assertion {
48
return g.ExpectWithOffset(0, actual, extra...)
51
func (g *Gomega) ExpectWithOffset(offset int, actual interface{}, extra ...interface{}) types.Assertion {
52
return NewAssertion(actual, g, offset, extra...)
55
func (g *Gomega) Eventually(actualOrCtx interface{}, args ...interface{}) types.AsyncAssertion {
56
return g.makeAsyncAssertion(AsyncAssertionTypeEventually, 0, actualOrCtx, args...)
59
func (g *Gomega) EventuallyWithOffset(offset int, actualOrCtx interface{}, args ...interface{}) types.AsyncAssertion {
60
return g.makeAsyncAssertion(AsyncAssertionTypeEventually, offset, actualOrCtx, args...)
63
func (g *Gomega) Consistently(actualOrCtx interface{}, args ...interface{}) types.AsyncAssertion {
64
return g.makeAsyncAssertion(AsyncAssertionTypeConsistently, 0, actualOrCtx, args...)
67
func (g *Gomega) ConsistentlyWithOffset(offset int, actualOrCtx interface{}, args ...interface{}) types.AsyncAssertion {
68
return g.makeAsyncAssertion(AsyncAssertionTypeConsistently, offset, actualOrCtx, args...)
71
func (g *Gomega) makeAsyncAssertion(asyncAssertionType AsyncAssertionType, offset int, actualOrCtx interface{}, args ...interface{}) types.AsyncAssertion {
73
timeoutInterval := -time.Duration(1)
74
pollingInterval := -time.Duration(1)
75
intervals := []interface{}{}
76
var ctx context.Context
80
if _, isCtx := actualOrCtx.(context.Context); isCtx && len(args) > 0 {
81
// the first argument is a context, we should accept it as the context _only if_ it is **not** the only argumnent **and** the second argument is not a parseable duration
82
// this is due to an unfortunate ambiguity in early version of Gomega in which multi-type durations are allowed after the actual
83
if _, err := toDuration(args[0]); err != nil {
84
ctx = actualOrCtx.(context.Context)
90
for _, arg := range args[startingIndex:] {
91
switch v := arg.(type) {
95
intervals = append(intervals, arg)
99
if len(intervals) > 0 {
100
timeoutInterval, err = toDuration(intervals[0])
102
g.Fail(err.Error(), offset+baseOffset)
105
if len(intervals) > 1 {
106
pollingInterval, err = toDuration(intervals[1])
108
g.Fail(err.Error(), offset+baseOffset)
112
return NewAsyncAssertion(asyncAssertionType, actual, g, timeoutInterval, pollingInterval, 1, ctx, offset)
115
func (g *Gomega) SetDefaultEventuallyTimeout(t time.Duration) {
116
g.DurationBundle.EventuallyTimeout = t
119
func (g *Gomega) SetDefaultEventuallyPollingInterval(t time.Duration) {
120
g.DurationBundle.EventuallyPollingInterval = t
123
func (g *Gomega) SetDefaultConsistentlyDuration(t time.Duration) {
124
g.DurationBundle.ConsistentlyDuration = t
127
func (g *Gomega) SetDefaultConsistentlyPollingInterval(t time.Duration) {
128
g.DurationBundle.ConsistentlyPollingInterval = t