github.com/jgarto/itcv@v0.0.0-20180826224514-4eea09c1aa0d/_vendor/src/golang.org/x/tools/godoc/vfs/emptyvfs_test.go (about) 1 // Copyright 2016 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package vfs_test 6 7 import ( 8 "testing" 9 "time" 10 11 "golang.org/x/tools/godoc/vfs" 12 "golang.org/x/tools/godoc/vfs/mapfs" 13 ) 14 15 func TestNewNameSpace(t *testing.T) { 16 17 // We will mount this filesystem under /fs1 18 mount := mapfs.New(map[string]string{"fs1file": "abcdefgh"}) 19 20 // Existing process. This should give error on Stat("/") 21 t1 := vfs.NameSpace{} 22 t1.Bind("/fs1", mount, "/", vfs.BindReplace) 23 24 // using NewNameSpace. This should work fine. 25 t2 := vfs.NewNameSpace() 26 t2.Bind("/fs1", mount, "/", vfs.BindReplace) 27 28 testcases := map[string][]bool{ 29 "/": {false, true}, 30 "/fs1": {true, true}, 31 "/fs1/fs1file": {true, true}, 32 } 33 34 fss := []vfs.FileSystem{t1, t2} 35 36 for j, fs := range fss { 37 for k, v := range testcases { 38 _, err := fs.Stat(k) 39 result := err == nil 40 if result != v[j] { 41 t.Errorf("fs: %d, testcase: %s, want: %v, got: %v, err: %s", j, k, v[j], result, err) 42 } 43 } 44 } 45 46 fi, err := t2.Stat("/") 47 if err != nil { 48 t.Fatal(err) 49 } 50 51 if fi.Name() != "/" { 52 t.Errorf("t2.Name() : want:%s got:%s", "/", fi.Name()) 53 } 54 55 if !fi.ModTime().IsZero() { 56 t.Errorf("t2.Modime() : want:%v got:%v", time.Time{}, fi.ModTime()) 57 } 58 }