diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-04-09 10:33:09 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2017-04-11 04:34:49 +0200 |
commit | 6a00b3004a9bc9f86a041b59dc27e6b24695fc13 (patch) | |
tree | aa10c054aaf6d48742dcaa089175cd79660593b0 /utils/merkletrie/index/node_test.go | |
parent | 777dcd5647ffb263a8bbf3887232ee207138468a (diff) | |
download | go-git-6a00b3004a9bc9f86a041b59dc27e6b24695fc13.tar.gz |
merkletrie: node support for index file
Diffstat (limited to 'utils/merkletrie/index/node_test.go')
-rw-r--r-- | utils/merkletrie/index/node_test.go | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/utils/merkletrie/index/node_test.go b/utils/merkletrie/index/node_test.go new file mode 100644 index 0000000..0ee0884 --- /dev/null +++ b/utils/merkletrie/index/node_test.go @@ -0,0 +1,116 @@ +package index + +import ( + "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" +) + +func Test(t *testing.T) { TestingT(t) } + +type NoderSuite struct{} + +var _ = Suite(&NoderSuite{}) + +func (s *NoderSuite) TestDiff(c *C) { + indexA := &index.Index{ + Entries: []index.Entry{ + {Name: "foo", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")}, + {Name: "bar/foo", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")}, + {Name: "bar/qux", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")}, + {Name: "bar/baz/foo", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")}, + }, + } + + indexB := &index.Index{ + Entries: []index.Entry{ + {Name: "foo", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")}, + {Name: "bar/foo", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")}, + {Name: "bar/qux", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")}, + {Name: "bar/baz/foo", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")}, + }, + } + + nodeA, err := NewRootNode(indexA) + c.Assert(err, IsNil) + nodeB, err := NewRootNode(indexB) + c.Assert(err, IsNil) + + ch, err := merkletrie.DiffTree(nodeA, nodeB, IsEquals) + c.Assert(err, IsNil) + c.Assert(ch, HasLen, 0) +} + +func (s *NoderSuite) TestDiffChange(c *C) { + indexA := &index.Index{ + Entries: []index.Entry{ + {Name: "bar/baz/bar", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")}, + }, + } + + indexB := &index.Index{ + Entries: []index.Entry{ + {Name: "bar/baz/foo", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")}, + }, + } + + nodeA, err := NewRootNode(indexA) + c.Assert(err, IsNil) + nodeB, err := NewRootNode(indexB) + c.Assert(err, IsNil) + + ch, err := merkletrie.DiffTree(nodeA, nodeB, IsEquals) + c.Assert(err, IsNil) + c.Assert(ch, HasLen, 2) +} + +func (s *NoderSuite) TestDiffDir(c *C) { + indexA := &index.Index{ + Entries: []index.Entry{ + {Name: "foo", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")}, + }, + } + + indexB := &index.Index{ + Entries: []index.Entry{ + {Name: "foo/bar", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")}, + }, + } + + nodeA, err := NewRootNode(indexA) + c.Assert(err, IsNil) + nodeB, err := NewRootNode(indexB) + c.Assert(err, IsNil) + + ch, err := merkletrie.DiffTree(nodeA, nodeB, IsEquals) + c.Assert(err, IsNil) + c.Assert(ch, HasLen, 2) +} + +func (s *NoderSuite) TestDiffSameRoot(c *C) { + indexA := &index.Index{ + Entries: []index.Entry{ + {Name: "foo.go", Hash: plumbing.NewHash("aab686eafeb1f44702738c8b0f24f2567c36da6d")}, + {Name: "foo/bar", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")}, + }, + } + + indexB := &index.Index{ + Entries: []index.Entry{ + {Name: "foo/bar", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")}, + {Name: "foo.go", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")}, + }, + } + + nodeA, err := NewRootNode(indexA) + c.Assert(err, IsNil) + nodeB, err := NewRootNode(indexB) + c.Assert(err, IsNil) + + ch, err := merkletrie.DiffTree(nodeA, nodeB, IsEquals) + c.Assert(err, IsNil) + c.Assert(ch, HasLen, 1) +} |