forked from cerc-io/ipld-eth-server
Update dependencies
- uses newer version of go-ethereum required for go1.11
This commit is contained in:
+9
-4
@@ -22,11 +22,11 @@ type AsyncAssertion struct {
|
||||
actualInput interface{}
|
||||
timeoutInterval time.Duration
|
||||
pollingInterval time.Duration
|
||||
fail types.GomegaFailHandler
|
||||
failWrapper *types.GomegaFailWrapper
|
||||
offset int
|
||||
}
|
||||
|
||||
func New(asyncType AsyncAssertionType, actualInput interface{}, fail types.GomegaFailHandler, timeoutInterval time.Duration, pollingInterval time.Duration, offset int) *AsyncAssertion {
|
||||
func New(asyncType AsyncAssertionType, actualInput interface{}, failWrapper *types.GomegaFailWrapper, timeoutInterval time.Duration, pollingInterval time.Duration, offset int) *AsyncAssertion {
|
||||
actualType := reflect.TypeOf(actualInput)
|
||||
if actualType.Kind() == reflect.Func {
|
||||
if actualType.NumIn() != 0 || actualType.NumOut() == 0 {
|
||||
@@ -37,7 +37,7 @@ func New(asyncType AsyncAssertionType, actualInput interface{}, fail types.Gomeg
|
||||
return &AsyncAssertion{
|
||||
asyncType: asyncType,
|
||||
actualInput: actualInput,
|
||||
fail: fail,
|
||||
failWrapper: failWrapper,
|
||||
timeoutInterval: timeoutInterval,
|
||||
pollingInterval: pollingInterval,
|
||||
offset: offset,
|
||||
@@ -45,10 +45,12 @@ func New(asyncType AsyncAssertionType, actualInput interface{}, fail types.Gomeg
|
||||
}
|
||||
|
||||
func (assertion *AsyncAssertion) Should(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
|
||||
assertion.failWrapper.TWithHelper.Helper()
|
||||
return assertion.match(matcher, true, optionalDescription...)
|
||||
}
|
||||
|
||||
func (assertion *AsyncAssertion) ShouldNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
|
||||
assertion.failWrapper.TWithHelper.Helper()
|
||||
return assertion.match(matcher, false, optionalDescription...)
|
||||
}
|
||||
|
||||
@@ -110,6 +112,8 @@ func (assertion *AsyncAssertion) match(matcher types.GomegaMatcher, desiredMatch
|
||||
matches, err = matcher.Match(value)
|
||||
}
|
||||
|
||||
assertion.failWrapper.TWithHelper.Helper()
|
||||
|
||||
fail := func(preamble string) {
|
||||
errMsg := ""
|
||||
message := ""
|
||||
@@ -122,7 +126,8 @@ func (assertion *AsyncAssertion) match(matcher types.GomegaMatcher, desiredMatch
|
||||
message = matcher.NegatedFailureMessage(value)
|
||||
}
|
||||
}
|
||||
assertion.fail(fmt.Sprintf("%s after %.3fs.\n%s%s%s", preamble, time.Since(timer).Seconds(), description, message, errMsg), 3+assertion.offset)
|
||||
assertion.failWrapper.TWithHelper.Helper()
|
||||
assertion.failWrapper.Fail(fmt.Sprintf("%s after %.3fs.\n%s%s%s", preamble, time.Since(timer).Seconds(), description, message, errMsg), 3+assertion.offset)
|
||||
}
|
||||
|
||||
if assertion.asyncType == AsyncAssertionTypeEventually {
|
||||
|
||||
+73
-67
@@ -4,9 +4,12 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/onsi/gomega/internal/testingtsupport"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
. "github.com/onsi/gomega/internal/asyncassertion"
|
||||
"github.com/onsi/gomega/types"
|
||||
)
|
||||
|
||||
var _ = Describe("Async Assertion", func() {
|
||||
@@ -15,9 +18,12 @@ var _ = Describe("Async Assertion", func() {
|
||||
callerSkip int
|
||||
)
|
||||
|
||||
var fakeFailHandler = func(message string, skip ...int) {
|
||||
failureMessage = message
|
||||
callerSkip = skip[0]
|
||||
var fakeFailWrapper = &types.GomegaFailWrapper{
|
||||
Fail: func(message string, skip ...int) {
|
||||
failureMessage = message
|
||||
callerSkip = skip[0]
|
||||
},
|
||||
TWithHelper: testingtsupport.EmptyTWithHelper{},
|
||||
}
|
||||
|
||||
BeforeEach(func() {
|
||||
@@ -32,10 +38,10 @@ var _ = Describe("Async Assertion", func() {
|
||||
a := New(AsyncAssertionTypeEventually, func() int {
|
||||
counter++
|
||||
return counter
|
||||
}, fakeFailHandler, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
}, fakeFailWrapper, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
|
||||
a.Should(BeNumerically("==", 5))
|
||||
Ω(failureMessage).Should(BeZero())
|
||||
Expect(failureMessage).Should(BeZero())
|
||||
})
|
||||
|
||||
It("should continue when the matcher errors", func() {
|
||||
@@ -46,13 +52,13 @@ var _ = Describe("Async Assertion", func() {
|
||||
return "not-a-number" //this should cause the matcher to error
|
||||
}
|
||||
return counter
|
||||
}, fakeFailHandler, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
}, fakeFailWrapper, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
|
||||
a.Should(BeNumerically("==", 5), "My description %d", 2)
|
||||
|
||||
Ω(failureMessage).Should(ContainSubstring("Timed out after"))
|
||||
Ω(failureMessage).Should(ContainSubstring("My description 2"))
|
||||
Ω(callerSkip).Should(Equal(4))
|
||||
Expect(failureMessage).Should(ContainSubstring("Timed out after"))
|
||||
Expect(failureMessage).Should(ContainSubstring("My description 2"))
|
||||
Expect(callerSkip).Should(Equal(4))
|
||||
})
|
||||
|
||||
It("should be able to timeout", func() {
|
||||
@@ -60,16 +66,16 @@ var _ = Describe("Async Assertion", func() {
|
||||
a := New(AsyncAssertionTypeEventually, func() int {
|
||||
counter++
|
||||
return counter
|
||||
}, fakeFailHandler, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
}, fakeFailWrapper, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
|
||||
a.Should(BeNumerically(">", 100), "My description %d", 2)
|
||||
|
||||
Ω(counter).Should(BeNumerically(">", 8))
|
||||
Ω(counter).Should(BeNumerically("<=", 10))
|
||||
Ω(failureMessage).Should(ContainSubstring("Timed out after"))
|
||||
Ω(failureMessage).Should(MatchRegexp(`\<int\>: \d`), "Should pass the correct value to the matcher message formatter.")
|
||||
Ω(failureMessage).Should(ContainSubstring("My description 2"))
|
||||
Ω(callerSkip).Should(Equal(4))
|
||||
Expect(counter).Should(BeNumerically(">", 8))
|
||||
Expect(counter).Should(BeNumerically("<=", 10))
|
||||
Expect(failureMessage).Should(ContainSubstring("Timed out after"))
|
||||
Expect(failureMessage).Should(MatchRegexp(`\<int\>: \d`), "Should pass the correct value to the matcher message formatter.")
|
||||
Expect(failureMessage).Should(ContainSubstring("My description 2"))
|
||||
Expect(callerSkip).Should(Equal(4))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -79,38 +85,38 @@ var _ = Describe("Async Assertion", func() {
|
||||
a := New(AsyncAssertionTypeEventually, func() int {
|
||||
counter += 1
|
||||
return counter
|
||||
}, fakeFailHandler, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
}, fakeFailWrapper, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
|
||||
a.ShouldNot(BeNumerically("<", 3))
|
||||
|
||||
Ω(counter).Should(Equal(3))
|
||||
Ω(failureMessage).Should(BeZero())
|
||||
Expect(counter).Should(Equal(3))
|
||||
Expect(failureMessage).Should(BeZero())
|
||||
})
|
||||
|
||||
It("should timeout when the matcher errors", func() {
|
||||
a := New(AsyncAssertionTypeEventually, func() interface{} {
|
||||
return 0 //this should cause the matcher to error
|
||||
}, fakeFailHandler, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
}, fakeFailWrapper, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
|
||||
a.ShouldNot(HaveLen(0), "My description %d", 2)
|
||||
|
||||
Ω(failureMessage).Should(ContainSubstring("Timed out after"))
|
||||
Ω(failureMessage).Should(ContainSubstring("Error:"))
|
||||
Ω(failureMessage).Should(ContainSubstring("My description 2"))
|
||||
Ω(callerSkip).Should(Equal(4))
|
||||
Expect(failureMessage).Should(ContainSubstring("Timed out after"))
|
||||
Expect(failureMessage).Should(ContainSubstring("Error:"))
|
||||
Expect(failureMessage).Should(ContainSubstring("My description 2"))
|
||||
Expect(callerSkip).Should(Equal(4))
|
||||
})
|
||||
|
||||
It("should be able to timeout", func() {
|
||||
a := New(AsyncAssertionTypeEventually, func() int {
|
||||
return 0
|
||||
}, fakeFailHandler, time.Duration(0.1*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
}, fakeFailWrapper, time.Duration(0.1*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
|
||||
a.ShouldNot(Equal(0), "My description %d", 2)
|
||||
|
||||
Ω(failureMessage).Should(ContainSubstring("Timed out after"))
|
||||
Ω(failureMessage).Should(ContainSubstring("<int>: 0"), "Should pass the correct value to the matcher message formatter.")
|
||||
Ω(failureMessage).Should(ContainSubstring("My description 2"))
|
||||
Ω(callerSkip).Should(Equal(4))
|
||||
Expect(failureMessage).Should(ContainSubstring("Timed out after"))
|
||||
Expect(failureMessage).Should(ContainSubstring("<int>: 0"), "Should pass the correct value to the matcher message formatter.")
|
||||
Expect(failureMessage).Should(ContainSubstring("My description 2"))
|
||||
Expect(callerSkip).Should(Equal(4))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -128,13 +134,13 @@ var _ = Describe("Async Assertion", func() {
|
||||
a := New(AsyncAssertionTypeEventually, func() (int, error) {
|
||||
i++
|
||||
return i, errors.New("bam")
|
||||
}, fakeFailHandler, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
}, fakeFailWrapper, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
a.Should(Equal(2))
|
||||
|
||||
Ω(failureMessage).Should(ContainSubstring("Timed out after"))
|
||||
Ω(failureMessage).Should(ContainSubstring("Error:"))
|
||||
Ω(failureMessage).Should(ContainSubstring("bam"))
|
||||
Ω(callerSkip).Should(Equal(4))
|
||||
Expect(failureMessage).Should(ContainSubstring("Timed out after"))
|
||||
Expect(failureMessage).Should(ContainSubstring("Error:"))
|
||||
Expect(failureMessage).Should(ContainSubstring("bam"))
|
||||
Expect(callerSkip).Should(Equal(4))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -164,12 +170,12 @@ var _ = Describe("Async Assertion", func() {
|
||||
a := New(AsyncAssertionTypeConsistently, func() string {
|
||||
calls++
|
||||
return "foo"
|
||||
}, fakeFailHandler, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
}, fakeFailWrapper, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
|
||||
a.Should(Equal("foo"))
|
||||
Ω(calls).Should(BeNumerically(">", 8))
|
||||
Ω(calls).Should(BeNumerically("<=", 10))
|
||||
Ω(failureMessage).Should(BeZero())
|
||||
Expect(calls).Should(BeNumerically(">", 8))
|
||||
Expect(calls).Should(BeNumerically("<=", 10))
|
||||
Expect(failureMessage).Should(BeZero())
|
||||
})
|
||||
})
|
||||
|
||||
@@ -182,11 +188,11 @@ var _ = Describe("Async Assertion", func() {
|
||||
return "bar"
|
||||
}
|
||||
return "foo"
|
||||
}, fakeFailHandler, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
}, fakeFailWrapper, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
|
||||
a.Should(Equal("foo"))
|
||||
Ω(failureMessage).Should(ContainSubstring("to equal"))
|
||||
Ω(callerSkip).Should(Equal(4))
|
||||
Expect(failureMessage).Should(ContainSubstring("to equal"))
|
||||
Expect(callerSkip).Should(Equal(4))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -199,11 +205,11 @@ var _ = Describe("Async Assertion", func() {
|
||||
return 3
|
||||
}
|
||||
return []int{1, 2, 3}
|
||||
}, fakeFailHandler, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
}, fakeFailWrapper, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
|
||||
a.Should(HaveLen(3))
|
||||
Ω(failureMessage).Should(ContainSubstring("HaveLen matcher expects"))
|
||||
Ω(callerSkip).Should(Equal(4))
|
||||
Expect(failureMessage).Should(ContainSubstring("HaveLen matcher expects"))
|
||||
Expect(callerSkip).Should(Equal(4))
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -212,10 +218,10 @@ var _ = Describe("Async Assertion", func() {
|
||||
Context("when the matcher consistently passes for the duration", func() {
|
||||
It("should pass", func() {
|
||||
c := make(chan bool)
|
||||
a := New(AsyncAssertionTypeConsistently, c, fakeFailHandler, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
a := New(AsyncAssertionTypeConsistently, c, fakeFailWrapper, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
|
||||
a.ShouldNot(Receive())
|
||||
Ω(failureMessage).Should(BeZero())
|
||||
Expect(failureMessage).Should(BeZero())
|
||||
})
|
||||
})
|
||||
|
||||
@@ -227,10 +233,10 @@ var _ = Describe("Async Assertion", func() {
|
||||
c <- true
|
||||
}()
|
||||
|
||||
a := New(AsyncAssertionTypeConsistently, c, fakeFailHandler, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
a := New(AsyncAssertionTypeConsistently, c, fakeFailWrapper, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
|
||||
a.ShouldNot(Receive())
|
||||
Ω(failureMessage).Should(ContainSubstring("not to receive anything"))
|
||||
Expect(failureMessage).Should(ContainSubstring("not to receive anything"))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -240,11 +246,11 @@ var _ = Describe("Async Assertion", func() {
|
||||
a := New(AsyncAssertionTypeConsistently, func() interface{} {
|
||||
calls++
|
||||
return calls
|
||||
}, fakeFailHandler, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
}, fakeFailWrapper, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
|
||||
a.ShouldNot(BeNumerically(">", 5))
|
||||
Ω(failureMessage).Should(ContainSubstring("not to be >"))
|
||||
Ω(callerSkip).Should(Equal(4))
|
||||
Expect(failureMessage).Should(ContainSubstring("not to be >"))
|
||||
Expect(callerSkip).Should(Equal(4))
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -263,12 +269,12 @@ var _ = Describe("Async Assertion", func() {
|
||||
a := New(AsyncAssertionTypeEventually, func() (int, error) {
|
||||
i++
|
||||
return i, errors.New("bam")
|
||||
}, fakeFailHandler, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
}, fakeFailWrapper, time.Duration(0.2*float64(time.Second)), time.Duration(0.02*float64(time.Second)), 1)
|
||||
a.Should(BeNumerically(">=", 2))
|
||||
|
||||
Ω(failureMessage).Should(ContainSubstring("Error:"))
|
||||
Ω(failureMessage).Should(ContainSubstring("bam"))
|
||||
Ω(callerSkip).Should(Equal(4))
|
||||
Expect(failureMessage).Should(ContainSubstring("Error:"))
|
||||
Expect(failureMessage).Should(ContainSubstring("bam"))
|
||||
Expect(callerSkip).Should(Equal(4))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -291,20 +297,20 @@ var _ = Describe("Async Assertion", func() {
|
||||
|
||||
Context("when passed a function with the wrong # or arguments & returns", func() {
|
||||
It("should panic", func() {
|
||||
Ω(func() {
|
||||
New(AsyncAssertionTypeEventually, func() {}, fakeFailHandler, 0, 0, 1)
|
||||
Expect(func() {
|
||||
New(AsyncAssertionTypeEventually, func() {}, fakeFailWrapper, 0, 0, 1)
|
||||
}).Should(Panic())
|
||||
|
||||
Ω(func() {
|
||||
New(AsyncAssertionTypeEventually, func(a string) int { return 0 }, fakeFailHandler, 0, 0, 1)
|
||||
Expect(func() {
|
||||
New(AsyncAssertionTypeEventually, func(a string) int { return 0 }, fakeFailWrapper, 0, 0, 1)
|
||||
}).Should(Panic())
|
||||
|
||||
Ω(func() {
|
||||
New(AsyncAssertionTypeEventually, func() int { return 0 }, fakeFailHandler, 0, 0, 1)
|
||||
Expect(func() {
|
||||
New(AsyncAssertionTypeEventually, func() int { return 0 }, fakeFailWrapper, 0, 0, 1)
|
||||
}).ShouldNot(Panic())
|
||||
|
||||
Ω(func() {
|
||||
New(AsyncAssertionTypeEventually, func() (int, error) { return 0, nil }, fakeFailHandler, 0, 0, 1)
|
||||
Expect(func() {
|
||||
New(AsyncAssertionTypeEventually, func() (int, error) { return 0, nil }, fakeFailWrapper, 0, 0, 1)
|
||||
}).ShouldNot(Panic())
|
||||
})
|
||||
})
|
||||
@@ -319,9 +325,9 @@ var _ = Describe("Async Assertion", func() {
|
||||
failures := InterceptGomegaFailures(func() {
|
||||
Eventually(c, 0.1).Should(Receive())
|
||||
})
|
||||
Ω(time.Since(t)).Should(BeNumerically("<", 90*time.Millisecond))
|
||||
Expect(time.Since(t)).Should(BeNumerically("<", 90*time.Millisecond))
|
||||
|
||||
Ω(failures).Should(HaveLen(1))
|
||||
Expect(failures).Should(HaveLen(1))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -336,9 +342,9 @@ var _ = Describe("Async Assertion", func() {
|
||||
return c
|
||||
}, 0.1).Should(Receive())
|
||||
})
|
||||
Ω(time.Since(t)).Should(BeNumerically(">=", 90*time.Millisecond))
|
||||
Expect(time.Since(t)).Should(BeNumerically(">=", 90*time.Millisecond))
|
||||
|
||||
Ω(failures).Should(HaveLen(1))
|
||||
Expect(failures).Should(HaveLen(1))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user