var receivedContainer models.Container err := json.Unmarshal(resp.Body.Bytes(), &receivedContainer) Expect(err).NotTo(HaveOccurred()) Expect(resp.Code).To(Equal(http.StatusOK)) Expect(receivedContainer).To(Equal(models.Container{ ID: "container-id-1", IP: "192.168.0.1", NetworkID: "network-id-1", })) }) Context("when the record does not exist in the database", func() { BeforeEach(func() { datastore.GetReturns(models.Container{}, store.RecordNotFoundError) }) It("logs the error and returns with a 404", func() { handler, request := rataWrap(getHandler, "GET", "/containers/:container_id", rata.Params{"container_id": "some-nonexistent-container-id"}) resp := httptest.NewRecorder() handler.ServeHTTP(resp, request) Expect(logger).To(gbytes.Say("get-container.*record-not-found")) Expect(resp.Code).To(Equal(http.StatusNotFound)) Expect(resp.Body.String()).To(BeEmpty()) }) }) Context("when the database in an unknown way", func() { BeforeEach(func() { datastore.GetReturns(models.Container{}, errors.New("some-database-error"))
deletor *fakes.Deletor controller *cni.DelController ipAllocator *fakes.IPAllocator networkMapper *fakes.NetworkMapper payload models.CNIDelPayload ) BeforeEach(func() { datastore = &fakes.Store{} deletor = &fakes.Deletor{} ipAllocator = &fakes.IPAllocator{} networkMapper = &fakes.NetworkMapper{} networkMapper.GetVNIReturns(42, nil) datastore.GetReturns(models.Container{ NetworkID: "some-network-id", }, nil) controller = &cni.DelController{ Datastore: datastore, Deletor: deletor, IPAllocator: ipAllocator, NetworkMapper: networkMapper, } payload = models.CNIDelPayload{ InterfaceName: "some-interface-name", ContainerNamespace: "/some/container/namespace/path", ContainerID: "some-container-id", } })