MCPcopy Create free account
hub / github.com/bobg/hashsplit / TestTree

Function TestTree

hashsplit_test.go:61–99  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

59}
60
61func TestTree(t *testing.T) {
62 text, err := os.ReadFile("testdata/commonsense.txt")
63 if err != nil {
64 t.Fatal(err)
65 }
66
67 root, err := buildTree(text)
68 if err != nil {
69 t.Fatal(err)
70 }
71
72 if !compareTrees(root, wantTree) {
73 t.Fatal("tree mismatch")
74 }
75
76 var innerErr error
77
78 pr, pw := io.Pipe()
79 go func() {
80 defer pw.Close()
81 for chunk := range root.AllChunks() {
82 _, innerErr = pw.Write(chunk)
83 if innerErr != nil {
84 return
85 }
86 }
87 }()
88
89 reassembled, err := io.ReadAll(pr)
90 if err != nil {
91 t.Fatal(err)
92 }
93 if innerErr != nil {
94 t.Fatal(innerErr)
95 }
96 if !bytes.Equal(text, reassembled) {
97 t.Error("reassembled text does not match original")
98 }
99}
100
101func TestSeek(t *testing.T) {
102 text, err := os.ReadFile("testdata/commonsense.txt")

Callers

nothing calls this directly

Calls 3

buildTreeFunction · 0.85
compareTreesFunction · 0.85
AllChunksMethod · 0.80

Tested by

no test coverage detected