summaryrefslogtreecommitdiff
path: root/vendor/github.com/onsi/gomega/gbytes
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2019-06-24 11:29:13 +0200
committerValentin Rothberg <rothberg@redhat.com>2019-06-24 13:20:59 +0200
commitd697456dc90adbaf68224ed7c115b38d5855e582 (patch)
tree5fd88c48b34e7bead0028fa97e39f43f03880642 /vendor/github.com/onsi/gomega/gbytes
parenta3211b73c62a9fcc13f09305bf629ef507b26d34 (diff)
downloadpodman-d697456dc90adbaf68224ed7c115b38d5855e582.tar.gz
podman-d697456dc90adbaf68224ed7c115b38d5855e582.tar.bz2
podman-d697456dc90adbaf68224ed7c115b38d5855e582.zip
migrate to go-modules
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'vendor/github.com/onsi/gomega/gbytes')
-rw-r--r--vendor/github.com/onsi/gomega/gbytes/buffer_test.go205
-rw-r--r--vendor/github.com/onsi/gomega/gbytes/gbuffer_suite_test.go13
-rw-r--r--vendor/github.com/onsi/gomega/gbytes/io_wrappers_test.go188
-rw-r--r--vendor/github.com/onsi/gomega/gbytes/say_matcher_test.go169
4 files changed, 0 insertions, 575 deletions
diff --git a/vendor/github.com/onsi/gomega/gbytes/buffer_test.go b/vendor/github.com/onsi/gomega/gbytes/buffer_test.go
deleted file mode 100644
index 9d4e8279d..000000000
--- a/vendor/github.com/onsi/gomega/gbytes/buffer_test.go
+++ /dev/null
@@ -1,205 +0,0 @@
-package gbytes_test
-
-import (
- "io"
- "time"
-
- . "github.com/onsi/gomega/gbytes"
-
- "bytes"
-
- . "github.com/onsi/ginkgo"
- . "github.com/onsi/gomega"
-)
-
-type SlowReader struct {
- R io.Reader
- D time.Duration
-}
-
-func (s SlowReader) Read(p []byte) (int, error) {
- time.Sleep(s.D)
- return s.R.Read(p)
-}
-
-var _ = Describe("Buffer", func() {
- var buffer *Buffer
-
- BeforeEach(func() {
- buffer = NewBuffer()
- })
-
- Describe("dumping the entire contents of the buffer", func() {
- It("should return everything that's been written", func() {
- buffer.Write([]byte("abc"))
- buffer.Write([]byte("def"))
- Expect(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"))
- Expect(buffer.Contents()).Should(Equal([]byte("abcdef")))
- Expect(buffer).Should(Say("abc"))
- Expect(buffer).ShouldNot(Say("abc"))
- Expect(buffer).Should(Say("def"))
- })
- })
-
- Describe("creating a buffer that wraps a reader", func() {
- Context("for a well-behaved reader", func() {
- It("should buffer the contents of the reader", func() {
- reader := bytes.NewBuffer([]byte("abcdef"))
- buffer := BufferReader(reader)
- Eventually(buffer).Should(Say("abc"))
- Expect(buffer).ShouldNot(Say("abc"))
- Eventually(buffer).Should(Say("def"))
- Eventually(buffer.Closed).Should(BeTrue())
- })
- })
-
- Context("for a slow reader", func() {
- It("should allow Eventually to time out", func() {
- slowReader := SlowReader{
- R: bytes.NewBuffer([]byte("abcdef")),
- D: time.Second,
- }
- buffer := BufferReader(slowReader)
- failures := InterceptGomegaFailures(func() {
- Eventually(buffer, 100*time.Millisecond).Should(Say("abc"))
- })
- Expect(failures).ShouldNot(BeEmpty())
-
- fastReader := SlowReader{
- R: bytes.NewBuffer([]byte("abcdef")),
- D: time.Millisecond,
- }
- buffer = BufferReader(fastReader)
- Eventually(buffer, 100*time.Millisecond).Should(Say("abc"))
- Eventually(buffer.Closed).Should(BeTrue())
- })
- })
- })
-
- Describe("reading from a buffer", func() {
- It("should read the current contents of the buffer", func() {
- buffer := BufferWithBytes([]byte("abcde"))
-
- dest := make([]byte, 3)
- n, err := buffer.Read(dest)
- Expect(err).ShouldNot(HaveOccurred())
- Expect(n).Should(Equal(3))
- Expect(string(dest)).Should(Equal("abc"))
-
- dest = make([]byte, 3)
- n, err = buffer.Read(dest)
- Expect(err).ShouldNot(HaveOccurred())
- Expect(n).Should(Equal(2))
- Expect(string(dest[:n])).Should(Equal("de"))
-
- n, err = buffer.Read(dest)
- Expect(err).Should(Equal(io.EOF))
- Expect(n).Should(Equal(0))
- })
-
- Context("after the buffer has been closed", func() {
- It("returns an error", func() {
- buffer := BufferWithBytes([]byte("abcde"))
-
- buffer.Close()
-
- dest := make([]byte, 3)
- n, err := buffer.Read(dest)
- Expect(err).Should(HaveOccurred())
- Expect(n).Should(Equal(0))
- })
- })
- })
-
- Describe("detecting regular expressions", func() {
- It("should fire the appropriate channel when the passed in pattern matches, then close it", func(done Done) {
- go func() {
- time.Sleep(10 * time.Millisecond)
- buffer.Write([]byte("abcde"))
- }()
-
- A := buffer.Detect("%s", "a.c")
- B := buffer.Detect("def")
-
- var gotIt bool
- select {
- case gotIt = <-A:
- case <-B:
- Fail("should not have gotten here")
- }
-
- Expect(gotIt).Should(BeTrue())
- Eventually(A).Should(BeClosed())
-
- buffer.Write([]byte("f"))
- Eventually(B).Should(Receive())
- Eventually(B).Should(BeClosed())
-
- close(done)
- })
-
- It("should fast-forward the buffer upon detection", func(done Done) {
- buffer.Write([]byte("abcde"))
- <-buffer.Detect("abc")
- Expect(buffer).ShouldNot(Say("abc"))
- Expect(buffer).Should(Say("de"))
- close(done)
- })
-
- It("should only fast-forward the buffer when the channel is read, and only if doing so would not rewind it", func(done Done) {
- 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
- Expect(buffer).Should(Say("abcd"))
- <-A
- Expect(buffer).ShouldNot(Say("d"))
- Expect(buffer).Should(Say("e"))
- Eventually(A).Should(BeClosed())
- close(done)
- })
-
- It("should be possible to cancel a detection", func(done Done) {
- A := buffer.Detect("abc")
- B := buffer.Detect("def")
- buffer.CancelDetects()
- buffer.Write([]byte("abcdef"))
- Eventually(A).Should(BeClosed())
- Eventually(B).Should(BeClosed())
-
- Expect(buffer).Should(Say("bcde"))
- <-buffer.Detect("f")
- close(done)
- })
- })
-
- Describe("closing the buffer", func() {
- It("should error when further write attempts are made", func() {
- _, err := buffer.Write([]byte("abc"))
- Expect(err).ShouldNot(HaveOccurred())
-
- buffer.Close()
-
- _, err = buffer.Write([]byte("def"))
- Expect(err).Should(HaveOccurred())
-
- Expect(buffer.Contents()).Should(Equal([]byte("abc")))
- })
-
- It("should be closed", func() {
- Expect(buffer.Closed()).Should(BeFalse())
-
- buffer.Close()
-
- Expect(buffer.Closed()).Should(BeTrue())
- })
- })
-})
diff --git a/vendor/github.com/onsi/gomega/gbytes/gbuffer_suite_test.go b/vendor/github.com/onsi/gomega/gbytes/gbuffer_suite_test.go
deleted file mode 100644
index 3a7dc0612..000000000
--- a/vendor/github.com/onsi/gomega/gbytes/gbuffer_suite_test.go
+++ /dev/null
@@ -1,13 +0,0 @@
-package gbytes_test
-
-import (
- . "github.com/onsi/ginkgo"
- . "github.com/onsi/gomega"
-
- "testing"
-)
-
-func TestGbytes(t *testing.T) {
- RegisterFailHandler(Fail)
- RunSpecs(t, "Gbytes Suite")
-}
diff --git a/vendor/github.com/onsi/gomega/gbytes/io_wrappers_test.go b/vendor/github.com/onsi/gomega/gbytes/io_wrappers_test.go
deleted file mode 100644
index 3da973498..000000000
--- a/vendor/github.com/onsi/gomega/gbytes/io_wrappers_test.go
+++ /dev/null
@@ -1,188 +0,0 @@
-package gbytes_test
-
-import (
- "fmt"
- "io"
- "time"
-
- . "github.com/onsi/gomega/gbytes"
-
- . "github.com/onsi/ginkgo"
- . "github.com/onsi/gomega"
-)
-
-type FakeCloser struct {
- err error
- duration time.Duration
-}
-
-func (f FakeCloser) Close() error {
- time.Sleep(f.duration)
- return f.err
-}
-
-type FakeReader struct {
- err error
- duration time.Duration
-}
-
-func (f FakeReader) Read(p []byte) (int, error) {
- time.Sleep(f.duration)
- if f.err != nil {
- return 0, f.err
- }
-
- for i := 0; i < len(p); i++ {
- p[i] = 'a'
- }
-
- return len(p), nil
-}
-
-type FakeWriter struct {
- err error
- duration time.Duration
-}
-
-func (f FakeWriter) Write(p []byte) (int, error) {
- time.Sleep(f.duration)
- if f.err != nil {
- return 0, f.err
- }
-
- return len(p), nil
-}
-
-var _ = Describe("Io Wrappers", func() {
- Describe("TimeoutCloser", func() {
- var innerCloser io.Closer
- var timeoutCloser io.Closer
-
- JustBeforeEach(func() {
- timeoutCloser = TimeoutCloser(innerCloser, 20*time.Millisecond)
- })
-
- Context("when the underlying Closer closes with no error", func() {
- BeforeEach(func() {
- innerCloser = FakeCloser{}
- })
-
- It("returns with no error", func() {
- Expect(timeoutCloser.Close()).Should(Succeed())
- })
- })
-
- Context("when the underlying Closer closes with an error", func() {
- BeforeEach(func() {
- innerCloser = FakeCloser{err: fmt.Errorf("boom")}
- })
-
- It("returns the error", func() {
- Expect(timeoutCloser.Close()).Should(MatchError("boom"))
- })
- })
-
- Context("when the underlying Closer hangs", func() {
- BeforeEach(func() {
- innerCloser = FakeCloser{
- err: fmt.Errorf("boom"),
- duration: time.Hour,
- }
- })
-
- It("returns ErrTimeout", func() {
- Expect(timeoutCloser.Close()).Should(MatchError(ErrTimeout))
- })
- })
- })
-
- Describe("TimeoutReader", func() {
- var innerReader io.Reader
- var timeoutReader io.Reader
-
- JustBeforeEach(func() {
- timeoutReader = TimeoutReader(innerReader, 20*time.Millisecond)
- })
-
- Context("when the underlying Reader returns no error", func() {
- BeforeEach(func() {
- innerReader = FakeReader{}
- })
-
- It("returns with no error", func() {
- p := make([]byte, 5)
- n, err := timeoutReader.Read(p)
- Expect(n).Should(Equal(5))
- Expect(err).ShouldNot(HaveOccurred())
- Expect(p).Should(Equal([]byte("aaaaa")))
- })
- })
-
- Context("when the underlying Reader returns an error", func() {
- BeforeEach(func() {
- innerReader = FakeReader{err: fmt.Errorf("boom")}
- })
-
- It("returns the error", func() {
- p := make([]byte, 5)
- _, err := timeoutReader.Read(p)
- Expect(err).Should(MatchError("boom"))
- })
- })
-
- Context("when the underlying Reader hangs", func() {
- BeforeEach(func() {
- innerReader = FakeReader{err: fmt.Errorf("boom"), duration: time.Hour}
- })
-
- It("returns ErrTimeout", func() {
- p := make([]byte, 5)
- _, err := timeoutReader.Read(p)
- Expect(err).Should(MatchError(ErrTimeout))
- })
- })
- })
-
- Describe("TimeoutWriter", func() {
- var innerWriter io.Writer
- var timeoutWriter io.Writer
-
- JustBeforeEach(func() {
- timeoutWriter = TimeoutWriter(innerWriter, 20*time.Millisecond)
- })
-
- Context("when the underlying Writer returns no error", func() {
- BeforeEach(func() {
- innerWriter = FakeWriter{}
- })
-
- It("returns with no error", func() {
- n, err := timeoutWriter.Write([]byte("aaaaa"))
- Expect(n).Should(Equal(5))
- Expect(err).ShouldNot(HaveOccurred())
- })
- })
-
- Context("when the underlying Writer returns an error", func() {
- BeforeEach(func() {
- innerWriter = FakeWriter{err: fmt.Errorf("boom")}
- })
-
- It("returns the error", func() {
- _, err := timeoutWriter.Write([]byte("aaaaa"))
- Expect(err).Should(MatchError("boom"))
- })
- })
-
- Context("when the underlying Writer hangs", func() {
- BeforeEach(func() {
- innerWriter = FakeWriter{err: fmt.Errorf("boom"), duration: time.Hour}
- })
-
- It("returns ErrTimeout", func() {
- _, err := timeoutWriter.Write([]byte("aaaaa"))
- Expect(err).Should(MatchError(ErrTimeout))
- })
- })
- })
-})
diff --git a/vendor/github.com/onsi/gomega/gbytes/say_matcher_test.go b/vendor/github.com/onsi/gomega/gbytes/say_matcher_test.go
deleted file mode 100644
index 0055d4a1b..000000000
--- a/vendor/github.com/onsi/gomega/gbytes/say_matcher_test.go
+++ /dev/null
@@ -1,169 +0,0 @@
-package gbytes_test
-
-import (
- "time"
-
- . "github.com/onsi/gomega/gbytes"
-
- . "github.com/onsi/ginkgo"
- . "github.com/onsi/gomega"
-)
-
-type speaker struct {
- buffer *Buffer
-}
-
-func (s *speaker) Buffer() *Buffer {
- return s.buffer
-}
-
-var _ = Describe("SayMatcher", func() {
- var buffer *Buffer
-
- BeforeEach(func() {
- buffer = NewBuffer()
- buffer.Write([]byte("abc"))
- })
-
- Context("when actual is not a gexec Buffer, or a BufferProvider", func() {
- It("should error", func() {
- failures := InterceptGomegaFailures(func() {
- Expect("foo").Should(Say("foo"))
- })
- Expect(failures[0]).Should(ContainSubstring("*gbytes.Buffer"))
- })
- })
-
- Context("when a match is found", func() {
- It("should succeed", func() {
- Expect(buffer).Should(Say("abc"))
- })
-
- It("should support printf-like formatting", func() {
- 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() {
- Expect(buffer).Should(Say("a.c"))
- })
-
- It("should fastforward the buffer", func() {
- buffer.Write([]byte("def"))
- 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() {
- Expect(buffer).ShouldNot(Say("def"))
- })
-
- Context("when the buffer is closed", func() {
- BeforeEach(func() {
- buffer.Close()
- })
-
- It("should abort an eventually", func() {
- t := time.Now()
- failures := InterceptGomegaFailures(func() {
- Eventually(buffer).Should(Say("def"))
- })
- Eventually(buffer).ShouldNot(Say("def"))
- Expect(time.Since(t)).Should(BeNumerically("<", 500*time.Millisecond))
- Expect(failures).Should(HaveLen(1))
-
- t = time.Now()
- Eventually(buffer).Should(Say("abc"))
- 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"))
- Expect(time.Since(t)).Should(BeNumerically("<", 500*time.Millisecond))
- })
-
- It("should not error with a synchronous matcher", func() {
- 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() {
- Expect(buffer).Should(Say("abc"))
- buffer.Write([]byte("def"))
- failures := InterceptGomegaFailures(func() {
- Expect(buffer).Should(Say("abc"))
- })
- 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() {
- Expect(buffer).ShouldNot(Say("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() {
- Expect(buffer).ShouldNot(Say("def"))
- Expect(buffer).Should(Say("abc"))
- })
- })
-
- Context("a nice real-life example", func() {
- It("should behave well", func() {
- Expect(buffer).Should(Say("abc"))
- go func() {
- time.Sleep(10 * time.Millisecond)
- buffer.Write([]byte("def"))
- }()
- Expect(buffer).ShouldNot(Say("def"))
- Eventually(buffer).Should(Say("def"))
- })
- })
-
- Context("when actual is a BufferProvider", func() {
- It("should use actual's buffer", func() {
- s := &speaker{
- buffer: NewBuffer(),
- }
-
- Expect(s).ShouldNot(Say("abc"))
-
- s.Buffer().Write([]byte("abc"))
- Expect(s).Should(Say("abc"))
- })
-
- It("should abort an eventually", func() {
- s := &speaker{
- buffer: NewBuffer(),
- }
-
- s.buffer.Close()
-
- t := time.Now()
- failures := InterceptGomegaFailures(func() {
- Eventually(s).Should(Say("def"))
- })
- Expect(failures).Should(HaveLen(1))
- Expect(time.Since(t)).Should(BeNumerically("<", 500*time.Millisecond))
- })
- })
-})