aboutsummaryrefslogtreecommitdiffstats
path: root/utils/merkletrie/filesystem/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/filesystem/node_test.go
parent7a428a915ce2b7bb0f4fc6dcee77932ebacfabbf (diff)
downloadgo-git-e14ee7a2645b486d72f52a0c62714b3049077554.tar.gz
merkletrie: filesystem and index speedup and documentation
Diffstat (limited to 'utils/merkletrie/filesystem/node_test.go')
-rw-r--r--utils/merkletrie/filesystem/node_test.go47
1 files changed, 17 insertions, 30 deletions
diff --git a/utils/merkletrie/filesystem/node_test.go b/utils/merkletrie/filesystem/node_test.go
index 291af6b..b7c124d 100644
--- a/utils/merkletrie/filesystem/node_test.go
+++ b/utils/merkletrie/filesystem/node_test.go
@@ -1,6 +1,7 @@
package filesystem
import (
+ "bytes"
"io"
"os"
"testing"
@@ -9,6 +10,7 @@ import (
"gopkg.in/src-d/go-billy.v2"
"gopkg.in/src-d/go-billy.v2/memfs"
"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) }
@@ -28,12 +30,7 @@ func (s *NoderSuite) TestDiff(c *C) {
WriteFile(fsB, "qux/bar", []byte("foo"), 0644)
WriteFile(fsB, "qux/qux", []byte("foo"), 0644)
- nodeA, err := NewRootNode(fsA)
- c.Assert(err, IsNil)
- nodeB, err := NewRootNode(fsB)
- c.Assert(err, IsNil)
-
- ch, err := merkletrie.DiffTree(nodeA, nodeB, IsEquals)
+ ch, err := merkletrie.DiffTree(NewRootNode(fsA), NewRootNode(fsB), IsEquals)
c.Assert(err, IsNil)
c.Assert(ch, HasLen, 0)
}
@@ -49,12 +46,7 @@ func (s *NoderSuite) TestDiffChangeContent(c *C) {
WriteFile(fsB, "qux/bar", []byte("bar"), 0644)
WriteFile(fsB, "qux/qux", []byte("foo"), 0644)
- nodeA, err := NewRootNode(fsA)
- c.Assert(err, IsNil)
- nodeB, err := NewRootNode(fsB)
- c.Assert(err, IsNil)
-
- ch, err := merkletrie.DiffTree(nodeA, nodeB, IsEquals)
+ ch, err := merkletrie.DiffTree(NewRootNode(fsA), NewRootNode(fsB), IsEquals)
c.Assert(err, IsNil)
c.Assert(ch, HasLen, 1)
}
@@ -66,12 +58,7 @@ func (s *NoderSuite) TestDiffChangeMissing(c *C) {
fsB := memfs.New()
WriteFile(fsB, "bar", []byte("bar"), 0644)
- nodeA, err := NewRootNode(fsA)
- c.Assert(err, IsNil)
- nodeB, err := NewRootNode(fsB)
- c.Assert(err, IsNil)
-
- ch, err := merkletrie.DiffTree(nodeA, nodeB, IsEquals)
+ ch, err := merkletrie.DiffTree(NewRootNode(fsA), NewRootNode(fsB), IsEquals)
c.Assert(err, IsNil)
c.Assert(ch, HasLen, 2)
}
@@ -83,12 +70,7 @@ func (s *NoderSuite) TestDiffChangeMode(c *C) {
fsB := memfs.New()
WriteFile(fsB, "foo", []byte("foo"), 0755)
- nodeA, err := NewRootNode(fsA)
- c.Assert(err, IsNil)
- nodeB, err := NewRootNode(fsB)
- c.Assert(err, IsNil)
-
- ch, err := merkletrie.DiffTree(nodeA, nodeB, IsEquals)
+ ch, err := merkletrie.DiffTree(NewRootNode(fsA), NewRootNode(fsB), IsEquals)
c.Assert(err, IsNil)
c.Assert(ch, HasLen, 1)
}
@@ -100,12 +82,7 @@ func (s *NoderSuite) TestDiffChangeModeNotRelevant(c *C) {
fsB := memfs.New()
WriteFile(fsB, "foo", []byte("foo"), 0655)
- nodeA, err := NewRootNode(fsA)
- c.Assert(err, IsNil)
- nodeB, err := NewRootNode(fsB)
- c.Assert(err, IsNil)
-
- ch, err := merkletrie.DiffTree(nodeA, nodeB, IsEquals)
+ ch, err := merkletrie.DiffTree(NewRootNode(fsA), NewRootNode(fsB), IsEquals)
c.Assert(err, IsNil)
c.Assert(ch, HasLen, 0)
}
@@ -125,3 +102,13 @@ func WriteFile(fs billy.Filesystem, filename string, data []byte, perm os.FileMo
}
return err
}
+
+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())
+}