diff options
author | n-peugnet <n.peugnet@free.fr> | 2021-09-01 16:01:04 +0200 |
---|---|---|
committer | n-peugnet <n.peugnet@free.fr> | 2021-09-01 16:01:04 +0200 |
commit | ba102f52038ee1a47352443a44e8ccd4e20bcbcb (patch) | |
tree | 22b73dee82da4bee2ff88a8ab68d9b2af2ed445d | |
parent | 72ec5a391646014531727fb3a71987d87b8a6933 (diff) | |
download | dna-backup-ba102f52038ee1a47352443a44e8ccd4e20bcbcb.tar.gz dna-backup-ba102f52038ee1a47352443a44e8ccd4e20bcbcb.zip |
split bsdiff test into smaller functions
-rw-r--r-- | repo_test.go | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/repo_test.go b/repo_test.go index eaacefd..19e1677 100644 --- a/repo_test.go +++ b/repo_test.go @@ -150,32 +150,44 @@ func TestStoreLoadFiles(t *testing.T) { } } -func TestBsdiff(t *testing.T) { - resultDir := t.TempDir() - dataDir := path.Join("test", "data", "logs") - addedFile := path.Join(dataDir, "2", "slogTest.log") +func prepareChunks(dataDir string, resultDir string, streamFunc func([]File, io.WriteCloser)) { resultVersion := path.Join(resultDir, "00000") resultChunks := path.Join(resultVersion, chunksName) os.MkdirAll(resultChunks, 0775) - reader, writer := io.Pipe() + reader := getDataStream(dataDir, streamFunc) chunks := make(chan []byte, 16) - files := listFiles(dataDir) - go concatFiles(files, writer) go chunkStream(reader, chunks) storeChunks(resultChunks, chunks) +} +func getDataStream(dataDir string, streamFunc func([]File, io.WriteCloser)) io.Reader { + reader, writer := io.Pipe() + files := listFiles(dataDir) + go streamFunc(files, writer) + return reader +} + +func TestBsdiff(t *testing.T) { + resultDir := t.TempDir() + dataDir := path.Join("test", "data", "logs") + addedFile := path.Join(dataDir, "2", "slogTest.log") + // Store initial chunks + prepareChunks(dataDir, resultDir, concatFiles) + + // Modify data input := []byte("hello") ioutil.WriteFile(addedFile, input, 0664) defer os.Remove(addedFile) - reader, writer = io.Pipe() + // Load previously stored chunks oldChunks := make(chan StoredChunk, 16) - files = listFiles(dataDir) repo := NewRepo(resultDir) versions := repo.loadVersions() go repo.loadChunks(versions, oldChunks) - go concatFiles(files, writer) fingerprints, sketches := hashChunks(oldChunks) + + // Read new data + reader := getDataStream(dataDir, concatFiles) recipe := repo.matchStream(reader, fingerprints) newChunks := extractTempChunks(mergeTempChunks(recipe)) assertLen(t, 2, newChunks, "New chunks:") |