import ( "net/http" "time" "github.com/cloudfoundry-incubator/bbs/models" "github.com/cloudfoundry-incubator/cf_http" "github.com/cloudfoundry-incubator/rep" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/onsi/gomega/ghttp" ) var _ = Describe("Client", func() { var fakeServer *ghttp.Server var client rep.Client BeforeEach(func() { fakeServer = ghttp.NewServer() client = rep.NewClient(cf_http.NewClient(), fakeServer.URL()) }) AfterEach(func() { fakeServer.Close() }) Describe("StopLRPInstance", func() { const cellAddr = "cell.example.com" var stopErr error var actualLRP = models.ActualLRP{ ActualLRPKey: models.NewActualLRPKey("some-process-guid", 2, "test-domain"),
Context("when the presence fails to be maintained", func() { It("should not exit, but keep trying to maintain presence at the same ID", func() { consulRunner.Reset() Eventually(fetchCells(logger, serviceClient), 5).Should(HaveLen(1)) cells, err := serviceClient.Cells(logger) Expect(err).NotTo(HaveOccurred()) Expect(cells[cellID]).To(Equal(cellPresence)) Expect(runner.Session).NotTo(Exit()) }) }) }) Context("acting as an auction representative", func() { var client rep.Client JustBeforeEach(func() { Eventually(fetchCells(logger, serviceClient)).Should(HaveLen(1)) cells, err := serviceClient.Cells(logger) Expect(err).NotTo(HaveOccurred()) client = rep.NewClient(http.DefaultClient, cf_http.NewCustomTimeoutClient(100*time.Millisecond), cells[cellID].RepAddress) }) Context("Capacity with a container", func() { BeforeEach(func() { fakeGarden.RouteToHandler("GET", "/containers", ghttp.RespondWithJSONEncoded(http.StatusOK, map[string][]string{"handles": []string{"handle-guid"}}), ) fakeGarden.RouteToHandler("GET", "/containers/bulk_info",
bbsRunner = bbstestrunner.New(bbsBinPath, bbsArgs) bbsProcess = ginkgomon.Invoke(bbsRunner) Eventually(fetchCells(logger), 5).Should(HaveLen(1)) cells, err := bbsClient.Cells() cellSet := models.NewCellSetFromList(cells) Expect(err).NotTo(HaveOccurred()) Expect(cellSet[cellID]).To(Equal(cellPresence)) Expect(runner.Session).NotTo(Exit()) }) }) }) Context("acting as an auction representative", func() { var client rep.Client JustBeforeEach(func() { Eventually(fetchCells(logger)).Should(HaveLen(1)) cells, err := bbsClient.Cells() cellSet := models.NewCellSetFromList(cells) Expect(err).NotTo(HaveOccurred()) client = rep.NewClient(http.DefaultClient, cf_http.NewCustomTimeoutClient(100*time.Millisecond), cellSet[cellID].RepAddress) }) Context("Capacity with a container", func() { It("returns total capacity", func() { state, err := client.State() Expect(err).NotTo(HaveOccurred()) Expect(state.TotalResources).To(Equal(rep.Resources{