func TestRWVFS(t *testing.T) { tmpdir, err := ioutil.TempDir("", "rwvfs-test-") if err != nil { t.Fatal("TempDir", err) } defer os.RemoveAll(tmpdir) h := http.Handler(rwvfs.HTTPHandler(rwvfs.Map(map[string]string{}), nil)) httpServer := httptest.NewServer(h) defer httpServer.Close() httpURL, err := url.Parse(httpServer.URL) if err != nil { t.Fatal(err) } tests := []struct { fs rwvfs.FileSystem }{ {rwvfs.OS(tmpdir)}, {rwvfs.Map(map[string]string{})}, {rwvfs.Sub(rwvfs.Map(map[string]string{}), "/x")}, {rwvfs.HTTP(httpURL, nil)}, {rwvfs.Union(rwvfs.Map(map[string]string{}), rwvfs.Map(map[string]string{}))}, } for _, test := range tests { testutil.Write(t, test.fs) testutil.Mkdir(t, test.fs) testutil.MkdirAll(t, test.fs) testutil.Glob(t, test.fs) } }
func TestBuildDataService_ListAll(t *testing.T) { setup() defer teardown() pathPrefix := urlPath(t, router.RepoBuildDataEntry, map[string]string{"RepoSpec": "r.com/x", "Rev": "c", "Path": "."}) fs := rwvfs.Map(map[string]string{ "a": "a", "b/c": "c", "b/d/e": "e", }) mux.Handle(pathPrefix+"/", http.StripPrefix(pathPrefix, rwvfs.HTTPHandler(fs, nil))) fs, err := client.BuildData.FileSystem(RepoRevSpec{RepoSpec: RepoSpec{URI: "r.com/x"}, Rev: "c"}) if err != nil { t.Fatal(err) } entries, err := rwvfs.StatAllRecursive(".", rwvfs.Walkable(fs)) if err != nil { t.Fatalf("StatAllRecursive returned error: %v", err) } names := fileInfoNames(entries) wantNames := []string{".", "a", "b", "b/c", "b/d", "b/d/e"} sort.Strings(names) sort.Strings(wantNames) if !reflect.DeepEqual(names, wantNames) { t.Errorf("got entry names %v, want %v", names, wantNames) } }
func TestHTTP_BaseURL(t *testing.T) { m := map[string]string{"b/c": "c"} mapFS := rwvfs.Map(m) prefix := "/foo/bar/baz" h := http.Handler(http.StripPrefix(prefix, rwvfs.HTTPHandler(mapFS, nil))) httpServer := httptest.NewServer(h) defer httpServer.Close() httpURL, err := url.Parse(httpServer.URL + prefix) if err != nil { t.Fatal(err) } fs := rwvfs.HTTP(httpURL, nil) if err := rwvfs.MkdirAll(fs, "b"); err != nil { t.Errorf("MkdirAll %q: %s", "b", err) } fis, err := fs.ReadDir("b") if err != nil { t.Fatal(err) } if len(fis) != 1 { t.Errorf("got len(fis) == %d, want 1", len(fis)) } if wantName := "c"; fis[0].Name() != wantName { t.Errorf("got name == %q, want %q", fis[0].Name(), wantName) } }