github.com/schwarzm/garden-linux@v0.0.0-20150507151835-33bca2147c47/old/rootfs_provider/namespaced_rootfs_provider_test.go (about) 1 package rootfs_provider_test 2 3 import ( 4 "io/ioutil" 5 "os" 6 "path/filepath" 7 "time" 8 9 "github.com/cloudfoundry-incubator/garden-linux/old/rootfs_provider" 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 "github.com/pivotal-golang/lager" 13 ) 14 15 var _ = Describe("Namespacer", func() { 16 var rootfs string 17 18 BeforeEach(func() { 19 var err error 20 rootfs, err = ioutil.TempDir("", "rootfs") 21 Expect(err).NotTo(HaveOccurred()) 22 23 os.MkdirAll(filepath.Join(rootfs, "foo", "bar", "baz"), 0755) 24 ioutil.WriteFile(filepath.Join(rootfs, "foo", "beans"), []byte("jam"), 0755) 25 }) 26 27 It("translates all of the uids", func() { 28 var translated []translation 29 namespacer := &rootfs_provider.UidNamespacer{ 30 Logger: lager.NewLogger("test"), 31 Translator: func(path string, info os.FileInfo, err error) error { 32 translated = append(translated, translation{ 33 path: path, 34 size: info.Size(), 35 mode: info.Mode(), 36 modTime: info.ModTime(), 37 err: err, 38 }) 39 40 return nil 41 }, 42 } 43 44 err := namespacer.Namespace(rootfs) 45 46 info, err := os.Stat(filepath.Join(rootfs, "foo", "bar", "baz")) 47 Expect(err).NotTo(HaveOccurred()) 48 Expect(translated).To(ContainElement(translation{ 49 path: filepath.Join(rootfs, "foo", "bar", "baz"), 50 size: info.Size(), 51 mode: info.Mode(), 52 modTime: info.ModTime(), 53 err: nil, 54 })) 55 56 info, err = os.Stat(filepath.Join(rootfs, "foo", "beans")) 57 Expect(err).NotTo(HaveOccurred()) 58 Expect(translated).To(ContainElement(translation{ 59 path: filepath.Join(rootfs, "foo", "beans"), 60 size: info.Size(), 61 mode: info.Mode(), 62 modTime: info.ModTime(), 63 err: nil, 64 })) 65 66 Expect(info.Mode()).To(Equal(os.FileMode(0755))) 67 }) 68 }) 69 70 type translation struct { 71 path string 72 size int64 73 mode os.FileMode 74 modTime time.Time 75 err error 76 }