Exemplo n.º 1
0
	"github.com/onsi/gomega/gexec"
)

const maxUpdDatagramSize = 65507

var _ = Describe("tee2metron", func() {
	It("prints stdout and stderr and streams them to metron", func() {
		metronReceivedBuffer, port := startFakeMetron()
		dropsondeDestinationFlag := "-dropsondeDestination=127.0.0.1:" + port
		command := exec.Command(tee2MetronPath, dropsondeDestinationFlag, "-sourceInstance=cell-123", chattyProcessPath, "chattyArg1", "chattyArg2", "-chattyFlag")

		session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
		Expect(err).NotTo(HaveOccurred())

		Consistently(session.Exited).ShouldNot(BeClosed())
		Eventually(gbytes.BufferWithBytes(*metronReceivedBuffer)).Should(gbytes.Say(chattyProcessPath))
		Eventually(gbytes.BufferWithBytes(*metronReceivedBuffer)).Should(gbytes.Say("lattice-debug"))
		Eventually(gbytes.BufferWithBytes(*metronReceivedBuffer)).Should(gbytes.Say("cell-123"))
		Eventually(gbytes.BufferWithBytes(*metronReceivedBuffer), 5).Should(gbytes.Say("Hi from stdout. My args are: [chattyArg1 chattyArg2 -chattyFlag]"))
		Eventually(gbytes.BufferWithBytes(*metronReceivedBuffer), 5).Should(gbytes.Say("Oopsie from stderr"))

		Eventually(session.Terminate()).Should(gexec.Exit(2))
		Expect(session.Out).To(gbytes.Say("Hi from stdout. My args are: [chattyArg1 chattyArg2 -chattyFlag]"))
		Expect(session.Err).To(gbytes.Say("Oopsie from stderr"))
	})

	Context("with a bad command", func() {
		Context("when the command is missing", func() {
			It("prints and error message and exits", func() {
				command := exec.Command(tee2MetronPath, "-dropsondeDestination=127.0.0.1:4000", "-sourceInstance=cell-123")
				session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Exemplo n.º 2
0
		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())
				})

				It("returns the unmarshalled config", func() {
					Ω(fetchedConfig).Should(Equal(someConfig))
				})
Exemplo n.º 3
0
		Ω(outputs).To(ContainSubstring(" --intFlag"))
		Ω(outputs).To(ContainSubstring(" -m"))
		Ω(outputs).To(ContainSubstring(" -f"))
		Ω(outputs).To(ContainSubstring(" --boolFlag, -b"))
	})

	It("prefixes the flag name with spaces", func() {
		outputs := fc.ShowUsage(5)
		Ω(outputs).To(ContainSubstring("     --intFlag"))
		Ω(outputs).To(ContainSubstring("     -f"))
		Ω(outputs).To(ContainSubstring("     --boolFlag"))
	})

	It("prints the usages with non-bool flags first", func() {
		outputs := fc.ShowUsage(0)
		buffer := gbytes.BufferWithBytes([]byte(outputs))
		Eventually(buffer).Should(gbytes.Say("intFlag"))
		Eventually(buffer).Should(gbytes.Say("Usage for intFlag"))
		Eventually(buffer).Should(gbytes.Say("boolFlag"))
		Eventually(buffer).Should(gbytes.Say("Usage for boolFlag"))
		Ω(outputs).To(ContainSubstring("f"))
		Ω(outputs).To(ContainSubstring("Usage for f"))
	})

	It("prefixes the non-bool flag with '-'", func() {
		outputs := fc.ShowUsage(0)
		Ω(outputs).To(ContainSubstring("-intFlag"))
	})

	It("prefixes single character bool flags with '-'", func() {
		outputs := fc.ShowUsage(0)
Exemplo n.º 4
0
		Context("when authenticated", func() {
			BeforeEach(func() {
				authValidator.IsAuthenticatedReturns(true)
			})

			Context("when a config version is specified", func() {
				BeforeEach(func() {
					request.Header.Set(atc.ConfigVersionHeader, "42")
				})

				Context("when the config is malformed", func() {
					Context("JSON", func() {
						BeforeEach(func() {
							request.Header.Set("Content-Type", "application/json")
							request.Body = gbytes.BufferWithBytes([]byte(`{`))
						})

						It("returns 400", func() {
							Expect(response.StatusCode).To(Equal(http.StatusBadRequest))
						})

						It("does not save anything", func() {
							Expect(configDB.SaveConfigCallCount()).To(Equal(0))
						})
					})

					Context("YAML", func() {
						BeforeEach(func() {
							request.Header.Set("Content-Type", "application/x-yaml")
							request.Body = gbytes.BufferWithBytes([]byte(`{`))
				aggregator.Point{Throughput: 2, Latency: time.Duration(13600000)},
			}

			Expect(report).To(HaveLen(len(expectedReport)))
			for i := range report {
				Expect(report[i]).To(Equal(expectedReport[i]))
			}
		})
	})

	Describe("GenerateCSV", func() {
		It("returns the data in a CSV format", func() {
			report := aggregator.Report{
				aggregator.Point{Throughput: 1, Latency: time.Duration(10000000)},
				aggregator.Point{Throughput: 2, Latency: time.Duration(20000000)},
				aggregator.Point{Throughput: 3, Latency: time.Duration(30000000)},
				aggregator.Point{Throughput: 4, Latency: time.Duration(40000000)},
				aggregator.Point{Throughput: 5, Latency: time.Duration(50000000)},
			}
			csv := gbytes.BufferWithBytes(report.GenerateCSV())

			Expect(csv).To(gbytes.Say(`throughput,latency\n`))
			Expect(csv).To(gbytes.Say(`(?m:^1,0\.010*$)`))
			Expect(csv).To(gbytes.Say(`(?m:^2,0\.020*$)`))
			Expect(csv).To(gbytes.Say(`(?m:^3,0\.030*$)`))
			Expect(csv).To(gbytes.Say(`(?m:^4,0\.040*$)`))
			Expect(csv).To(gbytes.Say(`(?m:^5,0\.050*$)`))
		})
	})
})