Expect(ok).To(BeTrue()) Expect(user789).To(Equal(uaa.User{})) Expect(uaaClient.UsersEmailsByIDsCall.Receives.Token).To(Equal(token)) Expect(uaaClient.UsersEmailsByIDsCall.Receives.IDs).To(Equal([]string{"user-123", "user-789"})) }) }) Describe("UAA Error Responses", func() { Context("when UAA cannot be reached", func() { It("returns a UAADownError", func() { uaaClient.UsersEmailsByIDsCall.Returns.Error = uaa.NewFailure(404, []byte("Requested route ('uaa.10.244.0.34.xip.io') does not exist")) _, err := loader.Load([]string{"user-123"}, token) Expect(err).To(BeAssignableToTypeOf(postal.UAADownError(""))) }) }) Context("when UAA returns an unknown UAA 404 error", func() { It("returns a UAAGenericError", func() { uaaClient.UsersEmailsByIDsCall.Returns.Error = uaa.NewFailure(404, []byte("Weird message we haven't seen")) _, err := loader.Load([]string{"user-123"}, token) Expect(err).To(BeAssignableToTypeOf(postal.UAAGenericError(""))) }) }) Context("when UAA returns an failure code that is not 404", func() { It("returns a UAADownError", func() {
It("returns a 502 when CloudController fails to respond", func() { writer.Write(recorder, services.CCDownError("Bad things happened!")) Expect(recorder.Code).To(Equal(http.StatusBadGateway)) body := make(map[string]interface{}) err := json.Unmarshal(recorder.Body.Bytes(), &body) if err != nil { panic(err) } Expect(body["errors"]).To(ContainElement("Bad things happened!")) }) It("returns a 502 when UAA fails to respond", func() { writer.Write(recorder, postal.UAADownError("Whoops!")) Expect(recorder.Code).To(Equal(http.StatusBadGateway)) body := make(map[string]interface{}) err := json.Unmarshal(recorder.Body.Bytes(), &body) if err != nil { panic(err) } Expect(body["errors"]).To(ContainElement("Whoops!")) }) It("returns a 502 when UAA fails for unknown reasons", func() { writer.Write(recorder, postal.UAAGenericError("UAA Unknown Error: BOOM!"))