ns.NameReturns("target-namespace") sbox.NamespaceReturns(ns) moveLink = commands.MoveLink{ Name: "link-name", SandboxName: "sandbox-name", } }) It("gets the sandbox from the repository", func() { err := moveLink.Execute(context) Expect(err).NotTo(HaveOccurred()) Expect(sandboxRepository.GetCallCount()).To(Equal(1)) Expect(sandboxRepository.GetArgsForCall(0)).To(Equal("sandbox-name")) }) It("moves the link to the target namespace", func() { err := moveLink.Execute(context) Expect(err).NotTo(HaveOccurred()) Expect(linkFactory.SetNamespaceCallCount()).To(Equal(1)) name, fd := linkFactory.SetNamespaceArgsForCall(0) Expect(name).To(Equal("link-name")) Expect(fd).To(BeEquivalentTo(999)) }) Context("when getting the sandbox fails", func() { BeforeEach(func() { sandboxRepository.GetReturns(nil, errors.New("welp"))
Name: "some-sandbox", } }) Context("when the namespace exists", func() { BeforeEach(func() { repo.GetReturns(&fakes.Sandbox{}, nil) }) It("returns true", func() { satisfied, err := sandboxExists.Satisfied(context) Expect(err).NotTo(HaveOccurred()) Expect(satisfied).To(BeTrue()) Expect(repo.GetCallCount()).To(Equal(1)) Expect(repo.GetArgsForCall(0)).To(Equal("some-sandbox")) }) }) Context("when the namespace does not exist", func() { BeforeEach(func() { repo.GetReturns(nil, sandbox.NotFoundError) }) It("returns false", func() { satisfied, err := sandboxExists.Satisfied(context) Expect(err).NotTo(HaveOccurred()) Expect(satisfied).To(BeFalse()) Expect(repo.GetCallCount()).To(Equal(1)) Expect(repo.GetArgsForCall(0)).To(Equal("some-sandbox"))
ns.ExecuteStub = func(callback func(*os.File) error) error { return callback(nil) } startDNS = commands.StartDNSServer{ ListenAddress: "10.10.10.10:53", SandboxName: "some-sandbox-name", } }) It("gets the namespace from the sandbox", func() { err := startDNS.Execute(context) Expect(err).NotTo(HaveOccurred()) Expect(sandboxRepo.GetCallCount()).To(Equal(1)) Expect(sandboxRepo.GetArgsForCall(0)).To(Equal("some-sandbox-name")) Expect(sbox.NamespaceCallCount()).To(Equal(1)) }) It("locks and unlocks the sandbox", func() { err := startDNS.Execute(context) Expect(err).NotTo(HaveOccurred()) Expect(sbox.LockCallCount()).To(Equal(1)) Expect(sbox.UnlockCallCount()).To(Equal(1)) }) It("adds a dummy link to the sandbox namespace", func() { ns.ExecuteStub = func(callback func(*os.File) error) error { Expect(linkFactory.CreateDummyCallCount()).To(Equal(0))
Context("when creating the sandbox errors", func() { It("should return a meaningful error", func() { ex.ExecuteReturns(errors.New("potato")) _, err := creator.Setup(config) Expect(err).To(MatchError("executing command: create sandbox: potato")) }) }) It("should get the sandbox ns from the sandbox repo", func() { _, err := creator.Setup(config) Expect(err).NotTo(HaveOccurred()) Expect(sandboxRepo.GetCallCount()).To(Equal(1)) Expect(sandboxRepo.GetArgsForCall(0)).To(Equal("vni-99")) }) Context("when getting the sandbox ns from the sandbox repo fails", func() { It("should return a meaningful error", func() { sandboxRepo.GetReturns(nil, errors.New("daikon")) _, err := creator.Setup(config) Expect(err).To(MatchError("get sandbox: daikon")) }) }) It("should execute the IdempotentlyCreateVxlan command group", func() { createVxlanResult := &fakes.Command{} commandBuilder.IdempotentlyCreateVxlanReturns(createVxlanResult)