Exemplo n.º 1
0
func parseRequestForDesireTask_r0(logger lager.Logger, req *http.Request, request *models.DesireTaskRequest) 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.TaskDefinition.Action.SetTimeoutMsFromDeprecatedTimeoutNs()

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

	return nil
}
Exemplo n.º 2
0
			Context("when the TaskGuid is blank", func() {
				BeforeEach(func() {
					request.TaskGuid = ""
				})

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

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

			BeforeEach(func() {
				request = models.DesireTaskRequest{
					TaskGuid:       "t-guid",
					Domain:         "domain",
					TaskDefinition: model_helpers.NewValidTaskDefinition(),
				}
			})

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