Esempio n. 1
0
func DoTestDirDescent(t *testing.T, repo fs.NodeRepo) {
	tg := treegen.New()
	treeSpec := tg.D("foo",
		tg.F("baobab", tg.B(91, 65537)),
		tg.D("bar",
			tg.D("aleph",
				tg.F("a", tg.B(42, 65537)))),
		tg.F("bar3003", tg.B(777, 65537)))

	path := treegen.TestTree(t, treeSpec)
	defer os.RemoveAll(path)

	dir, errors := fs.IndexDir(path, repo)
	assert.Equalf(t, 0, len(errors), "%v", errors)

	for _, fpath := range []string{
		filepath.Join("foo", "baobab"),
		filepath.Join("foo", "bar", "aleph", "a"),
		filepath.Join("foo", "bar3003")} {
		node, found := fs.Lookup(dir, fpath)
		assert.Tf(t, found, "not found: %s", fpath)
		_, isFile := node.(fs.File)
		assert.T(t, isFile)
	}

	node, found := fs.Lookup(dir, filepath.Join("foo", "bar"))
	assert.T(t, found)
	_, isDir := node.(fs.Dir)
	assert.T(t, isDir)
}
Esempio n. 2
0
func DoTestPatchRenameScope(t *testing.T, mkrepo repoMaker) {
	tg := treegen.New()
	treeSpec := tg.D("foo",
		tg.F("bar", tg.B(6806, 65536)),
		tg.F("baz", tg.B(6806, 65536)))

	srcpath := treegen.TestTree(t, treeSpec)
	defer os.RemoveAll(srcpath)
	srcRepo := mkrepo(t)
	defer srcRepo.Close()
	srcStore, err := fs.NewLocalStore(srcpath, srcRepo)
	assert.T(t, err == nil)

	tg = treegen.New()
	treeSpec = tg.D("foo",
		tg.F("baz", tg.B(6806, 65536)),
		tg.F("blop", tg.B(6806, 65536)))

	dstpath := treegen.TestTree(t, treeSpec)
	defer os.RemoveAll(dstpath)
	dstRepo := mkrepo(t)
	defer dstRepo.Close()
	dstStore, err := fs.NewLocalStore(dstpath, dstRepo)
	assert.T(t, err == nil)

	patchPlan := NewPatchPlan(srcStore, dstStore)
	//	printPlan(patchPlan)

	failedCmd, err := patchPlan.Exec()
	assert.Tf(t, failedCmd == nil && err == nil, "%v: %v", failedCmd, err)

	// The actual content of dst after the patch depends on
	// which file the repo chooses when matching foo/bar
	// to baz or blop in dst.
	//
	// If blop matches, it will get renamed to bar and the trees will
	// become identical. However if baz matches, blop will be left in place.

	srcDir, errors := fs.IndexDir(srcpath, fs.NewMemRepo())
	assert.Equalf(t, 0, len(errors), "%v", errors)
	dstDir, errors := fs.IndexDir(dstpath, fs.NewMemRepo())
	assert.Equalf(t, 0, len(errors), "%v", errors)

	for _, path := range []string{"foo/bar", "foo/baz"} {
		srcNode, has := fs.Lookup(srcDir, path)
		assert.T(t, has)
		dstNode, has := fs.Lookup(dstDir, path)
		assert.T(t, has)

		assert.Equal(t,
			srcNode.(fs.File).Info().Strong,
			dstNode.(fs.File).Info().Strong)
	}
}
Esempio n. 3
0
func DoTestDirResolve(t *testing.T, repo fs.NodeRepo) {
	tg := treegen.New()
	treeSpec := tg.D("foo",
		tg.D("bar",
			tg.D("aleph",
				tg.F("A", tg.B(42, 65537)),
				tg.F("a", tg.B(42, 65537))),
			tg.D("beth",
				tg.F("B", tg.B(43, 65537)),
				tg.F("b", tg.B(43, 65537))),
			tg.D("jimmy",
				tg.F("G", tg.B(44, 65537)),
				tg.F("g", tg.B(44, 65537)))),
		tg.D("baz",
			tg.D("uno",
				tg.F("1", tg.B(1, 65537)),
				tg.F("I", tg.B(1, 65537))),
			tg.D("dos",
				tg.F("2", tg.B(11, 65537)),
				tg.F("II", tg.B(11, 65537))),
			tg.D("tres",
				tg.F("3", tg.B(111, 65537)),
				tg.F("III", tg.B(111, 65537)))))

	path := treegen.TestTree(t, treeSpec)
	defer os.RemoveAll(path)

	foo, errors := fs.IndexDir(filepath.Join(path, "foo"), repo)
	assert.Equalf(t, 0, len(errors), "%v", errors)

	var node fs.FsNode
	var found bool

	node, found = fs.Lookup(foo, "bar")
	assert.T(t, found)
	_, isDir := node.(fs.Dir)
	assert.T(t, isDir)

	node, found = fs.Lookup(foo, filepath.Join("bar", "aleph"))
	assert.T(t, found)
	_, isDir = node.(fs.Dir)
	assert.T(t, isDir)

	node, found = fs.Lookup(foo, filepath.Join("bar", "aleph", "A"))
	assert.T(t, found)
	_, isFile := node.(fs.File)
	assert.T(t, isFile)
}