Beispiel #1
0
func TestMove(t *testing.T) {
	data := testutil.CreateDummyBuf(1024)

	withEmptyStore(t, func(st *store.Store) {
		if err := createDummySetup(t, st, data); err != nil {
			return
		}

		check := func(path string, expect []byte) {
			recvBuf := &bytes.Buffer{}
			if err := st.Cat(path, recvBuf); err != nil {
				t.Errorf("Catting of `%s` failed: %v", path, err)
				return
			}

			if !bytes.Equal(recvBuf.Bytes(), expect) {
				t.Errorf("Data differs between add/move/cat")
				return
			}
		}

		check("/dummy", data)

		if err := st.Move("/dummy", "/new_dummy", true); err != nil {
			t.Errorf("Move failed: %v", err)
			return
		}

		if err := st.Cat("/dummy", &bytes.Buffer{}); !store.IsNoSuchFileError(err) {
			t.Errorf("Move: dummy still reachable")
			return
		}

		check("/new_dummy", data)

		if err := st.Move("/dummy", "/new_dummy", true); !store.IsNoSuchFileError(err) {
			t.Errorf("Move could move dead file: %v", err)
			return
		}

		if err := st.Move("/dir", "/other", true); err != nil {
			t.Errorf("Move could not move dir: %v", err)
			return
		}

		check("/other/a", []byte{})
		check("/other/b", []byte{})

		if err := st.Cat("/dir/a", &bytes.Buffer{}); !store.IsNoSuchFileError(err) {
			t.Errorf("Move: /dir/a still reachable")
			return
		}

		if err := st.Cat("/dir/b", &bytes.Buffer{}); !store.IsNoSuchFileError(err) {
			t.Errorf("Move: /dir/b still reachable")
			return
		}
	})
}
Beispiel #2
0
func Errorize(name string, err error) error {
	if store.IsNoSuchFileError(err) {
		return fuse.ENOENT
	}

	if err != nil {
		log.Warningf("fuse: %s: %v", name, err)
		return fuse.EIO
	}

	return nil
}
Beispiel #3
0
func TestRemove(t *testing.T) {
	data := testutil.CreateDummyBuf(1024)

	withEmptyStore(t, func(st *store.Store) {
		if err := createDummySetup(t, st, data); err != nil {
			return
		}

		if _, err := st.Mkdir("/empty_dir"); err != nil {
			t.Errorf("Could not mkdir /empty_dir: %v", err)
			return
		}

		if err := st.Remove("/dummy", false); err != nil {
			t.Errorf("Could not remove /dummy: %v", err)
			return
		}

		if err := st.Remove("/dummy", false); !store.IsNoSuchFileError(err) {
			t.Errorf("Could remove /dummy twice: %v", err)
			return
		}

		if err := st.Remove("/dir", false); err != store.ErrNotEmpty {
			t.Errorf("Remove did not deny removing non-empty dir: %v", err)
			return
		}

		if err := st.Remove("/dir", true); err != nil {
			t.Errorf("Could not remove /dir recursively: %v", err)
			return
		}

		if err := st.Remove("/empty_dir", false); err != nil {
			t.Errorf("Could not remove /empty_dir non-recursively: %v", err)
			return
		}

		if err := st.ViewDir("/", func(root *store.Directory) error {
			if root.Size() != 0 {
				return fmt.Errorf("Size of the tree is not 0 after deletion (%d)", root.Size())
			}

			return nil
		}); err != nil {
			t.Errorf("Failed to get root: %v", err)
			return
		}
	})
}