Expect(err).NotTo(HaveOccurred()) }) AfterEach(func() { os.RemoveAll(dir) }) Describe("PathOf", func() { It("returns the full path of a namespace in the repository", func() { Expect(repo.PathOf("some-namespace")).To(Equal(filepath.Join(dir, "some-namespace"))) }) }) Describe("Destroy", func() { It("removes the namespace bind mount and file and logs the operation", func() { ns, err := repo.Create("destroy-ns-test") Expect(err).NotTo(HaveOccurred()) err = repo.Destroy(ns) Expect(err).NotTo(HaveOccurred()) Expect(path.Join(dir, "destroy-ns-test")).NotTo(BeAnExistingFile()) Expect(logger).To(gbytes.Say("destroy.destroying.*destroy-ns-test")) }) Context("when the namespace is not located within this repository", func() { var ( ns namespace.Namespace anotherRepo namespace.Repository repoDir string )
logger = lagertest.NewTestLogger("test") threadLocker := &ossupport.OSLocker{} // sandboxRepo, err = namespace.NewRepository(logger, sandboxRepoDir, threadLocker) // Expect(err).NotTo(HaveOccurred()) containerRepoDir, err := ioutil.TempDir("", "containers") Expect(err).NotTo(HaveOccurred()) containerRepo, err = namespace.NewRepository(logger, containerRepoDir, threadLocker) Expect(err).NotTo(HaveOccurred()) guid, err := uuid.NewV4() Expect(err).NotTo(HaveOccurred()) containerNamespace, err = containerRepo.Create(guid.String()) Expect(err).NotTo(HaveOccurred()) configFilePath = writeConfigFile(config.Daemon{ ListenHost: "127.0.0.1", ListenPort: 4001 + GinkgoParallelNode(), LocalSubnet: "192.168.1.0/16", OverlayNetwork: "192.168.0.0/16", SandboxDir: sandboxRepoDir, Database: testDatabase.DBConfig(), HostAddress: "10.11.12.13", OverlayDNSAddress: "192.168.255.254", ExternalDNSServer: "8.8.8.8", Suffix: "potato", })
}) Describe("Create", func() { var repo namespace.Repository var name string BeforeEach(func() { var err error repo, err = namespace.NewRepository(logger, repoDir, threadLocker) Expect(err).NotTo(HaveOccurred()) name = fmt.Sprintf("test-ns-%d", GinkgoParallelNode()) }) It("creates a namespace in the repository", func() { ns, err := repo.Create(name) Expect(err).NotTo(HaveOccurred()) nsPath := filepath.Join(repoDir, name) defer unix.Unmount(nsPath, unix.MNT_DETACH) Expect(ns.Name()).To(Equal(nsPath)) var repoStat unix.Stat_t err = unix.Stat(nsPath, &repoStat) Expect(err).NotTo(HaveOccurred()) var namespaceInode string callback := func(_ *os.File) error { output, err := exec.Command("stat", "-L", "-c", "%i", "/proc/self/ns/net").CombinedOutput() namespaceInode = strings.TrimSpace(string(output))