func captureStdout(buf *gbytes.Buffer) *os.File { stdout := os.Stdout r, w, err := os.Pipe() Expect(err).NotTo(HaveOccurred()) os.Stdout = w go func() { _, err = io.Copy(buf, r) buf.Close() r.Close() }() Expect(err).NotTo(HaveOccurred()) return stdout }
func NewBufferExpector(buffer *gbytes.Buffer, defaultTimeout time.Duration) *Expector { closed := make(chan struct{}) go func() { for { if buffer.Closed() { close(closed) break } time.Sleep(100 * time.Millisecond) } }() return &Expector{ defaultTimeout: defaultTimeout, buffer: buffer, closed: closed, } }
func expectExitInBuffer(timeout time.Duration, session *gexec.Session, outputBuffer *gbytes.Buffer) { Eventually(session, timeout).Should(gexec.Exit(0)) Expect(string(outputBuffer.Contents())).To(HaveSuffix("\n")) }
"github.com/concourse/atc" "github.com/concourse/atc/event" . "github.com/concourse/fly/eventstream" "github.com/concourse/fly/eventstream/fakes" "github.com/mgutz/ansi" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" ) var _ = Describe("V1.0 Renderer", func() { var ( out *gbytes.Buffer stream *fakes.FakeEventStream receivedEvents chan<- atc.Event exitStatus int ) BeforeEach(func() { out = gbytes.NewBuffer() stream = new(fakes.FakeEventStream) events := make(chan atc.Event, 100) receivedEvents = events stream.NextEventStub = func() (atc.Event, error) { select { case ev := <-events: return ev, nil
"fmt" "io" "os/exec" "syscall" "github.com/cloudfoundry-incubator/garden-linux/container_daemon" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" "github.com/pivotal-golang/lager/lagertest" ) var _ = Describe("Signalling a running process", func() { var pid int var signaller *container_daemon.ProcessSignaller var stdout *gbytes.Buffer BeforeEach(func() { stdout = gbytes.NewBuffer() cmd := exec.Command("bash", "-c", ` trap "echo TERMed; exit" TERM echo "pid = $$" sleep 2 `) cmd.Stdout = io.MultiWriter(stdout, GinkgoWriter) cmd.Stderr = GinkgoWriter err := cmd.Start() Expect(err).NotTo(HaveOccurred()) Eventually(stdout).Should(gbytes.Say("pid"))
BeforeEach(func() { fakeVersionedSource.StreamOutReturns(nil, disaster) }) It("returns the error", func() { Ω(artifactSource.StreamTo(fakeDestination)).Should(Equal(disaster)) }) }) }) Describe("streaming a file out", func() { Context("when the resource can stream out", func() { var ( fileContent = "file-content" tarBuffer *gbytes.Buffer ) BeforeEach(func() { tarBuffer = gbytes.NewBuffer() fakeVersionedSource.StreamOutReturns(tarBuffer, nil) }) Context("when the file exists", func() { BeforeEach(func() { tarWriter := tar.NewWriter(tarBuffer) err := tarWriter.WriteHeader(&tar.Header{ Name: "some-file", Mode: 0644,
"io" "strings" "time" . "github.com/vito/go-sse/sse" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" ) var _ = Describe("readCloser", func() { var ( eventStream string buffer *gbytes.Buffer readCloser *ReadCloser ) BeforeEach(func() { eventStream = "" buffer = gbytes.NewBuffer() readCloser = NewReadCloser(buffer) }) Describe("Next", func() { JustBeforeEach(func() { _, err := buffer.Write([]byte(eventStream))
"github.com/craigfurman/woodhouse-ci/jobs" "github.com/craigfurman/woodhouse-ci/runner" "github.com/craigfurman/woodhouse-ci/runner/fake_vcs_fetcher" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" ) var _ = Describe("DockerRunner", func() { var ( r *runner.DockerRunner vcsFetcher *fake_vcs_fetcher.FakeVcsFetcher cmd string rootFS string gitRepository string runErr error output *gbytes.Buffer exitStatus chan uint32 ) BeforeEach(func() { vcsFetcher = new(fake_vcs_fetcher.FakeVcsFetcher) r = runner.NewDockerRunner(vcsFetcher) output = gbytes.NewBuffer() exitStatus = make(chan uint32, 1) }) JustBeforeEach(func() { job := jobs.Job{
package metricsreporter_test import ( "tools/metronbenchmark/metricsreporter" "time" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" ) var _ = Describe("Metricsreporter", func() { var buffer *gbytes.Buffer var reporter *metricsreporter.MetricsReporter BeforeEach(func() { buffer = gbytes.NewBuffer() reporter = metricsreporter.New(time.Millisecond, buffer) go reporter.Start() }) AfterEach(func() { buffer.Close() reporter.Stop() }) It("should increment sent counter", func() { reporter.IncrementSentMessages() reporter.IncrementSentMessages() Eventually(buffer).Should(gbytes.Say("2, 0"))
filename string result string fetchErr error ) BeforeEach(func() { filename = "some-filename" }) JustBeforeEach(func() { result, fetchErr = containerDelegate.FetchContainerResultFile(logger, expectedGuid, filename) }) Context("when fetching the file stream from the container succeeds", func() { var fileStream *gbytes.Buffer BeforeEach(func() { fileStream = gbytes.NewBuffer() executorClient.GetFilesReturns(fileStream, nil) }) Context("and the payload is a reasonable size", func() { BeforeEach(func() { test_helper.WriteTar( fileStream, []test_helper.ArchiveFile{{ Name: "some-file", Body: "some result", Mode: 0600, }},
Describe("Get current version", func() { It("Gets a version from a tagged version", func() { version := UpdateGetCurrentVersion("right_st v98.76.54 - JUNK JUNK JUNK") Expect(version).To(Equal(&Version{98, 76, 54})) }) It("Gets no version for a dev version", func() { version := UpdateGetCurrentVersion("right_st master - JUNK JUNK JUNK") Expect(version).To(BeNil()) }) }) Context("With a update versions URL", func() { var ( buffer *gbytes.Buffer server *httptest.Server newExeContent string oldUpdateBaseUrl string ) BeforeEach(func() { buffer = gbytes.NewBuffer() exeItem := "right_st/right_st" if runtime.GOOS == "windows" { exeItem += ".exe" } tgzPath := regexp.MustCompile(`^/v[0-9]+\.[0-9]+\.[0-9]+/right_st-` + runtime.GOOS + `-` + runtime.GOARCH + `\.tgz$`) zipPath := regexp.MustCompile(`^/v[0-9]+\.[0-9]+\.[0-9]+/right_st-` + runtime.GOOS + `-` + runtime.GOARCH + `\.zip$`) server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { switch {
Data: []byte("some-data\nsome-more-data\n"), }.Encode()).Should(Equal("id: some-id\nevent: some-name\ndata: some-data\ndata: some-more-data\ndata\n\n")) }) It("includes retry if present", func() { Ω(Event{ ID: "some-id", Name: "some-name", Data: []byte("some-data"), Retry: 123 * time.Millisecond, }.Encode()).Should(Equal("id: some-id\nevent: some-name\nretry: 123\ndata: some-data\n\n")) }) }) Describe("Write", func() { var destination *gbytes.Buffer BeforeEach(func() { destination = gbytes.NewBuffer() }) It("writes the encoded event to the destination", func() { event := Event{ ID: "some-id", Name: "some-name", Data: []byte("some-data\nsome-more-data\n"), } err := event.Write(destination) Ω(err).ShouldNot(HaveOccurred())
. "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" "github.com/concourse/atc" "github.com/concourse/atc/event" "github.com/concourse/fly/eventstream" "github.com/concourse/fly/ui" "github.com/concourse/go-concourse/concourse/eventstream/fakes" ) var _ = Describe("V1.0 Renderer", func() { var ( out *gbytes.Buffer stream *fakes.FakeEventStream receivedEvents chan<- atc.Event exitStatus int ) BeforeEach(func() { color.NoColor = false out = gbytes.NewBuffer() stream = new(fakes.FakeEventStream) events := make(chan atc.Event, 100) receivedEvents = events stream.NextEventStub = func() (atc.Event, error) { select { case ev := <-events:
"github.com/cloudfoundry/cli/cf/commandregistry" "github.com/cloudfoundry/cli/cf/configuration/confighelpers" "github.com/cloudfoundry/cli/cf/help" "github.com/cloudfoundry/cli/testhelpers/io" "os" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" ) var _ = Describe("Help", func() { var buffer *gbytes.Buffer BeforeEach(func() { buffer = gbytes.NewBuffer() }) AfterEach(func() { buffer.Close() }) It("shows help for all commands", func() { dummyTemplate := ` {{range .Commands}}{{range .CommandSubGroups}}{{range .}} {{.Name}} {{end}}{{end}}{{end}} ` help.ShowHelp(buffer, dummyTemplate)
"github.com/cloudfoundry-incubator/lattice/ltc/exit_handler/fake_exit_handler" "github.com/cloudfoundry-incubator/lattice/ltc/terminal" "github.com/cloudfoundry-incubator/lattice/ltc/terminal/password_reader/fake_password_reader" "github.com/cloudfoundry-incubator/lattice/ltc/test_helpers" "github.com/codegangsta/cli" config_package "github.com/cloudfoundry-incubator/lattice/ltc/config" ) var _ = Describe("CommandFactory", func() { var ( stdinReader *io.PipeReader stdinWriter *io.PipeWriter outputBuffer *gbytes.Buffer terminalUI terminal.UI config *config_package.Config configPersister persister.Persister fakeTargetVerifier *fake_target_verifier.FakeTargetVerifier fakeBlobStoreVerifier *fake_blob_store_verifier.FakeBlobStoreVerifier fakeExitHandler *fake_exit_handler.FakeExitHandler fakePasswordReader *fake_password_reader.FakePasswordReader ) BeforeEach(func() { stdinReader, stdinWriter = io.Pipe() outputBuffer = gbytes.NewBuffer() fakeExitHandler = &fake_exit_handler.FakeExitHandler{} fakePasswordReader = &fake_password_reader.FakePasswordReader{} terminalUI = terminal.NewUI(stdinReader, outputBuffer, fakePasswordReader) fakeTargetVerifier = &fake_target_verifier.FakeTargetVerifier{} fakeBlobStoreVerifier = &fake_blob_store_verifier.FakeBlobStoreVerifier{} configPersister = persister.NewMemPersister()
step = steps.NewUpload( container, *uploadAction, uploader, compressor, tempDir, fakeStreamer, make(chan struct{}, 1), logger, ) }) Describe("Perform", func() { Context("when streaming out works", func() { var buffer *gbytes.Buffer BeforeEach(func() { buffer = gbytes.NewBuffer() gardenClient.Connection.StreamOutStub = func(handle string, spec garden.StreamOutSpec) (io.ReadCloser, error) { Expect(spec.Path).To(Equal("./expected-src.txt")) Expect(spec.User).To(Equal("notroot")) Expect(handle).To(Equal("some-container-handle")) tarWriter := tar.NewWriter(buffer) dropletContents := "expected-contents" err := tarWriter.WriteHeader(&tar.Header{ Name: "./expected-src.txt",
"github.com/cloudfoundry/cli/cf/terminal/terminalfakes" "github.com/cloudfoundry/cli/flags" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" ) var _ = Describe("Help", func() { commandsloader.Load() var ( fakeFactory *testreq.FakeReqFactory fakeUI *terminalfakes.FakeUI fakeConfig *pluginconfigfakes.FakePluginConfiguration deps commandregistry.Dependency cmd *commands.Help flagContext flags.FlagContext buffer *gbytes.Buffer ) BeforeEach(func() { buffer = gbytes.NewBuffer() fakeUI = new(terminalfakes.FakeUI) fakeUI.WriterReturns(buffer) fakeConfig = new(pluginconfigfakes.FakePluginConfiguration) deps = commandregistry.Dependency{ UI: fakeUI, PluginConfig: fakeConfig,
package test_helpers_test import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" "github.com/cloudfoundry-incubator/lattice/ltc/test_helpers" ) var _ = Describe("RegexSafeSay", func() { var outputBuffer *gbytes.Buffer BeforeEach(func() { outputBuffer = gbytes.NewBuffer() }) Describe("Say", func() { BeforeEach(func() { outputBuffer.Write([]byte(`match this \|?-^$.(){}`)) }) It("matches with regex-escaped characters", func() { Expect(outputBuffer).To(test_helpers.Say(`match this \|?-^$.(){}`)) }) It("negated match", func() { Expect(outputBuffer).NotTo(test_helpers.Say("match that")) }) Context("when format string is passed with arguments", func() { It("matches with regex-escaped characters", func() { Expect(outputBuffer).To(test_helpers.Say(`match %s \|?-^$.(){}`, "this")) })
. "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" ) var _ = Describe("RightScript Scaffold", func() { var ( buffer *gbytes.Buffer tempDir string emptyScript string emptyScriptMetadata string metadataScript string metadataScriptContents string shellScript string shellScriptContents string shellScriptMetadata string rubyScript string rubyScriptContents string rubyScriptMetadata string perlScript string perlScriptContents string perlScriptMetadata string powershellScript string powershellScriptContents string powershellScriptMetadata string ) BeforeEach(func() { buffer = gbytes.NewBuffer() var err error tempDir, err = ioutil.TempDir("", "scaffold") if err != nil {
. "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" ) var _ = Describe("RightScript Metadata", func() { var ( validScript io.ReadSeeker noMetadataScript io.ReadSeeker missingEndDelimiterScript io.ReadSeeker invalidYamlSyntaxScript io.ReadSeeker invalidMetadataStructureScript io.ReadSeeker incorrectInputTypeSyntaxScript io.ReadSeeker incorrectInputValueSyntaxScript io.ReadSeeker emptyTextValueScript io.ReadSeeker unknownFieldScript io.ReadSeeker buffer *gbytes.Buffer emptyMetadata RightScriptMetadata emptyMetadataScript string populatedMetadata RightScriptMetadata populatedMetadataScript string differentCommentMetadata RightScriptMetadata differentCommentMetadataScript string ) BeforeEach(func() { validScript = strings.NewReader(`#!/bin/bash # --- # RightScript Name: Some RightScript Name # Description: Some description of stuff # Inputs:
BeforeEach(func() { fakeVersionedSource.StreamOutReturns(nil, disaster) }) It("returns the error", func() { Expect(artifactSource.StreamTo(fakeDestination)).To(Equal(disaster)) }) }) }) Describe("streaming a file out", func() { Context("when the resource can stream out", func() { var ( fileContent = "file-content" tarBuffer *gbytes.Buffer ) BeforeEach(func() { tarBuffer = gbytes.NewBuffer() fakeVersionedSource.StreamOutReturns(tarBuffer, nil) }) Context("when the file exists", func() { BeforeEach(func() { tarWriter := tar.NewWriter(tarBuffer) err := tarWriter.WriteHeader(&tar.Header{ Name: "some-file", Mode: 0644,
. "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" ) var _ = Describe("Config", func() { It("Gets the default config file", func() { configFile := DefaultConfigFile() Expect(filepath.Base(configFile)).To(Equal(".right_st.yml")) Expect(filepath.IsAbs(configFile)).To(BeTrue()) }) Describe("Read config", func() { var ( tempDir string buffer *gbytes.Buffer ) BeforeEach(func() { var err error tempDir, err = ioutil.TempDir("", "config") if err != nil { panic(err) } buffer = gbytes.NewBuffer() }) AfterEach(func() { os.RemoveAll(tempDir) })
It("returns an error", func() { Ω(fetchErr).Should(Equal(UnspecifiedArtifactSourceError{"foo-bar.yml"})) }) }) Context("when the file's artifact source can be found in the repository", func() { var fakeArtifactSource *fakes.FakeArtifactSource BeforeEach(func() { fakeArtifactSource = new(fakes.FakeArtifactSource) repo.RegisterSource("some", fakeArtifactSource) }) Context("when the artifact source provides a proper file", func() { var streamedOut *gbytes.Buffer BeforeEach(func() { marshalled, err := yaml.Marshal(someConfig) Ω(err).ShouldNot(HaveOccurred()) streamedOut = gbytes.BufferWithBytes(marshalled) fakeArtifactSource.StreamFileReturns(streamedOut, nil) }) It("fetches the file via the correct path", func() { Ω(fakeArtifactSource.StreamFileArgsForCall(0)).Should(Equal("build.yml")) }) It("succeeds", func() { Ω(fetchErr).ShouldNot(HaveOccurred())
"github.com/concourse/s3-resource" "github.com/concourse/s3-resource/fakes" "github.com/concourse/s3-resource/out" "github.com/onsi/gomega/gbytes" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("Out Command", func() { Describe("running the command", func() { var ( tmpPath string sourceDir string request out.OutRequest stderr *gbytes.Buffer s3client *fakes.FakeS3Client command *out.OutCommand ) BeforeEach(func() { var err error tmpPath, err = ioutil.TempDir("", "out_command") Ω(err).ShouldNot(HaveOccurred()) sourceDir = filepath.Join(tmpPath, "source") err = os.MkdirAll(sourceDir, 0755) Ω(err).ShouldNot(HaveOccurred()) request = out.OutRequest{
func (p *testProcessor) Shutdown(reason string, cp *CheckPointer) error { return nil } type ginkgoLogger struct { } func (l *ginkgoLogger) Printf(format string, v ...interface{}) { GinkgoWriter.Write([]byte(fmt.Sprintf(format, v...))) GinkgoWriter.Write([]byte{0xa}) //new line } var _ = Describe("Message", func() { Describe("receive normal message", func() { var stdin *gbytes.Buffer var stdout *gbytes.Buffer var processor RecordProcessor var shardID string BeforeEach(func() { SetLogger(&ginkgoLogger{}) stdin = gbytes.NewBuffer() stdout = gbytes.NewBuffer() processor = &testProcessor{} shardID = uuid.NewRandom().String() go RunIO(processor, stdin, stdout) })
package test_helpers_test import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" "github.com/cloudfoundry-incubator/lattice/ltc/test_helpers" ) var _ = Describe("RegexSafeSay", func() { var gbytesBuffer *gbytes.Buffer BeforeEach(func() { gbytesBuffer = gbytes.NewBuffer() }) Describe("Say", func() { It("matches with regex-escaped characters", func() { gbytesBuffer.Write([]byte(`match this \|?-^$.(){}`)) Expect(gbytesBuffer).To(test_helpers.Say(`match this \|?-^$.(){}`)) }) It("negated match", func() { gbytesBuffer.Write([]byte("say that")) Expect(gbytesBuffer).ToNot(test_helpers.Say("different")) }) })
import ( "fmt" "os" "syscall" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" "github.com/cloudfoundry-incubator/ltc/exit_handler" ) var _ = Describe("ExitHandler", func() { var ( buffer *gbytes.Buffer exitFunc func(int) signalChan chan os.Signal exitHandler exit_handler.ExitHandler ) BeforeEach(func() { buffer = gbytes.NewBuffer() exitFunc = func(code int) { buffer.Write([]byte(fmt.Sprintf("Exit-Code=%d", code))) } signalChan = make(chan os.Signal) exitHandler = exit_handler.New(signalChan, exitFunc) go exitHandler.Run() exitHandler.OnExit(func() {
It("returns an error", func() { Expect(fetchErr).To(Equal(UnspecifiedArtifactSourceError{"foo-bar.yml"})) }) }) Context("when the file's artifact source can be found in the repository", func() { var fakeArtifactSource *fakes.FakeArtifactSource BeforeEach(func() { fakeArtifactSource = new(fakes.FakeArtifactSource) repo.RegisterSource("some", fakeArtifactSource) }) Context("when the artifact source provides a proper file", func() { var streamedOut *gbytes.Buffer BeforeEach(func() { marshalled, err := yaml.Marshal(someConfig) Expect(err).NotTo(HaveOccurred()) streamedOut = gbytes.BufferWithBytes(marshalled) fakeArtifactSource.StreamFileReturns(streamedOut, nil) }) It("fetches the file via the correct path", func() { Expect(fakeArtifactSource.StreamFileArgsForCall(0)).To(Equal("build.yml")) }) It("succeeds", func() { Expect(fetchErr).NotTo(HaveOccurred())