syncthing/vendor/github.com/onsi/ginkgo/internal/writer/writer_test.go
Jakob Borg 65aaa607ab Use Go 1.5 vendoring instead of Godeps
Change made by:

- running "gvt fetch" on each of the packages mentioned in
  Godeps/Godeps.json
- `rm -rf Godeps`
- tweaking the build scripts to not mention Godeps
- tweaking the build scripts to test `./lib/...`, `./cmd/...` explicitly
  (to avoid testing vendor)
- tweaking the build scripts to not juggle GOPATH for Godeps and instead
  set GO15VENDOREXPERIMENT.

This also results in some updated packages at the same time I bet.

Building with Go 1.3 and 1.4 still *works* but won't use our vendored
dependencies - the user needs to have the actual packages in their
GOPATH then, which they'll get with a normal "go get". Building with Go
1.6+ will get our vendored dependencies by default even when not using
our build script, which is nice.

By doing this we gain some freedom in that we can pick and choose
manually what to include in vendor, as it's not based on just dependency
analysis of our own code. This is also a risk as we might pick up
dependencies we are unaware of, as the build may work locally with those
packages present in GOPATH. On the other hand the build server will
detect this as it has no packages in it's GOPATH beyond what is included
in the repo.

Recommended tool to manage dependencies is github.com/FiloSottile/gvt.
2016-03-05 21:21:24 +01:00

76 lines
1.8 KiB
Go

package writer_test
import (
"github.com/onsi/gomega/gbytes"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/internal/writer"
. "github.com/onsi/gomega"
)
var _ = Describe("Writer", func() {
var writer *Writer
var out *gbytes.Buffer
BeforeEach(func() {
out = gbytes.NewBuffer()
writer = New(out)
})
It("should stream directly to the outbuffer by default", func() {
writer.Write([]byte("foo"))
Ω(out).Should(gbytes.Say("foo"))
})
It("should not emit the header when asked to DumpOutWitHeader", func() {
writer.Write([]byte("foo"))
writer.DumpOutWithHeader("my header")
Ω(out).ShouldNot(gbytes.Say("my header"))
Ω(out).Should(gbytes.Say("foo"))
})
Context("when told not to stream", func() {
BeforeEach(func() {
writer.SetStream(false)
})
It("should only write to the buffer when told to DumpOut", func() {
writer.Write([]byte("foo"))
Ω(out).ShouldNot(gbytes.Say("foo"))
writer.DumpOut()
Ω(out).Should(gbytes.Say("foo"))
})
It("should truncate the internal buffer when told to truncate", func() {
writer.Write([]byte("foo"))
writer.Truncate()
writer.DumpOut()
Ω(out).ShouldNot(gbytes.Say("foo"))
writer.Write([]byte("bar"))
writer.DumpOut()
Ω(out).Should(gbytes.Say("bar"))
})
Describe("emitting a header", func() {
Context("when the buffer has content", func() {
It("should emit the header followed by the content", func() {
writer.Write([]byte("foo"))
writer.DumpOutWithHeader("my header")
Ω(out).Should(gbytes.Say("my header"))
Ω(out).Should(gbytes.Say("foo"))
})
})
Context("when the buffer has no content", func() {
It("should not emit the header", func() {
writer.DumpOutWithHeader("my header")
Ω(out).ShouldNot(gbytes.Say("my header"))
})
})
})
})
})