Example #1
0
func (handler *stagingHandler) doErrorResponse(resp http.ResponseWriter, message string) {
	response := cc_messages.StagingResponseForCC{
		Error: backend.SanitizeErrorMessage(message),
	}
	responseJson, _ := json.Marshal(response)

	resp.WriteHeader(http.StatusInternalServerError)
	resp.Write(responseJson)
}
					})

					It("returns an internal service error status code", func() {
						Expect(responseRecorder.Code).To(Equal(http.StatusInternalServerError))
					})

					It("should not call staging complete", func() {
						Expect(fakeCcClient.StagingCompleteCallCount()).To(Equal(0))
					})

					Context("when the response builder succeeds", func() {
						var responseForCC cc_messages.StagingResponseForCC

						BeforeEach(func() {
							responseForCC = cc_messages.StagingResponseForCC{
								Error: backend.SanitizeErrorMessage(desireError.Error()),
							}
						})

						It("returns the cloud controller error response", func() {
							var response cc_messages.StagingResponseForCC
							decoder := json.NewDecoder(responseRecorder.Body)
							err := decoder.Decode(&response)
							Expect(err).NotTo(HaveOccurred())

							Expect(response).To(Equal(responseForCC))
						})
					})
				})
			})
				})

				It("populates a staging response correctly", func() {
					Expect(buildError).NotTo(HaveOccurred())
					Expect(response).To(Equal(cc_messages.StagingResponseForCC{
						Error: &cc_messages.StagingError{Message: "some-failure-reason was totally sanitized"},
					}))
				})
			})
		})
	})

	Describe("SanitizeErrorMessage", func() {
		Context("when the message is InsufficientResources", func() {
			It("returns a InsufficientResources", func() {
				stagingErr := backend.SanitizeErrorMessage(diego_errors.INSUFFICIENT_RESOURCES_MESSAGE)
				Expect(stagingErr.Id).To(Equal(cc_messages.INSUFFICIENT_RESOURCES))
				Expect(stagingErr.Message).To(Equal(diego_errors.INSUFFICIENT_RESOURCES_MESSAGE))
			})
		})

		Context("when the message is NoCompatibleCell", func() {
			It("returns a NoCompatibleCell", func() {
				stagingErr := backend.SanitizeErrorMessage(diego_errors.CELL_MISMATCH_MESSAGE)
				Expect(stagingErr.Id).To(Equal(cc_messages.NO_COMPATIBLE_CELL))
				Expect(stagingErr.Message).To(Equal(diego_errors.CELL_MISMATCH_MESSAGE))
			})
		})

		Context("when the message is missing docker image URL", func() {
			It("returns a StagingError", func() {