spec garden.ContainerSpec ) BeforeEach(func() { spec = garden.ContainerSpec{} }) JustBeforeEach(func() { var err error createdContainer, err = gdnr.Create(spec) Expect(err).NotTo(HaveOccurred()) }) It("passes the rootfs provided by the volumizer to the containerizer", func() { Expect(containerizer.CreateArgsForCall(0).RootFSPath).To(Equal("the-volumized-rootfs-path")) }) PIt("destroys volumes when creating fails", func() {}) Context("when a handle is specified", func() { BeforeEach(func() { spec.Handle = "the-handle" }) It("passes the handle to the containerizer", func() { Expect(containerizer.CreateArgsForCall(0).Handle).To(Equal("the-handle")) }) It("remembers the handle", func() { Expect(createdContainer.Handle()).To(Equal("the-handle"))
Describe("creating a container", func() { Context("when a handle is specified", func() { It("passes the created network to the containerizer", func() { networker.NetworkStub = func(_ lager.Logger, handle, spec string) (string, error) { return "/path/to/netns/" + handle, nil } _, err := gdnr.Create(garden.ContainerSpec{ Handle: "bob", Network: "10.0.0.2/30", }) Expect(err).NotTo(HaveOccurred()) Expect(containerizer.CreateCallCount()).To(Equal(1)) _, spec := containerizer.CreateArgsForCall(0) Expect(spec.NetworkPath).To(Equal("/path/to/netns/bob")) }) Context("when networker fails", func() { BeforeEach(func() { networker.NetworkReturns("", errors.New("booom!")) }) It("returns an error", func() { _, err := gdnr.Create(garden.ContainerSpec{Handle: "bob"}) Expect(err).To(MatchError("booom!")) }) It("should not create the volume", func() { gdnr.Create(garden.ContainerSpec{Handle: "bob"})
networker = new(fakes.FakeNetworker) gdnr = &gardener.Gardener{ Containerizer: containerizer, UidGenerator: uidGenerator, Networker: networker, } }) Describe("creating a container", func() { Context("when a handle is specified", func() { It("asks the containerizer to create a container", func() { _, err := gdnr.Create(garden.ContainerSpec{Handle: "bob"}) Expect(err).NotTo(HaveOccurred()) Expect(containerizer.CreateCallCount()).To(Equal(1)) Expect(containerizer.CreateArgsForCall(0).Handle).To(Equal("bob")) }) It("passes the created network to the containerizer", func() { networker.NetworkStub = func(spec string) (string, error) { return "/path/to/netns/" + spec, nil } _, err := gdnr.Create(garden.ContainerSpec{ Handle: "bob", Network: "10.0.0.2/30", }) Expect(err).NotTo(HaveOccurred()) Expect(containerizer.CreateCallCount()).To(Equal(1)) Expect(containerizer.CreateArgsForCall(0).NetworkPath).To(Equal("/path/to/netns/10.0.0.2/30"))