Skip to content

Commit 4c7df5e

Browse files
committed
maintain backward compatibility for Eventually and Consisntetly's signatures
1 parent 1ba8372 commit 4c7df5e

File tree

4 files changed

+29
-37
lines changed

4 files changed

+29
-37
lines changed

gexec/session.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ To assert that the command has exited it is more convenient to use the Exit matc
121121
122122
When the process exits because it has received a particular signal, the exit code will be 128+signal-value
123123
(See http://www.tldp.org/LDP/abs/html/exitcodes.html and http://man7.org/linux/man-pages/man7/signal.7.html)
124-
125124
*/
126125
func (s *Session) ExitCode() int {
127126
s.lock.Lock()
@@ -142,9 +141,7 @@ will wait for the command to exit then return the entirety of Out's contents.
142141
Wait uses eventually under the hood and accepts the same timeout/polling intervals that eventually does.
143142
*/
144143
func (s *Session) Wait(timeout ...interface{}) *Session {
145-
args := []any{s}
146-
args = append(args, timeout...)
147-
EventuallyWithOffset(1, args...).Should(Exit())
144+
EventuallyWithOffset(1, s, timeout...).Should(Exit())
148145
return s
149146
}
150147

gomega_dsl.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,9 @@ is equivalent to
368368
369369
Eventually(...).WithTimeout(time.Second).WithPolling(2*time.Second).WithContext(ctx).Should(...)
370370
*/
371-
func Eventually(args ...interface{}) AsyncAssertion {
371+
func Eventually(actualOrCtx interface{}, args ...interface{}) AsyncAssertion {
372372
ensureDefaultGomegaIsConfigured()
373-
return Default.Eventually(args...)
373+
return Default.Eventually(actualOrCtx, args...)
374374
}
375375

376376
// EventuallyWithOffset operates like Eventually but takes an additional
@@ -382,9 +382,9 @@ func Eventually(args ...interface{}) AsyncAssertion {
382382
// `EventuallyWithOffset` specifying a timeout interval (and an optional polling interval) are
383383
// the same as `Eventually(...).WithOffset(...).WithTimeout` or
384384
// `Eventually(...).WithOffset(...).WithTimeout(...).WithPolling`.
385-
func EventuallyWithOffset(offset int, args ...interface{}) AsyncAssertion {
385+
func EventuallyWithOffset(offset int, actualOrCtx interface{}, args ...interface{}) AsyncAssertion {
386386
ensureDefaultGomegaIsConfigured()
387-
return Default.EventuallyWithOffset(offset, args...)
387+
return Default.EventuallyWithOffset(offset, actualOrCtx, args...)
388388
}
389389

390390
/*
@@ -402,9 +402,9 @@ Consistently is useful in cases where you want to assert that something *does no
402402
403403
This will block for 200 milliseconds and repeatedly check the channel and ensure nothing has been received.
404404
*/
405-
func Consistently(args ...interface{}) AsyncAssertion {
405+
func Consistently(actualOrCtx interface{}, args ...interface{}) AsyncAssertion {
406406
ensureDefaultGomegaIsConfigured()
407-
return Default.Consistently(args...)
407+
return Default.Consistently(actualOrCtx, args...)
408408
}
409409

410410
// ConsistentlyWithOffset operates like Consistently but takes an additional
@@ -413,9 +413,9 @@ func Consistently(args ...interface{}) AsyncAssertion {
413413
//
414414
// `ConsistentlyWithOffset` is the same as `Consistently(...).WithOffset` and
415415
// optional `WithTimeout` and `WithPolling`.
416-
func ConsistentlyWithOffset(offset int, args ...interface{}) AsyncAssertion {
416+
func ConsistentlyWithOffset(offset int, actualOrCtx interface{}, args ...interface{}) AsyncAssertion {
417417
ensureDefaultGomegaIsConfigured()
418-
return Default.ConsistentlyWithOffset(offset, args...)
418+
return Default.ConsistentlyWithOffset(offset, actualOrCtx, args...)
419419
}
420420

421421
/*

internal/gomega.go

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package internal
22

33
import (
44
"context"
5-
"fmt"
65
"time"
76

87
"github.com/onsi/gomega/types"
@@ -53,42 +52,38 @@ func (g *Gomega) ExpectWithOffset(offset int, actual interface{}, extra ...inter
5352
return NewAssertion(actual, g, offset, extra...)
5453
}
5554

56-
func (g *Gomega) Eventually(args ...interface{}) types.AsyncAssertion {
57-
return g.makeAsyncAssertion(AsyncAssertionTypeEventually, 0, args...)
55+
func (g *Gomega) Eventually(actualOrCtx interface{}, args ...interface{}) types.AsyncAssertion {
56+
return g.makeAsyncAssertion(AsyncAssertionTypeEventually, 0, actualOrCtx, args...)
5857
}
5958

60-
func (g *Gomega) EventuallyWithOffset(offset int, args ...interface{}) types.AsyncAssertion {
61-
return g.makeAsyncAssertion(AsyncAssertionTypeEventually, offset, args...)
59+
func (g *Gomega) EventuallyWithOffset(offset int, actualOrCtx interface{}, args ...interface{}) types.AsyncAssertion {
60+
return g.makeAsyncAssertion(AsyncAssertionTypeEventually, offset, actualOrCtx, args...)
6261
}
6362

64-
func (g *Gomega) Consistently(args ...interface{}) types.AsyncAssertion {
65-
return g.makeAsyncAssertion(AsyncAssertionTypeConsistently, 0, args...)
63+
func (g *Gomega) Consistently(actualOrCtx interface{}, args ...interface{}) types.AsyncAssertion {
64+
return g.makeAsyncAssertion(AsyncAssertionTypeConsistently, 0, actualOrCtx, args...)
6665
}
6766

68-
func (g *Gomega) ConsistentlyWithOffset(offset int, args ...interface{}) types.AsyncAssertion {
69-
return g.makeAsyncAssertion(AsyncAssertionTypeConsistently, offset, args...)
67+
func (g *Gomega) ConsistentlyWithOffset(offset int, actualOrCtx interface{}, args ...interface{}) types.AsyncAssertion {
68+
return g.makeAsyncAssertion(AsyncAssertionTypeConsistently, offset, actualOrCtx, args...)
7069
}
7170

72-
func (g *Gomega) makeAsyncAssertion(asyncAssertionType AsyncAssertionType, offset int, args ...interface{}) types.AsyncAssertion {
71+
func (g *Gomega) makeAsyncAssertion(asyncAssertionType AsyncAssertionType, offset int, actualOrCtx interface{}, args ...interface{}) types.AsyncAssertion {
7372
baseOffset := 3
7473
timeoutInterval := -time.Duration(1)
7574
pollingInterval := -time.Duration(1)
7675
intervals := []interface{}{}
7776
var ctx context.Context
78-
if len(args) == 0 {
79-
g.Fail(fmt.Sprintf("Call to %s is missing a value or function to poll", asyncAssertionType), offset+baseOffset)
80-
return nil
81-
}
8277

83-
actual := args[0]
84-
startingIndex := 1
85-
if _, isCtx := args[0].(context.Context); isCtx && len(args) > 1 {
78+
actual := actualOrCtx
79+
startingIndex := 0
80+
if _, isCtx := actualOrCtx.(context.Context); isCtx && len(args) > 0 {
8681
// 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
8782
// this is due to an unfortunate ambiguity in early version of Gomega in which multi-type durations are allowed after the actual
88-
if _, err := toDuration(args[1]); err != nil {
89-
ctx = args[0].(context.Context)
90-
actual = args[1]
91-
startingIndex = 2
83+
if _, err := toDuration(args[0]); err != nil {
84+
ctx = actualOrCtx.(context.Context)
85+
actual = args[0]
86+
startingIndex = 1
9287
}
9388
}
9489

types/types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ type Gomega interface {
1919
Expect(actual interface{}, extra ...interface{}) Assertion
2020
ExpectWithOffset(offset int, actual interface{}, extra ...interface{}) Assertion
2121

22-
Eventually(args ...interface{}) AsyncAssertion
23-
EventuallyWithOffset(offset int, args ...interface{}) AsyncAssertion
22+
Eventually(actualOrCtx interface{}, args ...interface{}) AsyncAssertion
23+
EventuallyWithOffset(offset int, actualOrCtx interface{}, args ...interface{}) AsyncAssertion
2424

25-
Consistently(args ...interface{}) AsyncAssertion
26-
ConsistentlyWithOffset(offset int, args ...interface{}) AsyncAssertion
25+
Consistently(actualOrCtx interface{}, args ...interface{}) AsyncAssertion
26+
ConsistentlyWithOffset(offset int, actualOrCtx interface{}, args ...interface{}) AsyncAssertion
2727

2828
SetDefaultEventuallyTimeout(time.Duration)
2929
SetDefaultEventuallyPollingInterval(time.Duration)

0 commit comments

Comments
 (0)