Exemplo n.º 1
0
		dummyRequest = new(http.Request)
	})

	Describe("Reading state", func() {
		Context("When reading light state returns with error", func() {
			BeforeEach(func() {
				fakeGpio.ReadReturns("", errors.New("gpio read error"))
				expectedLightState.StateKnown = false
				expectedReturn, err = json.Marshal(expectedLightState)
				Expect(err).NotTo(HaveOccurred())
			})

			It("Should read from light pin", func() {
				lh.HandleGet(fakeResponseWriter, dummyRequest)
				Expect(fakeGpio.ReadCallCount()).To(Equal(1))
				Expect(fakeGpio.ReadArgsForCall(0)).To(Equal(gpioLightPin))
			})

			It("Should return unknown light state", func() {
				lh.HandleGet(fakeResponseWriter, dummyRequest)
				Expect(fakeResponseWriter.WriteCallCount()).To(Equal(1))
				Expect(fakeResponseWriter.WriteArgsForCall(0)).To(Equal(expectedReturn))
			})

			It("Should respond with HTTP status code 503", func() {
				lh.HandleGet(fakeResponseWriter, dummyRequest)
				Expect(fakeResponseWriter.WriteHeaderCallCount()).To(Equal(1))
				Expect(fakeResponseWriter.WriteHeaderArgsForCall(0)).To(Equal(http.StatusServiceUnavailable))
			})
		})