func initFileSystems() (fss []fsi.FileSystem, c aetest.Context) { var err error c, err = aetest.NewContext(nil) if err != nil { log.Fatal(err) } // defer c.Close() // Not here, but instead at the start of the test-funcs // We cant make variadic options generic, // since they need the concrete filesystem type. fs1 := dsfs.New( dsfs.MountName(dsfs.MountPointLast()), dsfs.AeContext(c), ) fs3 := osfs.New() fs4 := memfs.New( memfs.Ident("m"), ) fss = []fsi.FileSystem{fs1, fs3, fs4} return fss, c }
func TestPathCleanage(t *testing.T) { log.SetFlags(0) _, c := initFileSystems() defer c.Close() cases := [][]string{ []string{"", "mntX/", ""}, []string{"/", "mntX/", ""}, []string{".", "mntX/", ""}, []string{"./", "mntX/", ""}, []string{"mntX", "mntX/", ""}, []string{"mntX/", "mntX/", ""}, // 5... []string{"file", "mntX/", "file"}, []string{"dir/", "mntX/", "dir/"}, []string{"./dir1/", "mntX/", "dir1/"}, []string{"mntX/dir1", "mntX/", "dir1"}, []string{"mntX/dir1/file2", "mntX/dir1/", "file2"}, // 10 []string{"mntY/dir1/file2", "mntX/mntY/dir1/", "file2"}, []string{"///mntX/dir1/dir2///dir3/", "mntX/dir1/dir2/", "dir3/"}, []string{"mntX/dir1/dir2///file3", "mntX/dir1/dir2/", "file3"}, []string{"/dir1/dir2///file3", "mntX/dir1/dir2/", "file3"}, []string{"dir1/dir2///dir3/", "mntX/dir1/dir2/", "dir3/"}, // 15 []string{"c:\\dir1\\dir2", "mntX/c:/dir1/", "dir2"}, } fs := memfs.New( memfs.Ident("mntX"), ) for i, v := range cases { inpt := v[0] _ = inpt wnt1 := v[1] wnt2 := v[2] dir, bname := common.UnixPather(v[0], fs.RootDir()) fullpath := dir + bname log.Printf("#%2v %-30q %-24q => %-16q %-12q ", i, inpt, dir, bname, fullpath) if wnt1 != dir { t.Errorf("dir #%2v got %-24v - wnt %-16v\n", i, dir, wnt1) } if wnt2 != bname { t.Errorf("bname #%2v got %-24v - wnt %-16v\n", i, bname, wnt2) } if wnt1+wnt2 != fullpath { t.Errorf("fullp #%2v got %-24v - wnt %-16v\n", i, fullpath, wnt1+wnt2) } } }
import ( "bytes" "net/http" "sync" "github.com/pbberlin/tools/net/http/loghttp" "github.com/pbberlin/tools/os/fsi/dsfs" "github.com/pbberlin/tools/os/fsi/memfs" "google.golang.org/appengine" ) const TplPrefix = "/mnt02" const pathToTmpl = "/page/programmatic_content/index.html" var fs1 = memfs.New( memfs.Ident(TplPrefix[1:]), // a closured variable in init( ) did not survive map-pointer reallocation ) // Implements fsi.File type SyncedMap struct { sync.Mutex mp map[string]string } // We need this, since we have that additional step of putting the {{ .Variable }} strings into the hugo html var mp = SyncedMap{mp: map[string]string{}} func TemplateFromHugoReset(w http.ResponseWriter, r *http.Request, mapOnerous map[string]interface{}) { r.Header.Set("X-Custom-Header-Counter", "nocounter") mpOld := mp