Exemple #1
0
		fakeGpio = new(gpio_fakes.FakeGpio)
		fakeResponseWriter = new(test_helpers_fakes.FakeResponseWriter)

		lh = light.NewHandler(
			fakeLogger,
			fakeGpio,
			gpioLightPin,
		)

		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))