Example #1
0
File: expect.go Project: mmb/boosh
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,
	}
}
Example #2
0
				})

				It("fetches the file via the correct path", func() {
					Ω(fakeArtifactSource.StreamFileArgsForCall(0)).Should(Equal("build.yml"))
				})

				It("succeeds", func() {
					Ω(fetchErr).ShouldNot(HaveOccurred())
				})

				It("returns the unmarshalled config", func() {
					Ω(fetchedConfig).Should(Equal(someConfig))
				})

				It("closes the stream", func() {
					Ω(streamedOut.Closed()).Should(BeTrue())
				})
			})

			Context("when the artifact source provides an invalid configuration", func() {
				var streamedOut *gbytes.Buffer

				BeforeEach(func() {
					invalidConfig := someConfig
					invalidConfig.Platform = ""
					invalidConfig.Run = atc.TaskRunConfig{}

					marshalled, err := yaml.Marshal(invalidConfig)
					Ω(err).ShouldNot(HaveOccurred())

					streamedOut = gbytes.BufferWithBytes(marshalled)
Example #3
0
							It("streams out the given path", func() {
								reader, err := artifactSource.StreamFile("some-path")
								Ω(err).ShouldNot(HaveOccurred())

								Ω(ioutil.ReadAll(reader)).Should(Equal([]byte(fileContent)))

								Ω(fakeVersionedSource.StreamOutArgsForCall(0)).Should(Equal("some-path"))
							})

							Describe("closing the stream", func() {
								It("closes the stream from the versioned source", func() {
									reader, err := artifactSource.StreamFile("some-path")
									Ω(err).ShouldNot(HaveOccurred())

									Ω(tarBuffer.Closed()).Should(BeFalse())

									err = reader.Close()
									Ω(err).ShouldNot(HaveOccurred())

									Ω(tarBuffer.Closed()).Should(BeTrue())
								})
							})
						})

						Context("but the stream is empty", func() {
							It("returns ErrFileNotFound", func() {
								_, err := artifactSource.StreamFile("some-path")
								Ω(err).Should(MatchError(FileNotFoundError{Path: "some-path"}))
							})
						})
Example #4
0
							It("streams out the given path", func() {
								reader, err := artifactSource.StreamFile("some-path")
								Expect(err).NotTo(HaveOccurred())

								Expect(ioutil.ReadAll(reader)).To(Equal([]byte(fileContent)))

								Expect(fakeVersionedSource.StreamOutArgsForCall(0)).To(Equal("some-path"))
							})

							Describe("closing the stream", func() {
								It("closes the stream from the versioned source", func() {
									reader, err := artifactSource.StreamFile("some-path")
									Expect(err).NotTo(HaveOccurred())

									Expect(tarBuffer.Closed()).To(BeFalse())

									err = reader.Close()
									Expect(err).NotTo(HaveOccurred())

									Expect(tarBuffer.Closed()).To(BeTrue())
								})
							})
						})

						Context("but the stream is empty", func() {
							It("returns ErrFileNotFound", func() {
								_, err := artifactSource.StreamFile("some-path")
								Expect(err).To(MatchError(FileNotFoundError{Path: "some-path"}))
							})
						})
		})

		It("does not error", func() {
			Expect(runErr).NotTo(HaveOccurred())
		})

		It("asynchronously writes combined stdout and stderr", func() {
			Eventually(output).Should(gbytes.Say("hello"))
		})

		It("sends the status code", func() {
			Expect(<-exitStatus).To(Equal(uint32(0)))
		})

		It("closes the output writer", func() {
			Eventually(output.Closed()).Should(BeTrue())
		})

		Context("and the job has no git repository", func() {
			It("does not fetch from any repository", func() {
				Expect(vcsFetcher.FetchCallCount()).To(Equal(0))
			})
		})

		Context("and the job has a git repository", func() {
			var repoDir string

			BeforeEach(func() {
				var err error
				repoDir, err = ioutil.TempDir("", "docker-runner-unit-tests")
				Expect(err).NotTo(HaveOccurred())
Example #6
0
							Body: "some result",
							Mode: 0600,
						}},
					)
				})

				It("succeeds", func() {
					Expect(fetchErr).NotTo(HaveOccurred())
				})

				It("returns the result of the first file in the stream", func() {
					Expect(result).To(Equal("some result"))
				})

				It("closes the result stream", func() {
					Expect(fileStream.Closed()).To(BeTrue())
				})

				It("logs the fetching", func() {
					Expect(logger).To(gbytes.Say(sessionPrefix + ".fetching-container-result"))
					Expect(logger).To(gbytes.Say(sessionPrefix + ".succeeded-fetching-container-result"))
				})
			})

			Context("but the payload is too large", func() {
				BeforeEach(func() {
					test_helper.WriteTar(
						fileStream,
						[]test_helper.ArchiveFile{{
							Name: "some-file",
							Body: strings.Repeat("x", internal.MAX_RESULT_SIZE+1),
Example #7
0
					Expect(err).NotTo(HaveOccurred())

					err = tarWriter.Flush()
					Expect(err).NotTo(HaveOccurred())

					return buffer, nil
				}
			})

			It("uploads the specified file to the destination", func() {
				err := step.Perform()
				Expect(err).NotTo(HaveOccurred())

				Expect(uploadedPayload).NotTo(BeZero())

				Expect(buffer.Closed()).To(BeTrue())

				Expect(string(uploadedPayload)).To(Equal("expected-contents"))
			})

			It("logs the step", func() {
				err := step.Perform()
				Expect(err).NotTo(HaveOccurred())
				Expect(logger.TestSink.LogMessages()).To(ConsistOf([]string{
					"test.upload-step.upload-starting",
					"test.URLUploader.uploading",
					"test.URLUploader.succeeded-uploading",
					"test.upload-step.upload-successful",
				}))
			})
Example #8
0
				})

				It("fetches the file via the correct path", func() {
					Expect(fakeArtifactSource.StreamFileArgsForCall(0)).To(Equal("build.yml"))
				})

				It("succeeds", func() {
					Expect(fetchErr).NotTo(HaveOccurred())
				})

				It("returns the unmarshalled config", func() {
					Expect(fetchedConfig).To(Equal(someConfig))
				})

				It("closes the stream", func() {
					Expect(streamedOut.Closed()).To(BeTrue())
				})
			})

			Context("when the artifact source provides an invalid configuration", func() {
				var streamedOut *gbytes.Buffer

				BeforeEach(func() {
					invalidConfig := someConfig
					invalidConfig.Platform = ""
					invalidConfig.Run = atc.TaskRunConfig{}

					marshalled, err := yaml.Marshal(invalidConfig)
					Expect(err).NotTo(HaveOccurred())

					streamedOut = gbytes.BufferWithBytes(marshalled)