BeforeEach(func() { namespaceOpener.OpenPathReturns(nil, errors.New("POTATO")) }) It("should return a meaningful error", func() { err := deletor.Delete("some-interface-name", "/path/to/container/namespace", "sandbox-name", "some-vxlan") Expect(err).To(MatchError("open container netns: POTATO")) }) }) It("should construct the correct command sequence", func() { err := deletor.Delete("some-interface-name", "/path/to/container/namespace", "sandbox-name", "some-vxlan") Expect(err).NotTo(HaveOccurred()) Expect(executor.ExecuteCallCount()).To(Equal(1)) Expect(executor.ExecuteArgsForCall(0)).To(Equal( commands.All( commands.InNamespace{ Namespace: containerNS, Command: commands.DeleteLink{ LinkName: "some-interface-name", }, }, commands.CleanupSandbox{ SandboxName: "sandbox-name", VxlanDeviceName: "some-vxlan", }, ), )) })
_, err := creator.Setup(config) Expect(err).NotTo(HaveOccurred()) Expect(sandbox.LockCallCount()).To(Equal(1)) Expect(sandbox.UnlockCallCount()).To(Equal(1)) }) It("should execute the IdempotentlyCreateSandbox command group", func() { createSandboxResult := &fakes.Command{} commandBuilder.IdempotentlyCreateSandboxReturns(createSandboxResult) _, err := creator.Setup(config) Expect(err).NotTo(HaveOccurred()) Expect(ex.ExecuteCallCount()).To(Equal(3)) Expect(ex.ExecuteArgsForCall(0)).To(Equal(createSandboxResult)) sandboxName, vxlanName, vni, dnsAddress := commandBuilder.IdempotentlyCreateSandboxArgsForCall(0) Expect(sandboxName).To(Equal("vni-99")) Expect(vxlanName).To(Equal("vxlan99")) Expect(vni).To(Equal(99)) Expect(dnsAddress).To(Equal("some-dns-address")) }) 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")) })