Esempio n. 1
0
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)
	}
}
Esempio n. 2
0
func TestEmptyUnion(t *testing.T) {
	u := rwvfs.Union()
	infos, err := u.ReadDir("/")
	if err != nil {
		t.Fatal(err)
	}
	if got, want := len(infos), 0; got != want {
		t.Errorf(`ReadDir: got %d, want %d`, got, want)
	}

	_, err = u.Create("/foo")
	if err == nil {
		t.Error("Create: read-only error expected")
	}
}
Esempio n. 3
0
func TestUnion(t *testing.T) {
	m1 := map[string]string{"foo/file": ""}
	m2 := map[string]string{"bar/file": ""}
	u := rwvfs.Union(rwvfs.Map(m1), rwvfs.Map(m2))

	infos, err := u.ReadDir("/")
	if err != nil {
		t.Fatal(err)
	}
	if got, want := len(infos), 2; got != want {
		t.Errorf(`ReadDir: got %d, want %d`, got, want)
	}

	testCreate(t, u, "test", m1)
	testCreate(t, u, "foo/test", m1)
	testCreate(t, u, "bar/test", m2)
}