func printConditions(w *wunderground.Wunderground) { conditions, err := w.Conditions(zip) if err != nil { panic(err) } fmt.Printf("\nResponse:\n %+v\n", conditions.Response) fmt.Printf("\nConditions:\n %+v\n", conditions.Condition) }
BeforeEach(func() { fakeServer = NewMockWunderground() conf.ApiHost = fakeServer.Server.URL w = wunderground.New(conf) }) AfterEach(func() { fakeServer.Close() }) It("builds the correct url for the wunderground api", func() { zipCode := "80516" fakeServer.FakeResponseBody = `{"response":{}}` _, err := w.Conditions("80516") Expect(err).ToNot(HaveOccurred()) Expect(fakeServer.ReceivedReq.Method).To(Equal("GET")) path := fmt.Sprintf("/api/%s/conditions/q/%s.json", apiKey, zipCode) Expect(fakeServer.ReceivedReq.URL.Path).To(Equal(path)) }) It("returns an error for invalid api key", func() { fakeServer.FakeResponseBody = InvalidApiKeyResponse _, err := w.Conditions("80303") Expect(err).To(HaveOccurred()) Expect(err.Error()).To(Equal("keynotfound: this key does not exist")) })