From b22e7fa5a7bcd5492aaf9ec11f57cb4322eb8cb4 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Tue, 18 Jul 2017 23:12:09 +0200 Subject: utils: merkletrie fix test on windows --- utils/merkletrie/index/node_test.go | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'utils/merkletrie/index') diff --git a/utils/merkletrie/index/node_test.go b/utils/merkletrie/index/node_test.go index 00da8da..283ca74 100644 --- a/utils/merkletrie/index/node_test.go +++ b/utils/merkletrie/index/node_test.go @@ -2,6 +2,7 @@ package index import ( "bytes" + "path/filepath" "testing" . "gopkg.in/check.v1" @@ -43,15 +44,17 @@ func (s *NoderSuite) TestDiff(c *C) { func (s *NoderSuite) TestDiffChange(c *C) { indexA := &index.Index{ - Entries: []*index.Entry{ - {Name: "bar/baz/bar", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")}, - }, + Entries: []*index.Entry{{ + Name: filepath.Join("bar", "baz", "bar"), + Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d"), + }}, } indexB := &index.Index{ - Entries: []*index.Entry{ - {Name: "bar/baz/foo", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")}, - }, + Entries: []*index.Entry{{ + Name: filepath.Join("bar", "baz", "foo"), + Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d"), + }}, } ch, err := merkletrie.DiffTree(NewRootNode(indexA), NewRootNode(indexB), isEquals) @@ -61,15 +64,17 @@ func (s *NoderSuite) TestDiffChange(c *C) { func (s *NoderSuite) TestDiffDir(c *C) { indexA := &index.Index{ - Entries: []*index.Entry{ - {Name: "foo", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")}, - }, + Entries: []*index.Entry{{ + Name: "foo", + Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d"), + }}, } indexB := &index.Index{ - Entries: []*index.Entry{ - {Name: "foo/bar", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")}, - }, + Entries: []*index.Entry{{ + Name: filepath.Join("foo", "bar"), + Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d"), + }}, } ch, err := merkletrie.DiffTree(NewRootNode(indexA), NewRootNode(indexB), isEquals) -- cgit From 8210c82bcd6ff7f7c66b8f5fc1be00307fe59c42 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Wed, 19 Jul 2017 01:26:16 +0200 Subject: utils: merkletrie filesystem based on path, and not in filepath --- utils/merkletrie/index/node.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'utils/merkletrie/index') diff --git a/utils/merkletrie/index/node.go b/utils/merkletrie/index/node.go index 859c097..9622622 100644 --- a/utils/merkletrie/index/node.go +++ b/utils/merkletrie/index/node.go @@ -1,7 +1,7 @@ package index import ( - "path/filepath" + "path" "strings" "gopkg.in/src-d/go-git.v4/plumbing/format/index" @@ -28,19 +28,19 @@ func NewRootNode(idx *index.Index) noder.Noder { m := map[string]*node{rootNode: {isDir: true}} for _, e := range idx.Entries { - parts := strings.Split(e.Name, string(filepath.Separator)) + parts := strings.Split(e.Name, string("/")) - var path string + var fullpath string for _, part := range parts { - parent := path - path = filepath.Join(path, part) + parent := fullpath + fullpath = path.Join(fullpath, part) - if _, ok := m[path]; ok { + if _, ok := m[fullpath]; ok { continue } - n := &node{path: path} - if path == e.Name { + n := &node{path: fullpath} + if fullpath == e.Name { n.entry = e } else { n.isDir = true @@ -74,7 +74,7 @@ func (n *node) Hash() []byte { } func (n *node) Name() string { - return filepath.Base(n.path) + return path.Base(n.path) } func (n *node) IsDir() bool { -- cgit