aboutsummaryrefslogtreecommitdiffstats
path: root/utils/merkletrie/index/node_test.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-04-11 23:20:06 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2017-04-11 23:20:06 +0200
commite14ee7a2645b486d72f52a0c62714b3049077554 (patch)
treeb3acc4ebfedd7f70289f47bd520a7e2d0514e4d3 /utils/merkletrie/index/node_test.go
parent7a428a915ce2b7bb0f4fc6dcee77932ebacfabbf (diff)
downloadgo-git-e14ee7a2645b486d72f52a0c62714b3049077554.tar.gz
merkletrie: filesystem and index speedup and documentation
Diffstat (limited to 'utils/merkletrie/index/node_test.go')
-rw-r--r--utils/merkletrie/index/node_test.go40
1 files changed, 16 insertions, 24 deletions
diff --git a/utils/merkletrie/index/node_test.go b/utils/merkletrie/index/node_test.go
index 0ee0884..48aa35f 100644
--- a/utils/merkletrie/index/node_test.go
+++ b/utils/merkletrie/index/node_test.go
@@ -1,12 +1,14 @@
package index
import (
+ "bytes"
"testing"
. "gopkg.in/check.v1"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/format/index"
"gopkg.in/src-d/go-git.v4/utils/merkletrie"
+ "gopkg.in/src-d/go-git.v4/utils/merkletrie/noder"
)
func Test(t *testing.T) { TestingT(t) }
@@ -34,12 +36,7 @@ func (s *NoderSuite) TestDiff(c *C) {
},
}
- nodeA, err := NewRootNode(indexA)
- c.Assert(err, IsNil)
- nodeB, err := NewRootNode(indexB)
- c.Assert(err, IsNil)
-
- ch, err := merkletrie.DiffTree(nodeA, nodeB, IsEquals)
+ ch, err := merkletrie.DiffTree(NewRootNode(indexA), NewRootNode(indexB), isEquals)
c.Assert(err, IsNil)
c.Assert(ch, HasLen, 0)
}
@@ -57,12 +54,7 @@ func (s *NoderSuite) TestDiffChange(c *C) {
},
}
- nodeA, err := NewRootNode(indexA)
- c.Assert(err, IsNil)
- nodeB, err := NewRootNode(indexB)
- c.Assert(err, IsNil)
-
- ch, err := merkletrie.DiffTree(nodeA, nodeB, IsEquals)
+ ch, err := merkletrie.DiffTree(NewRootNode(indexA), NewRootNode(indexB), isEquals)
c.Assert(err, IsNil)
c.Assert(ch, HasLen, 2)
}
@@ -80,12 +72,7 @@ func (s *NoderSuite) TestDiffDir(c *C) {
},
}
- nodeA, err := NewRootNode(indexA)
- c.Assert(err, IsNil)
- nodeB, err := NewRootNode(indexB)
- c.Assert(err, IsNil)
-
- ch, err := merkletrie.DiffTree(nodeA, nodeB, IsEquals)
+ ch, err := merkletrie.DiffTree(NewRootNode(indexA), NewRootNode(indexB), isEquals)
c.Assert(err, IsNil)
c.Assert(ch, HasLen, 2)
}
@@ -105,12 +92,17 @@ func (s *NoderSuite) TestDiffSameRoot(c *C) {
},
}
- nodeA, err := NewRootNode(indexA)
- c.Assert(err, IsNil)
- nodeB, err := NewRootNode(indexB)
- c.Assert(err, IsNil)
-
- ch, err := merkletrie.DiffTree(nodeA, nodeB, IsEquals)
+ ch, err := merkletrie.DiffTree(NewRootNode(indexA), NewRootNode(indexB), isEquals)
c.Assert(err, IsNil)
c.Assert(ch, HasLen, 1)
}
+
+var empty = make([]byte, 24)
+
+func isEquals(a, b noder.Hasher) bool {
+ if bytes.Equal(a.Hash(), empty) || bytes.Equal(b.Hash(), empty) {
+ return false
+ }
+
+ return bytes.Equal(a.Hash(), b.Hash())
+}