コード例 #1
0
ファイル: light_test.go プロジェクト: robdimsdale/garagepi
			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))
			})
		})

		Context("When reading light state contains leading/trailing whitespace", func() {
			BeforeEach(func() {
				fakeGpio.ReadReturns("\t0\n", nil)
				expectedLightState.StateKnown = true
				expectedLightState.LightOn = false
コード例 #2
0
ファイル: homepage_test.go プロジェクト: robdimsdale/garagepi
	BeforeEach(func() {
		fakeLogger = lagertest.NewTestLogger("homepage handle test")
		fakeLightHandler = new(light_fakes.FakeHandler)
		fakeLoginHandler = new(login_fakes.FakeHandler)
		fakeResponseWriter = new(test_helpers_fakes.FakeResponseWriter)

		var err error

		templates, err = template.New("head").Parse(headTemplate)
		Expect(err).NotTo(HaveOccurred())
		templates, err = templates.New("homepage").Parse(homepageTemplate)
		Expect(err).NotTo(HaveOccurred())

		hh = homepage.NewHandler(
			fakeLogger,
			templates,
			fakeLightHandler,
			fakeLoginHandler,
		)

		dummyRequest = new(http.Request)
	})

	Describe("Homepage Handling", func() {
		It("Should write the contents of the homepage template to the response writer", func() {
			hh.Handle(fakeResponseWriter, dummyRequest)
			Expect(fakeResponseWriter.WriteCallCount()).To(BeNumerically(">=", 1))
		})
	})
})