mirror of
https://github.com/restic/restic.git
synced 2026-02-03 04:20:45 -05:00
data: test LoadTree+SaveTree cycle
This commit is contained in:
parent
6de64911fb
commit
fa8889eec4
1 changed files with 21 additions and 0 deletions
|
|
@ -8,6 +8,7 @@ import (
|
|||
"path/filepath"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/restic/restic/internal/archiver"
|
||||
|
|
@ -161,6 +162,26 @@ func TestTreeEqualSerialization(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestTreeLoadSaveCycle(t *testing.T) {
|
||||
files := []string{"node.go", "tree.go", "tree_test.go"}
|
||||
builder := data.NewTreeJSONBuilder()
|
||||
for _, fn := range files {
|
||||
node := nodeForFile(t, fn)
|
||||
rtest.OK(t, builder.AddNode(node))
|
||||
}
|
||||
buf, err := builder.Finalize()
|
||||
rtest.OK(t, err)
|
||||
|
||||
tm := data.TestTreeMap{restic.Hash(buf): buf}
|
||||
it, err := data.LoadTree(context.TODO(), tm, restic.Hash(buf))
|
||||
rtest.OK(t, err)
|
||||
|
||||
mtm := data.TestWritableTreeMap{TestTreeMap: data.TestTreeMap{}}
|
||||
id, err := data.SaveTree(context.TODO(), mtm, it)
|
||||
rtest.OK(t, err)
|
||||
rtest.Equals(t, restic.Hash(buf), id, "saved tree id mismatch")
|
||||
}
|
||||
|
||||
func BenchmarkBuildTree(b *testing.B) {
|
||||
const size = 100 // Directories of this size are not uncommon.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue