Exemplo n.º 1
0
func parseRequestForDesireDesiredLRP_r0(logger lager.Logger, req *http.Request, request *models.DesireLRPRequest) error {
	data, err := ioutil.ReadAll(req.Body)
	if err != nil {
		logger.Error("failed-to-read-body", err)
		return models.ErrUnknownError
	}

	err = request.Unmarshal(data)
	if err != nil {
		logger.Error("failed-to-parse-request-body", err)
		return models.ErrBadRequest
	}

	request.DesiredLrp.Action.SetTimeoutMsFromDeprecatedTimeoutNs()
	request.DesiredLrp.Setup.SetTimeoutMsFromDeprecatedTimeoutNs()
	request.DesiredLrp.Monitor.SetTimeoutMsFromDeprecatedTimeoutNs()
	request.DesiredLrp.StartTimeoutMs = int64(request.DesiredLrp.DeprecatedStartTimeoutS * 1000)

	if err := request.Validate(); err != nil {
		logger.Error("invalid-request", err)
		return models.NewError(models.Error_InvalidRequest, err.Error())
	}

	return nil
}
			Context("when the ProcessGuid is blank", func() {
				BeforeEach(func() {
					request.ProcessGuid = ""
				})

				It("returns a validation error", func() {
					Expect(request.Validate()).To(ConsistOf(models.ErrInvalidField{"process_guid"}))
				})
			})
		})
	})

	Describe("DesireLRPRequest", func() {
		Describe("Validate", func() {
			var request models.DesireLRPRequest

			BeforeEach(func() {
				request = models.DesireLRPRequest{
					DesiredLrp: model_helpers.NewValidDesiredLRP("some-guid"),
				}
			})

			Context("when valid", func() {
				It("returns nil", func() {
					Expect(request.Validate()).To(BeNil())
				})
			})

			Context("when the DesiredLRP is blank", func() {
				BeforeEach(func() {