pkg/ns: test IsNSFS()
authorStefan Junker <mail@stefanjunker.de>
Tue, 24 May 2016 20:30:01 +0000 (22:30 +0200)
committerStefan Junker <mail@stefanjunker.de>
Tue, 24 May 2016 20:30:49 +0000 (22:30 +0200)
ns/ns_test.go

index d89e693..82001ea 100644 (file)
@@ -211,6 +211,28 @@ var _ = Describe("Linux namespace operations", func() {
                        })
                })
        })
+
+       Describe("IsNSFS", func() {
+               It("should detect a namespace", func() {
+                       createdNetNS, err := ns.NewNS()
+                       isNSFS, err := ns.IsNSFS(createdNetNS.Path())
+                       Expect(err).NotTo(HaveOccurred())
+                       Expect(isNSFS).To(Equal(true))
+               })
+
+               It("should refuse other paths", func() {
+                       tempFile, err := ioutil.TempFile("", "nstest")
+                       Expect(err).NotTo(HaveOccurred())
+                       defer tempFile.Close()
+
+                       nspath := tempFile.Name()
+                       defer os.Remove(nspath)
+
+                       isNSFS, err := ns.IsNSFS(nspath)
+                       Expect(err).NotTo(HaveOccurred())
+                       Expect(isNSFS).To(Equal(false))
+               })
+       })
 })
 
 func allNetNSInCurrentProcess() []string {