Expect(response.Error).To(Equal(models.ErrUnknownError)) }) }) }) Describe("DesireDesiredLRP", func() { var ( desiredLRP *models.DesiredLRP requestBody interface{} ) BeforeEach(func() { desiredLRP = model_helpers.NewValidDesiredLRP("some-guid") desiredLRP.Instances = 5 requestBody = &models.DesireLRPRequest{ DesiredLrp: desiredLRP, } }) JustBeforeEach(func() { request := newTestRequest(requestBody) handler.DesireDesiredLRP(logger, responseRecorder, request) }) Context("when creating desired lrp in DB succeeds", func() { var createdActualLRPGroups []*models.ActualLRPGroup BeforeEach(func() { createdActualLRPGroups = []*models.ActualLRPGroup{}
etcdRunner.Start() }) It("errors", func() { _, err := etcdDB.DesiredLRPSchedulingInfos(logger, filter) Expect(err).To(HaveOccurred()) }) }) }) Describe("DesireLRP", func() { var lrp *models.DesiredLRP BeforeEach(func() { lrp = model_helpers.NewValidDesiredLRP("some-process-guid") lrp.Instances = 5 }) Context("when the desired LRP does not yet exist", func() { It("persists the scheduling info and run info", func() { err := etcdDB.DesireLRP(logger, lrp) Expect(err).NotTo(HaveOccurred()) persisted, err := etcdDB.DesiredLRPByProcessGuid(logger, "some-process-guid") Expect(err).NotTo(HaveOccurred()) Expect(persisted.DesiredLRPKey()).To(Equal(lrp.DesiredLRPKey())) Expect(persisted.DesiredLRPResource()).To(Equal(lrp.DesiredLRPResource())) Expect(persisted.Annotation).To(Equal(lrp.Annotation)) Expect(persisted.Instances).To(Equal(lrp.Instances)) Expect(persisted.DesiredLRPRunInfo(clock.Now())).To(Equal(lrp.DesiredLRPRunInfo(clock.Now())))
routes := models.Routes{ "blah": (*json.RawMessage)(&routeContent), } annotation := "annotated" update = &models.DesiredLRPUpdate{ Instances: &instances, Routes: &routes, Annotation: &annotation, } _, err := sqlDB.UpdateDesiredLRP(logger, expectedDesiredLRP.ProcessGuid, update) Expect(err).NotTo(HaveOccurred()) desiredLRP, err := sqlDB.DesiredLRPByProcessGuid(logger, expectedDesiredLRP.ProcessGuid) Expect(err).NotTo(HaveOccurred()) expectedDesiredLRP.Instances = instances expectedDesiredLRP.Annotation = annotation expectedDesiredLRP.Routes = &routes expectedDesiredLRP.ModificationTag.Increment() Expect(desiredLRP).To(BeEquivalentTo(expectedDesiredLRP)) }) It("returns the desired lrp from before the update", func() { instances := int32(20) update = &models.DesiredLRPUpdate{ Instances: &instances, } beforeDesiredLRP, err := sqlDB.UpdateDesiredLRP(logger, expectedDesiredLRP.ProcessGuid, update) Expect(err).NotTo(HaveOccurred())
Expect(response.Error).To(Equal(models.ErrUnknownError)) }) }) }) Describe("DesireDesiredLRP_r0", func() { var ( desiredLRP *models.DesiredLRP expectedDesiredLRP *models.DesiredLRP requestBody interface{} ) BeforeEach(func() { desiredLRP = model_helpers.NewValidDesiredLRP("some-guid") desiredLRP.Instances = 5 desiredLRP.StartTimeoutMs = 0 desiredLRP.DeprecatedStartTimeoutS = 15 desiredLRP.Setup = &models.Action{ TimeoutAction: &models.TimeoutAction{ Action: models.WrapAction(&models.UploadAction{ From: "web_location", To: "potato", User: "******", }), DeprecatedTimeoutNs: int64(time.Second), }, } desiredLRP.Action = &models.Action{ TimeoutAction: &models.TimeoutAction{ Action: models.WrapAction(&models.UploadAction{
}(validGuid) } invalidGuids := []string{"", "bang!", "!!!", "\\slash", "star*", "params()", "invalid/key", "with.dots"} for _, invalidGuid := range invalidGuids { func(invalidGuid string) { It(fmt.Sprintf("'%s' is an invalid process_guid", invalidGuid), func() { desiredLRP.ProcessGuid = invalidGuid assertDesiredLRPValidationFailsWithMessage(desiredLRP, "process_guid") }) }(invalidGuid) } }) It("requires a positive nonzero number of instances", func() { desiredLRP.Instances = -1 assertDesiredLRPValidationFailsWithMessage(desiredLRP, "instances") desiredLRP.Instances = 0 validationErr := desiredLRP.Validate() Expect(validationErr).NotTo(HaveOccurred()) desiredLRP.Instances = 1 validationErr = desiredLRP.Validate() Expect(validationErr).NotTo(HaveOccurred()) }) It("requires a domain", func() { desiredLRP.Domain = "" assertDesiredLRPValidationFailsWithMessage(desiredLRP, "domain") })