BeforeEach(func() { msg = watcher.Neighbor{ SandboxName: "/path/to/some-sandbox-name", Neigh: watcher.Neigh{ IP: net.ParseIP("192.168.1.2"), }, } fakeStore.AllReturns([]models.Container{ models.Container{ IP: "1.2.3.4", HostIP: "10.10.10.10", SandboxName: "some-sandbox-name", }, models.Container{ IP: "192.168.1.2", MAC: "ff:ff:ff:ff:ff:ff", HostIP: "10.11.12.13", SandboxName: "some-sandbox-name", }, }, nil) }) It("retrieves the addresses associated with each incoming IP", func() { missesChannel <- msg Eventually(fakeStore.AllCallCount).Should(Equal(1)) }) Context("when the IP and sandbox match", func() {
marshaler = &lfakes.Marshaler{} marshaler.MarshalStub = json.Marshal logger = lagertest.NewTestLogger("test") handler = &handlers.ListContainers{ Marshaler: marshaler, Logger: logger, Datastore: dataStore, } containers = []models.Container{ {ID: "container-id-1", IP: "192.168.0.1", NetworkID: "network-id-1"}, {ID: "container-id-2", IP: "192.168.0.2", NetworkID: "network-id-1"}, {ID: "container-id-199", IP: "192.168.0.3", NetworkID: "network-id-2"}, {ID: "container-id-200", IP: "192.168.0.4", NetworkID: "network-id-2"}, } dataStore.AllReturns(containers, nil) }) It("should return the containers as a JSON list", func() { req, err := http.NewRequest("GET", "/containers", nil) Expect(err).NotTo(HaveOccurred()) resp := httptest.NewRecorder() handler.ServeHTTP(resp, req) var receivedContainers []models.Container err = json.Unmarshal(resp.Body.Bytes(), &receivedContainers) Expect(err).NotTo(HaveOccurred()) Expect(resp.Code).To(Equal(http.StatusOK)) Expect(receivedContainers).To(ConsistOf(containers)) })
) BeforeEach(func() { marshaler = &lfakes.Marshaler{} marshaler.MarshalStub = json.Marshal datastore = &fakes.Store{} logger = lagertest.NewTestLogger("test") getHandler = &handlers.NetworksListContainers{ Marshaler: marshaler, Logger: logger, Datastore: datastore, } datastore.AllReturns([]models.Container{ {ID: "container-id-1", IP: "192.168.0.1", NetworkID: "network-id-1"}, {ID: "container-id-2", IP: "192.168.0.2", NetworkID: "network-id-1"}, {ID: "container-id-199", IP: "192.168.0.3", NetworkID: "network-id-2"}, {ID: "container-id-200", IP: "192.168.0.4", NetworkID: "network-id-2"}, }, nil) }) It("should return a matching set of containers as json", func() { handler, request := rataWrap(getHandler, "GET", "/networks/:network_id", rata.Params{"network_id": "network-id-1"}) resp := httptest.NewRecorder() handler.ServeHTTP(resp, request) var receivedContainers []models.Container err := json.Unmarshal(resp.Body.Bytes(), &receivedContainers) Expect(err).NotTo(HaveOccurred()) Expect(resp.Code).To(Equal(http.StatusOK)) Expect(receivedContainers).To(Equal([]models.Container{