コード例 #1
0
ファイル: patch_test.go プロジェクト: cmars/replican-sync
// Test an actual file patch on the munged file scenario from TestMatchMunge.
// Resulting patched file should be identical to the source file.
func TestPatch(t *testing.T) {
	srcPath := "../../testroot/My Music/0 10k 30.mp4"
	dstPath := filepath.Join(os.TempDir(), "foo.mp4")
	os.RemoveAll(dstPath)
	defer os.RemoveAll(dstPath)

	origDstF, err := os.Open("../../testroot/My Music/0 10k 30 munged.mp4")
	assert.Tf(t, err == nil, "%v", err)

	dstF, err := os.Create(dstPath)
	assert.Tf(t, err == nil, "%v", err)

	_, err = io.Copy(dstF, origDstF)
	assert.Tf(t, err == nil, "%v", err)

	origDstF.Close()
	dstF.Close()

	patchPlan, err := Patch(srcPath, dstPath)
	//	printPlan(patchPlan)

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

	srcFileInfo, _, err := fs.IndexFile(srcPath)
	assert.T(t, err == nil)

	dstFileInfo, _, err := fs.IndexFile(dstPath)
	assert.Tf(t, err == nil, "%v", err)

	assert.Equal(t, srcFileInfo.Strong, dstFileInfo.Strong)
}
コード例 #2
0
ファイル: merge_test.go プロジェクト: vanackere/replican-sync
// Test the matcher on a case where the source file has the same 
// prefix as destination, but has been appended to.
func TestMatchAppend(t *testing.T) {
	tg := treegen.New()
	treeSpec := tg.F("bar", tg.B(42, 65537), tg.B(43, 65537))

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

	// Try indexing root dir as a file
	srcFile, err := fs.IndexFile(srcpath)
	assert.Tf(t, err != nil, "%v", err)

	// Ok, for real this time
	srcFile, err = fs.IndexFile(filepath.Join(srcpath, "bar"))
	assert.Tf(t, err == nil, "%v", err)
	assert.Equal(t, 17, len(srcFile.Blocks))

	tg = treegen.New()
	treeSpec = tg.F("bar", tg.B(42, 65537))

	dstpath := treegen.TestTree(t, treeSpec)
	defer os.RemoveAll(dstpath)
	dstFile, err := fs.IndexFile(filepath.Join(dstpath, "bar"))
	assert.Equal(t, 9, len(dstFile.Blocks))

	match, err := MatchFile(srcFile, filepath.Join(dstpath, "bar"))
	assert.T(t, err == nil, "%v", err)

	assert.Equal(t, 8, len(match.BlockMatches))

	notMatched := match.NotMatched()
	assert.Equal(t, 1, len(notMatched))
	assert.Equal(t, int64(65536), notMatched[0].From)
	assert.Equal(t, int64(65537+65537), notMatched[0].To)
}
コード例 #3
0
ファイル: merge_test.go プロジェクト: vanackere/replican-sync
// Test an actual file patch on the munged file scenario from TestMatchMunge.
// Resulting patched file should be identical to the source file.
func TestPatch(t *testing.T) {
	srcPath := "../../testroot/My Music/0 10k 30.mp4"
	dstPath := filepath.Join(os.TempDir(), "foo.mp4")

	os.Remove(dstPath)

	origDstF, err := os.Open("../../testroot/My Music/0 10k 30 munged.mp4")
	assert.Tf(t, err == nil, "%v", err)

	dstF, err := os.Create(dstPath)
	assert.Tf(t, err == nil, "%v", err)

	_, err = io.Copy(dstF, origDstF)
	assert.Tf(t, err == nil, "%v", err)

	origDstF.Close()
	dstF.Close()

	err = PatchFile(srcPath, dstPath)
	if err != nil {
		fmt.Print(err.Error())
	}
	assert.T(t, err == nil)

	srcFile, err := fs.IndexFile(srcPath)
	assert.T(t, err == nil)

	dstFile, err := fs.IndexFile(dstPath)
	assert.Tf(t, err == nil, "%v", err)

	assert.Equal(t, srcFile.Strong(), dstFile.Strong())
}
コード例 #4
0
ファイル: match.go プロジェクト: vanackere/replican-sync
func Match(src string, dst string) (match *FileMatch, err error) {
	var srcFile *fs.File
	srcFile, err = fs.IndexFile(src)
	if srcFile == nil {
		return nil, err
	}

	match, err = MatchFile(srcFile, dst)
	return match, err
}
コード例 #5
0
ファイル: match.go プロジェクト: cmars/replican-sync
func Match(src string, dst string) (match *FileMatch, err os.Error) {
	srcFileInfo, srcBlocksInfo, err := fs.IndexFile(src)
	if err != nil {
		return nil, err
	}

	repo := fs.NewMemRepo()
	srcFile := repo.AddFile(nil, srcFileInfo, srcBlocksInfo)
	match, err = MatchFile(srcFile, dst)
	return match, err
}
コード例 #6
0
ファイル: fs_test.go プロジェクト: cmars/replican-sync
func TestFsIndexSomeMp3(t *testing.T) {
	cwd, _ := os.Getwd()
	t.Logf("CWD=%s", cwd)

	f, blks, err := fs.IndexFile("../../testroot/My Music/0 10k 30.mp4")
	if f == nil {
		t.Fatalf("Failed to index file: %s", err.String())
	}

	assert.Equal(t, "5ab3e5d621402e5894429b5f595a1e2d7e1b3078", f.Strong)
	assert.Equal(t, "d1f11a93449fa4d3f320234743204ce157bbf1f3", blks[0].Strong)
	assert.Equal(t, "eabbe570b21cd2c5101a18b51a3174807fa5c0da", blks[1].Strong)
}