Esempio n. 1
0
					Expect(c.ApiKey).To(Equal("api_key"))
					Expect(c.BotId).To(Equal("bot_id"))
					Expect(err).To(BeNil())
				})
			})
		})
	})

	Describe("RegisterBot", func() {
		var server *ghttp.Server
		var bc *BotmetricsClient
		var err error

		BeforeEach(func() {
			server = ghttp.NewServer()
			os.Setenv("BOTMETRICS_API_HOST", server.URL())
			bc, err = NewBotmetricsClient("api-key", "bot-id")
			Expect(err).To(BeNil())
		})

		AfterEach(func() {
			server.Close()
			os.Unsetenv("BOTMETRICS_API_HOST")
		})

		verifyRequestResponse := func(server *ghttp.Server, method, uri, token, createdAt string, responseCode int64) {
			var verifier http.HandlerFunc = func(w http.ResponseWriter, r *http.Request) {
				Expect(r.Method).To(Equal(method))
				Expect(r.RequestURI).To(Equal(uri))
				err := r.ParseForm()
				Expect(err).To(BeNil())
	thingsThatRan := func() []string {
		lock.Lock()
		defer lock.Unlock()
		return things
	}

	Context("when not running in parallel", func() {
		Context("when all is well", func() {
			BeforeEach(func() {
				node = newNode(func() {
					ranThing("A")
				}, func() {
					ranThing("B")
				})

				outcome = node.Run(1, 1, server.URL())
			})

			It("should run A, then B", func() {
				Ω(thingsThatRan()).Should(Equal([]string{"A", "B"}))
			})

			It("should report success", func() {
				Ω(outcome).Should(BeTrue())
				Ω(node.Passed()).Should(BeTrue())
				Ω(node.Summary().State).Should(Equal(types.SpecStatePassed))
			})
		})

		Context("when A fails", func() {
			BeforeEach(func() {
		return NewSynchronizedBeforeSuiteNode(bodyA, bodyB, codeLocation, time.Millisecond, failer)
	}

	Describe("when not running in parallel", func() {
		Context("when all is well", func() {
			var data []byte
			BeforeEach(func() {
				data = nil

				node = newNode(func() []byte {
					return []byte("my data")
				}, func(d []byte) {
					data = d
				})

				outcome = node.Run(1, 1, server.URL())
			})

			It("should run A, then B passing the output from A to B", func() {
				Ω(data).Should(Equal([]byte("my data")))
			})

			It("should report success", func() {
				Ω(outcome).Should(BeTrue())
				Ω(node.Passed()).Should(BeTrue())
				Ω(node.Summary().State).Should(Equal(types.SpecStatePassed))
			})
		})

		Context("when A fails", func() {
			var ranB bool