func (h *CellHandler) GetAll(w http.ResponseWriter, req *http.Request) {
	logger := h.logger.Session("get-all")

	cellPresences, err := h.bbs.Cells()
	if err != nil {
		logger.Error("failed-to-fetch-cells", err)
		writeUnknownErrorResponse(w, err)
		return
	}

	responses := make([]receptor.CellResponse, 0, len(cellPresences))
	for _, cellPresence := range cellPresences {
		responses = append(responses, serialization.CellPresenceToCellResponse(cellPresence))
	}

	writeJSONResponse(w, http.StatusOK, responses)
}
示例#2
0
		var cellResponses []receptor.CellResponse
		var getErr error

		BeforeEach(func() {
			Eventually(func() []models.CellPresence {
				cellPresences, err := legacyBBS.Cells()
				Expect(err).NotTo(HaveOccurred())
				return cellPresences
			}).Should(HaveLen(1))

			cellResponses, getErr = client.Cells()
		})

		It("responds without error", func() {
			Expect(getErr).NotTo(HaveOccurred())
		})

		It("has the correct data from the bbs", func() {
			cellPresences, err := legacyBBS.Cells()
			Expect(err).NotTo(HaveOccurred())

			expectedResponses := make([]receptor.CellResponse, 0, 1)
			for _, cellPresence := range cellPresences {
				expectedResponses = append(expectedResponses, serialization.CellPresenceToCellResponse(cellPresence))
			}

			Expect(cellResponses).To(ConsistOf(expectedResponses))
		})
	})
})
			It("call the BBS to retrieve the actual LRPs", func() {
				Expect(fakeBBS.CellsCallCount()).To(Equal(1))
			})

			It("responds with 200 Status OK", func() {
				Expect(responseRecorder.Code).To(Equal(http.StatusOK))
			})

			It("returns a list of cell presence responses", func() {
				response := []receptor.CellResponse{}
				err := json.Unmarshal(responseRecorder.Body.Bytes(), &response)
				Expect(err).NotTo(HaveOccurred())

				Expect(response).To(HaveLen(2))
				for _, cellPresence := range cellPresences {
					Expect(response).To(ContainElement(serialization.CellPresenceToCellResponse(cellPresence)))
				}
			})
		})

		Context("when the BBS returns no cells", func() {
			BeforeEach(func() {
				fakeBBS.CellsReturns([]models.CellPresence{}, nil)
			})

			It("responds with 200 Status OK", func() {
				Expect(responseRecorder.Code).To(Equal(http.StatusOK))
			})

			It("returns an empty list", func() {
				Expect(responseRecorder.Body.String()).To(Equal("[]"))
示例#4
0
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("CellPresence Serialization", func() {
	Describe("CellPresenceToCellResponse", func() {
		var cellPresence models.CellPresence

		BeforeEach(func() {
			capacity := models.NewCellCapacity(128, 1024, 6)
			cellPresence = models.NewCellPresence("cell-id-0", "1.2.3.4", "the-zone", capacity)
		})

		It("serializes all the fields", func() {
			expectedResponse := receptor.CellResponse{
				CellID: "cell-id-0",
				Zone:   "the-zone",
				Capacity: receptor.CellCapacity{
					MemoryMB:   128,
					DiskMB:     1024,
					Containers: 6,
				},
			}

			actualResponse := serialization.CellPresenceToCellResponse(cellPresence)
			Expect(actualResponse).To(Equal(expectedResponse))
		})
	})
})