forked from cerc-io/ipld-eth-server
Update dependencies
- uses newer version of go-ethereum required for go1.11
This commit is contained in:
+31
-31
@@ -33,20 +33,20 @@ var _ = Describe("Buffer", func() {
|
||||
It("should return everything that's been written", func() {
|
||||
buffer.Write([]byte("abc"))
|
||||
buffer.Write([]byte("def"))
|
||||
Ω(buffer.Contents()).Should(Equal([]byte("abcdef")))
|
||||
Expect(buffer.Contents()).Should(Equal([]byte("abcdef")))
|
||||
|
||||
Ω(buffer).Should(Say("bcd"))
|
||||
Ω(buffer.Contents()).Should(Equal([]byte("abcdef")))
|
||||
Expect(buffer).Should(Say("bcd"))
|
||||
Expect(buffer.Contents()).Should(Equal([]byte("abcdef")))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("creating a buffer with bytes", func() {
|
||||
It("should create the buffer with the cursor set to the beginning", func() {
|
||||
buffer := BufferWithBytes([]byte("abcdef"))
|
||||
Ω(buffer.Contents()).Should(Equal([]byte("abcdef")))
|
||||
Ω(buffer).Should(Say("abc"))
|
||||
Ω(buffer).ShouldNot(Say("abc"))
|
||||
Ω(buffer).Should(Say("def"))
|
||||
Expect(buffer.Contents()).Should(Equal([]byte("abcdef")))
|
||||
Expect(buffer).Should(Say("abc"))
|
||||
Expect(buffer).ShouldNot(Say("abc"))
|
||||
Expect(buffer).Should(Say("def"))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -56,7 +56,7 @@ var _ = Describe("Buffer", func() {
|
||||
reader := bytes.NewBuffer([]byte("abcdef"))
|
||||
buffer := BufferReader(reader)
|
||||
Eventually(buffer).Should(Say("abc"))
|
||||
Ω(buffer).ShouldNot(Say("abc"))
|
||||
Expect(buffer).ShouldNot(Say("abc"))
|
||||
Eventually(buffer).Should(Say("def"))
|
||||
Eventually(buffer.Closed).Should(BeTrue())
|
||||
})
|
||||
@@ -72,7 +72,7 @@ var _ = Describe("Buffer", func() {
|
||||
failures := InterceptGomegaFailures(func() {
|
||||
Eventually(buffer, 100*time.Millisecond).Should(Say("abc"))
|
||||
})
|
||||
Ω(failures).ShouldNot(BeEmpty())
|
||||
Expect(failures).ShouldNot(BeEmpty())
|
||||
|
||||
fastReader := SlowReader{
|
||||
R: bytes.NewBuffer([]byte("abcdef")),
|
||||
@@ -91,19 +91,19 @@ var _ = Describe("Buffer", func() {
|
||||
|
||||
dest := make([]byte, 3)
|
||||
n, err := buffer.Read(dest)
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
Ω(n).Should(Equal(3))
|
||||
Ω(string(dest)).Should(Equal("abc"))
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
Expect(n).Should(Equal(3))
|
||||
Expect(string(dest)).Should(Equal("abc"))
|
||||
|
||||
dest = make([]byte, 3)
|
||||
n, err = buffer.Read(dest)
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
Ω(n).Should(Equal(2))
|
||||
Ω(string(dest[:n])).Should(Equal("de"))
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
Expect(n).Should(Equal(2))
|
||||
Expect(string(dest[:n])).Should(Equal("de"))
|
||||
|
||||
n, err = buffer.Read(dest)
|
||||
Ω(err).Should(Equal(io.EOF))
|
||||
Ω(n).Should(Equal(0))
|
||||
Expect(err).Should(Equal(io.EOF))
|
||||
Expect(n).Should(Equal(0))
|
||||
})
|
||||
|
||||
Context("after the buffer has been closed", func() {
|
||||
@@ -114,8 +114,8 @@ var _ = Describe("Buffer", func() {
|
||||
|
||||
dest := make([]byte, 3)
|
||||
n, err := buffer.Read(dest)
|
||||
Ω(err).Should(HaveOccurred())
|
||||
Ω(n).Should(Equal(0))
|
||||
Expect(err).Should(HaveOccurred())
|
||||
Expect(n).Should(Equal(0))
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -137,7 +137,7 @@ var _ = Describe("Buffer", func() {
|
||||
Fail("should not have gotten here")
|
||||
}
|
||||
|
||||
Ω(gotIt).Should(BeTrue())
|
||||
Expect(gotIt).Should(BeTrue())
|
||||
Eventually(A).Should(BeClosed())
|
||||
|
||||
buffer.Write([]byte("f"))
|
||||
@@ -150,8 +150,8 @@ var _ = Describe("Buffer", func() {
|
||||
It("should fast-forward the buffer upon detection", func(done Done) {
|
||||
buffer.Write([]byte("abcde"))
|
||||
<-buffer.Detect("abc")
|
||||
Ω(buffer).ShouldNot(Say("abc"))
|
||||
Ω(buffer).Should(Say("de"))
|
||||
Expect(buffer).ShouldNot(Say("abc"))
|
||||
Expect(buffer).Should(Say("de"))
|
||||
close(done)
|
||||
})
|
||||
|
||||
@@ -159,10 +159,10 @@ var _ = Describe("Buffer", func() {
|
||||
buffer.Write([]byte("abcde"))
|
||||
A := buffer.Detect("abc")
|
||||
time.Sleep(20 * time.Millisecond) //give the goroutine a chance to detect and write to the channel
|
||||
Ω(buffer).Should(Say("abcd"))
|
||||
Expect(buffer).Should(Say("abcd"))
|
||||
<-A
|
||||
Ω(buffer).ShouldNot(Say("d"))
|
||||
Ω(buffer).Should(Say("e"))
|
||||
Expect(buffer).ShouldNot(Say("d"))
|
||||
Expect(buffer).Should(Say("e"))
|
||||
Eventually(A).Should(BeClosed())
|
||||
close(done)
|
||||
})
|
||||
@@ -175,7 +175,7 @@ var _ = Describe("Buffer", func() {
|
||||
Eventually(A).Should(BeClosed())
|
||||
Eventually(B).Should(BeClosed())
|
||||
|
||||
Ω(buffer).Should(Say("bcde"))
|
||||
Expect(buffer).Should(Say("bcde"))
|
||||
<-buffer.Detect("f")
|
||||
close(done)
|
||||
})
|
||||
@@ -184,22 +184,22 @@ var _ = Describe("Buffer", func() {
|
||||
Describe("closing the buffer", func() {
|
||||
It("should error when further write attempts are made", func() {
|
||||
_, err := buffer.Write([]byte("abc"))
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
|
||||
buffer.Close()
|
||||
|
||||
_, err = buffer.Write([]byte("def"))
|
||||
Ω(err).Should(HaveOccurred())
|
||||
Expect(err).Should(HaveOccurred())
|
||||
|
||||
Ω(buffer.Contents()).Should(Equal([]byte("abc")))
|
||||
Expect(buffer.Contents()).Should(Equal([]byte("abc")))
|
||||
})
|
||||
|
||||
It("should be closed", func() {
|
||||
Ω(buffer.Closed()).Should(BeFalse())
|
||||
Expect(buffer.Closed()).Should(BeFalse())
|
||||
|
||||
buffer.Close()
|
||||
|
||||
Ω(buffer.Closed()).Should(BeTrue())
|
||||
Expect(buffer.Closed()).Should(BeTrue())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
+12
-12
@@ -68,7 +68,7 @@ var _ = Describe("Io Wrappers", func() {
|
||||
})
|
||||
|
||||
It("returns with no error", func() {
|
||||
Ω(timeoutCloser.Close()).Should(Succeed())
|
||||
Expect(timeoutCloser.Close()).Should(Succeed())
|
||||
})
|
||||
})
|
||||
|
||||
@@ -78,7 +78,7 @@ var _ = Describe("Io Wrappers", func() {
|
||||
})
|
||||
|
||||
It("returns the error", func() {
|
||||
Ω(timeoutCloser.Close()).Should(MatchError("boom"))
|
||||
Expect(timeoutCloser.Close()).Should(MatchError("boom"))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -91,7 +91,7 @@ var _ = Describe("Io Wrappers", func() {
|
||||
})
|
||||
|
||||
It("returns ErrTimeout", func() {
|
||||
Ω(timeoutCloser.Close()).Should(MatchError(ErrTimeout))
|
||||
Expect(timeoutCloser.Close()).Should(MatchError(ErrTimeout))
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -112,9 +112,9 @@ var _ = Describe("Io Wrappers", func() {
|
||||
It("returns with no error", func() {
|
||||
p := make([]byte, 5)
|
||||
n, err := timeoutReader.Read(p)
|
||||
Ω(n).Should(Equal(5))
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
Ω(p).Should(Equal([]byte("aaaaa")))
|
||||
Expect(n).Should(Equal(5))
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
Expect(p).Should(Equal([]byte("aaaaa")))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -126,7 +126,7 @@ var _ = Describe("Io Wrappers", func() {
|
||||
It("returns the error", func() {
|
||||
p := make([]byte, 5)
|
||||
_, err := timeoutReader.Read(p)
|
||||
Ω(err).Should(MatchError("boom"))
|
||||
Expect(err).Should(MatchError("boom"))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -138,7 +138,7 @@ var _ = Describe("Io Wrappers", func() {
|
||||
It("returns ErrTimeout", func() {
|
||||
p := make([]byte, 5)
|
||||
_, err := timeoutReader.Read(p)
|
||||
Ω(err).Should(MatchError(ErrTimeout))
|
||||
Expect(err).Should(MatchError(ErrTimeout))
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -158,8 +158,8 @@ var _ = Describe("Io Wrappers", func() {
|
||||
|
||||
It("returns with no error", func() {
|
||||
n, err := timeoutWriter.Write([]byte("aaaaa"))
|
||||
Ω(n).Should(Equal(5))
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
Expect(n).Should(Equal(5))
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
@@ -170,7 +170,7 @@ var _ = Describe("Io Wrappers", func() {
|
||||
|
||||
It("returns the error", func() {
|
||||
_, err := timeoutWriter.Write([]byte("aaaaa"))
|
||||
Ω(err).Should(MatchError("boom"))
|
||||
Expect(err).Should(MatchError("boom"))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -181,7 +181,7 @@ var _ = Describe("Io Wrappers", func() {
|
||||
|
||||
It("returns ErrTimeout", func() {
|
||||
_, err := timeoutWriter.Write([]byte("aaaaa"))
|
||||
Ω(err).Should(MatchError(ErrTimeout))
|
||||
Expect(err).Should(MatchError(ErrTimeout))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
+3
-4
@@ -15,7 +15,7 @@ type BufferProvider interface {
|
||||
/*
|
||||
Say is a Gomega matcher that operates on gbytes.Buffers:
|
||||
|
||||
Ω(buffer).Should(Say("something"))
|
||||
Expect(buffer).Should(Say("something"))
|
||||
|
||||
will succeed if the unread portion of the buffer matches the regular expression "something".
|
||||
|
||||
@@ -36,12 +36,11 @@ In such cases, Say simply operates on the *gbytes.Buffer returned by Buffer()
|
||||
If the buffer is closed, the Say matcher will tell Eventually to abort.
|
||||
*/
|
||||
func Say(expected string, args ...interface{}) *sayMatcher {
|
||||
formattedRegexp := expected
|
||||
if len(args) > 0 {
|
||||
formattedRegexp = fmt.Sprintf(expected, args...)
|
||||
expected = fmt.Sprintf(expected, args...)
|
||||
}
|
||||
return &sayMatcher{
|
||||
re: regexp.MustCompile(formattedRegexp),
|
||||
re: regexp.MustCompile(expected),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+38
-32
@@ -1,9 +1,10 @@
|
||||
package gbytes_test
|
||||
|
||||
import (
|
||||
. "github.com/onsi/gomega/gbytes"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/gomega/gbytes"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
@@ -27,36 +28,41 @@ var _ = Describe("SayMatcher", func() {
|
||||
Context("when actual is not a gexec Buffer, or a BufferProvider", func() {
|
||||
It("should error", func() {
|
||||
failures := InterceptGomegaFailures(func() {
|
||||
Ω("foo").Should(Say("foo"))
|
||||
Expect("foo").Should(Say("foo"))
|
||||
})
|
||||
Ω(failures[0]).Should(ContainSubstring("*gbytes.Buffer"))
|
||||
Expect(failures[0]).Should(ContainSubstring("*gbytes.Buffer"))
|
||||
})
|
||||
})
|
||||
|
||||
Context("when a match is found", func() {
|
||||
It("should succeed", func() {
|
||||
Ω(buffer).Should(Say("abc"))
|
||||
Expect(buffer).Should(Say("abc"))
|
||||
})
|
||||
|
||||
It("should support printf-like formatting", func() {
|
||||
Ω(buffer).Should(Say("a%sc", "b"))
|
||||
Expect(buffer).Should(Say("a%sc", "b"))
|
||||
})
|
||||
|
||||
It("should match literal %", func() {
|
||||
buffer.Write([]byte("%"))
|
||||
Expect(buffer).Should(Say("abc%"))
|
||||
})
|
||||
|
||||
It("should use a regular expression", func() {
|
||||
Ω(buffer).Should(Say("a.c"))
|
||||
Expect(buffer).Should(Say("a.c"))
|
||||
})
|
||||
|
||||
It("should fastforward the buffer", func() {
|
||||
buffer.Write([]byte("def"))
|
||||
Ω(buffer).Should(Say("abcd"))
|
||||
Ω(buffer).Should(Say("ef"))
|
||||
Ω(buffer).ShouldNot(Say("[a-z]"))
|
||||
Expect(buffer).Should(Say("abcd"))
|
||||
Expect(buffer).Should(Say("ef"))
|
||||
Expect(buffer).ShouldNot(Say("[a-z]"))
|
||||
})
|
||||
})
|
||||
|
||||
Context("when no match is found", func() {
|
||||
It("should not error", func() {
|
||||
Ω(buffer).ShouldNot(Say("def"))
|
||||
Expect(buffer).ShouldNot(Say("def"))
|
||||
})
|
||||
|
||||
Context("when the buffer is closed", func() {
|
||||
@@ -70,65 +76,65 @@ var _ = Describe("SayMatcher", func() {
|
||||
Eventually(buffer).Should(Say("def"))
|
||||
})
|
||||
Eventually(buffer).ShouldNot(Say("def"))
|
||||
Ω(time.Since(t)).Should(BeNumerically("<", 500*time.Millisecond))
|
||||
Ω(failures).Should(HaveLen(1))
|
||||
Expect(time.Since(t)).Should(BeNumerically("<", 500*time.Millisecond))
|
||||
Expect(failures).Should(HaveLen(1))
|
||||
|
||||
t = time.Now()
|
||||
Eventually(buffer).Should(Say("abc"))
|
||||
Ω(time.Since(t)).Should(BeNumerically("<", 500*time.Millisecond))
|
||||
Expect(time.Since(t)).Should(BeNumerically("<", 500*time.Millisecond))
|
||||
})
|
||||
|
||||
It("should abort a consistently", func() {
|
||||
t := time.Now()
|
||||
Consistently(buffer, 2.0).ShouldNot(Say("def"))
|
||||
Ω(time.Since(t)).Should(BeNumerically("<", 500*time.Millisecond))
|
||||
Expect(time.Since(t)).Should(BeNumerically("<", 500*time.Millisecond))
|
||||
})
|
||||
|
||||
It("should not error with a synchronous matcher", func() {
|
||||
Ω(buffer).ShouldNot(Say("def"))
|
||||
Ω(buffer).Should(Say("abc"))
|
||||
Expect(buffer).ShouldNot(Say("def"))
|
||||
Expect(buffer).Should(Say("abc"))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Context("when a positive match fails", func() {
|
||||
It("should report where it got stuck", func() {
|
||||
Ω(buffer).Should(Say("abc"))
|
||||
Expect(buffer).Should(Say("abc"))
|
||||
buffer.Write([]byte("def"))
|
||||
failures := InterceptGomegaFailures(func() {
|
||||
Ω(buffer).Should(Say("abc"))
|
||||
Expect(buffer).Should(Say("abc"))
|
||||
})
|
||||
Ω(failures[0]).Should(ContainSubstring("Got stuck at:"))
|
||||
Ω(failures[0]).Should(ContainSubstring("def"))
|
||||
Expect(failures[0]).Should(ContainSubstring("Got stuck at:"))
|
||||
Expect(failures[0]).Should(ContainSubstring("def"))
|
||||
})
|
||||
})
|
||||
|
||||
Context("when a negative match fails", func() {
|
||||
It("should report where it got stuck", func() {
|
||||
failures := InterceptGomegaFailures(func() {
|
||||
Ω(buffer).ShouldNot(Say("abc"))
|
||||
Expect(buffer).ShouldNot(Say("abc"))
|
||||
})
|
||||
Ω(failures[0]).Should(ContainSubstring("Saw:"))
|
||||
Ω(failures[0]).Should(ContainSubstring("Which matches the unexpected:"))
|
||||
Ω(failures[0]).Should(ContainSubstring("abc"))
|
||||
Expect(failures[0]).Should(ContainSubstring("Saw:"))
|
||||
Expect(failures[0]).Should(ContainSubstring("Which matches the unexpected:"))
|
||||
Expect(failures[0]).Should(ContainSubstring("abc"))
|
||||
})
|
||||
})
|
||||
|
||||
Context("when a match is not found", func() {
|
||||
It("should not fastforward the buffer", func() {
|
||||
Ω(buffer).ShouldNot(Say("def"))
|
||||
Ω(buffer).Should(Say("abc"))
|
||||
Expect(buffer).ShouldNot(Say("def"))
|
||||
Expect(buffer).Should(Say("abc"))
|
||||
})
|
||||
})
|
||||
|
||||
Context("a nice real-life example", func() {
|
||||
It("should behave well", func() {
|
||||
Ω(buffer).Should(Say("abc"))
|
||||
Expect(buffer).Should(Say("abc"))
|
||||
go func() {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
buffer.Write([]byte("def"))
|
||||
}()
|
||||
Ω(buffer).ShouldNot(Say("def"))
|
||||
Expect(buffer).ShouldNot(Say("def"))
|
||||
Eventually(buffer).Should(Say("def"))
|
||||
})
|
||||
})
|
||||
@@ -139,10 +145,10 @@ var _ = Describe("SayMatcher", func() {
|
||||
buffer: NewBuffer(),
|
||||
}
|
||||
|
||||
Ω(s).ShouldNot(Say("abc"))
|
||||
Expect(s).ShouldNot(Say("abc"))
|
||||
|
||||
s.Buffer().Write([]byte("abc"))
|
||||
Ω(s).Should(Say("abc"))
|
||||
Expect(s).Should(Say("abc"))
|
||||
})
|
||||
|
||||
It("should abort an eventually", func() {
|
||||
@@ -156,8 +162,8 @@ var _ = Describe("SayMatcher", func() {
|
||||
failures := InterceptGomegaFailures(func() {
|
||||
Eventually(s).Should(Say("def"))
|
||||
})
|
||||
Ω(failures).Should(HaveLen(1))
|
||||
Ω(time.Since(t)).Should(BeNumerically("<", 500*time.Millisecond))
|
||||
Expect(failures).Should(HaveLen(1))
|
||||
Expect(time.Since(t)).Should(BeNumerically("<", 500*time.Millisecond))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user