missWatcher *fakes.MissWatcher namespaceRepository *fakes.Repository sandboxRepo *fakes.SandboxRepository ) BeforeEach(func() { context = &fakes.Context{} logger = lagertest.NewTestLogger("test") context.LoggerReturns(logger) sandboxNS = &fakes.Namespace{} sandboxNS.NameReturns("sandbox-name") sbox = &fakes.Sandbox{} sbox.NamespaceReturns(sandboxNS) linkFactory = &fakes.LinkFactory{} context.LinkFactoryReturns(linkFactory) missWatcher = &fakes.MissWatcher{} namespaceRepository = &fakes.Repository{} sandboxRepo = &fakes.SandboxRepository{} sandboxRepo.GetStub = func(key string) (sandbox.Sandbox, error) { if key == "sandbox-name" { return sbox, nil } return nil, sandbox.NotFoundError } context.SandboxRepositoryReturns(sandboxRepo)
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) Expect(err).NotTo(HaveOccurred()) Expect(sandboxRepository.GetCallCount()).To(Equal(1)) Expect(sandboxRepository.GetArgsForCall(0)).To(Equal("sandbox-name")) })
expectedSandbox, err := sandboxRepo.Create("some-sandbox-name") Expect(err).NotTo(HaveOccurred()) sbox, err := sandboxRepo.Get("some-sandbox-name") Expect(err).NotTo(HaveOccurred()) Expect(sbox).To(Equal(expectedSandbox)) }) }) }) Describe("Destroy", func() { var sbox, otherSbox *fakes.Sandbox BeforeEach(func() { sbox = &fakes.Sandbox{} sbox.NamespaceReturns(sboxNamespace) sandboxRepo.Sandboxes["some-sandbox-name"] = sbox otherSbox = &fakes.Sandbox{} sandboxRepo.Sandboxes["some-other-sandbox-name"] = otherSbox }) It("locks and unlocks", func() { err := sandboxRepo.Destroy("some-sandbox-name") Expect(err).NotTo(HaveOccurred()) Expect(locker.LockCallCount()).To(Equal(1)) Expect(locker.UnlockCallCount()).To(Equal(1)) }) It("logs entry and exit", func() {