pkg/ns: test case for rejecting a non-ns nspath
authorStefan Junker <mail@stefanjunker.de>
Tue, 24 May 2016 20:21:57 +0000 (22:21 +0200)
committerStefan Junker <mail@stefanjunker.de>
Tue, 24 May 2016 20:30:49 +0000 (22:30 +0200)
ns/ns_test.go

index de0f385..d89e693 100644 (file)
@@ -17,6 +17,7 @@ package ns_test
 import (
        "errors"
        "fmt"
+       "io/ioutil"
        "os"
        "path/filepath"
 
@@ -169,6 +170,18 @@ var _ = Describe("Linux namespace operations", func() {
                                        Expect(netnsInode).NotTo(Equal(createdNetNSInode))
                                }
                        })
+
+                       It("fails when the path is not a namespace", func() {
+                               tempFile, err := ioutil.TempFile("", "nstest")
+                               Expect(err).NotTo(HaveOccurred())
+                               defer tempFile.Close()
+
+                               nspath := tempFile.Name()
+                               defer os.Remove(nspath)
+
+                               _, err = ns.GetNS(nspath)
+                               Expect(err).To(MatchError(fmt.Sprintf("%v is not of type NSFS", nspath)))
+                       })
                })
 
                Describe("closing a network namespace", func() {