context *fakes.Context sandboxRepository *fakes.Repository startMonitor commands.StartMonitor fakeWatcher *fakes.MissWatcher hostNS *fakes.Namespace sandboxNS *fakes.Namespace ) BeforeEach(func() { context = &fakes.Context{} sandboxRepository = &fakes.Repository{} context.SandboxNamespaceRepositoryReturns(sandboxRepository) sandboxNS = &fakes.Namespace{} sandboxRepository.GetReturns(sandboxNS, nil) hostNS = &fakes.Namespace{} fakeWatcher = &fakes.MissWatcher{} startMonitor = commands.StartMonitor{ HostNamespace: hostNS, Watcher: fakeWatcher, SandboxName: "some-sandbox", VxlanLinkName: "some-vxlan-name", } hostNS.ExecuteStub = func(callback func(_ *os.File) error) error { return callback(nil) }
Describe("Load", func() { var ( sboxFile *os.File sboxFileName string sboxNamespaceDir string ) BeforeEach(func() { var err error sboxNamespaceDir, err = ioutil.TempDir("", "") Expect(err).NotTo(HaveOccurred()) sboxFile, err = ioutil.TempFile(sboxNamespaceDir, "test") sboxFileName = path.Base(sboxFile.Name()) Expect(err).NotTo(HaveOccurred()) namespaceRepo.GetReturns(sboxNamespace, nil) }) It("reads in files from the sanboxNamespaceDir into memory", func() { sbox, err := sandboxRepo.Get(sboxFileName) Expect(err).To(Equal(sandbox.NotFoundError)) Expect(sbox).To(BeNil()) err = sandboxRepo.Load(sboxNamespaceDir) Expect(err).NotTo(HaveOccurred()) Expect(namespaceRepo.GetCallCount()).To(Equal(1)) Expect(namespaceRepo.GetArgsForCall(0)).To(Equal(sboxFileName)) sbox, err = sandboxRepo.Get(sboxFileName) Expect(err).NotTo(HaveOccurred())