Esempio n. 1
0
			Expect(space).To(Equal(cf.CloudControllerSpace{
				GUID:             "space-001",
				Name:             "space-name",
				OrganizationGUID: "org-001",
			}))

			Expect(cc.LoadSpaceCall.Receives.SpaceGUID).To(Equal("space-001"))
			Expect(cc.LoadSpaceCall.Receives.Token).To(Equal("some-token"))
		})

		Context("when the space cannot be found", func() {
			It("returns an error object", func() {
				cc.LoadSpaceCall.Returns.Error = cf.NewFailure(404, "not found")

				_, err := loader.Load("missing-space", "some-token")
				Expect(err).To(Equal(services.CCNotFoundError("CloudController Failure (404): not found")))
			})
		})

		Context("when Load returns any other type of error", func() {
			It("returns a CCDownError when the error is cf.Failure", func() {
				cc.LoadSpaceCall.Returns.Error = cf.NewFailure(401, "BOOM!")

				_, err := loader.Load("space-001", "some-token")
				Expect(err).To(Equal(services.CCDownError("CloudController Failure (401): BOOM!")))
			})

			It("returns the same error for all other cases", func() {
				cc.LoadSpaceCall.Returns.Error = errors.New("BOOM!")

				_, err := loader.Load("space-001", "some-token")
Esempio n. 2
0
	It("returns a 500 when there is a template update error", func() {
		writer.Write(recorder, models.TemplateUpdateError{Message: "Failed to update Template in the database"})

		Expect(recorder.Code).To(Equal(http.StatusInternalServerError))

		body := make(map[string]interface{})
		err := json.Unmarshal(recorder.Body.Bytes(), &body)
		if err != nil {
			panic(err)
		}

		Expect(body["errors"]).To(ContainElement("Failed to update Template in the database"))
	})

	It("returns a 404 when the space cannot be found", func() {
		writer.Write(recorder, services.CCNotFoundError("Space could not be found"))

		Expect(recorder.Code).To(Equal(http.StatusNotFound))

		body := make(map[string]interface{})
		err := json.Unmarshal(recorder.Body.Bytes(), &body)
		if err != nil {
			panic(err)
		}

		Expect(body["errors"]).To(ContainElement("CloudController Error: Space could not be found"))
	})

	It("returns a 400 when the request cannot be parsed due to syntatically invalid JSON", func() {
		writer.Write(recorder, webutil.ParseError{})