sandboxRepository *fakes.SandboxRepository sbox *fakes.Sandbox moveLink commands.MoveLink ) BeforeEach(func() { context = &fakes.Context{} linkFactory = &fakes.LinkFactory{} context.LinkFactoryReturns(linkFactory) sandboxRepository = &fakes.SandboxRepository{} context.SandboxRepositoryReturns(sandboxRepository) sbox = &fakes.Sandbox{} sandboxRepository.GetReturns(sbox, nil) ns := &fakes.Namespace{} ns.FdReturns(999) 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)
dnsServerFactory = &fakes.DNSServerFactory{} ns = &fakes.Namespace{} sandboxRepo = &fakes.SandboxRepository{} sbox = &fakes.Sandbox{} sbox.NamespaceReturns(ns) dnsServer = &fakes.Runner{} dnsServerFactory.NewReturns(dnsServer) context = &fakes.Context{} context.ListenerFactoryReturns(listenerFactory) context.LinkFactoryReturns(linkFactory) context.AddressManagerReturns(addressManager) context.DNSServerFactoryReturns(dnsServerFactory) context.SandboxRepositoryReturns(sandboxRepo) sandboxRepo.GetReturns(sbox, nil) returnedListener = &net.UDPConn{} listenerFactory.ListenUDPReturns(returnedListener, nil) 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() {
} return nil } }) It("gets the sandbox by name", func() { err := cleanupSandboxCommand.Execute(context) Expect(err).NotTo(HaveOccurred()) Expect(sandboxRepo.GetCallCount()).To(Equal(1)) Expect(sandboxRepo.GetArgsForCall(0)).To(Equal("sandbox-name")) }) Context("when sandbox doesn't exist", func() { It("returns without an error", func() { sandboxRepo.GetReturns(nil, sandbox.NotFoundError) err := cleanupSandboxCommand.Execute(context) Expect(err).NotTo(HaveOccurred()) }) }) Context("when getting the sandbox fails", func() { BeforeEach(func() { sandboxRepo.GetReturns(nil, errors.New("raisins")) }) It("returns an error", func() { err := cleanupSandboxCommand.Execute(context) Expect(err).To(MatchError("get sandbox: raisins")) })
context *fakes.Context ) BeforeEach(func() { repo = &fakes.SandboxRepository{} context = &fakes.Context{} context.SandboxRepositoryReturns(repo) sandboxExists = conditions.SandboxExists{ 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)
}, GW: net.ParseIP("192.168.1.1"), }, { Dst: net.IPNet{ IP: net.ParseIP("192.168.2.5"), Mask: net.CIDRMask(24, 32), }, GW: net.ParseIP("192.168.1.99"), }}, }, } sandboxNS = &fakes.Namespace{NameStub: func() string { return "sandbox ns sentinel" }} sandbox.NamespaceReturns(sandboxNS) sandboxRepo.GetReturns(sandbox, nil) ex.ExecuteStub = func(command executor.Command) error { switch ex.ExecuteCallCount() { case 3: nsCommand := command.(commands.InNamespace) getCommand := nsCommand.Command.(*commands.GetHardwareAddress) getCommand.Result = containerMAC } return nil } config = container.CreatorConfig{ NetworkID: "some-crazy-network-id", ContainerNsPath: "/some/container/ns/path", ContainerID: "123456789012345",