Esempio n. 1
0
		Context("once the state has been synced with CC", func() {
			Context("lrps", func() {
				BeforeEach(func() {
					schedulingInfoResponse := models.DesiredLRPSchedulingInfosResponse{
						Error: nil,
						DesiredLrpSchedulingInfos: []*models.DesiredLRPSchedulingInfo{
							{
								DesiredLRPKey: models.DesiredLRPKey{ // perfect. love it. keep it.
									ProcessGuid: "process-guid-1",
									Domain:      cc_messages.AppLRPDomain,
								},
								Annotation: "1.1",
							},
							{
								DesiredLRPKey: models.DesiredLRPKey{ // annotation mismatch so update
									ProcessGuid: "process-guid-2",
									Domain:      cc_messages.AppLRPDomain,
								},
							}, // missing 3 so create it
							{
								DesiredLRPKey: models.DesiredLRPKey{ // extra to be removed
									ProcessGuid: "process-guid-4",
									Domain:      cc_messages.AppLRPDomain,
								},
								Annotation: "4.1",
							},
						},
					}
					data, err := schedulingInfoResponse.Marshal()
					Expect(err).ToNot(HaveOccurred())
		JustBeforeEach(func() {
			request := newTestRequest(requestBody)
			handler.DesiredLRPSchedulingInfos(responseRecorder, request)
		})

		Context("when reading scheduling infos from DB succeeds", func() {
			var schedulingInfos []*models.DesiredLRPSchedulingInfo

			BeforeEach(func() {
				schedulingInfos = []*models.DesiredLRPSchedulingInfo{&schedulingInfo1, &schedulingInfo2}
				fakeDesiredLRPDB.DesiredLRPSchedulingInfosReturns(schedulingInfos, nil)
			})

			It("returns a list of desired lrp groups", func() {
				Expect(responseRecorder.Code).To(Equal(http.StatusOK))
				response := models.DesiredLRPSchedulingInfosResponse{}
				err := response.Unmarshal(responseRecorder.Body.Bytes())
				Expect(err).NotTo(HaveOccurred())

				Expect(response.Error).To(BeNil())
				Expect(response.DesiredLrpSchedulingInfos).To(Equal(schedulingInfos))
			})

			Context("and no filter is provided", func() {
				It("call the DB with no filters to retrieve the desired lrps", func() {
					Expect(fakeDesiredLRPDB.DesiredLRPSchedulingInfosCallCount()).To(Equal(1))
					_, filter := fakeDesiredLRPDB.DesiredLRPSchedulingInfosArgsForCall(0)
					Expect(filter).To(Equal(models.DesiredLRPFilter{}))
				})
			})