From b5da4e98571b02dc106de4f9b2cb2a298489f1b1 Mon Sep 17 00:00:00 2001 From: Alberto Cortés Date: Wed, 22 Feb 2017 16:45:46 +0100 Subject: Fix issue 275 (edited) (#276) Fix #275 . It was not possible to write a test for this issue as the original fsnoder didn't support filenames with length > 1. Therefore this patch has 3 commits: add support for long filenames in fsnoder. add a test case for the issue using the new long filenames from step 1. fix the issue by comparing paths level by level instead of lexigographically over the whole path. --- utils/merkletrie/internal/fsnoder/new_test.go | 43 +++++++++++++++++++-------- 1 file changed, 30 insertions(+), 13 deletions(-) (limited to 'utils/merkletrie/internal/fsnoder/new_test.go') diff --git a/utils/merkletrie/internal/fsnoder/new_test.go b/utils/merkletrie/internal/fsnoder/new_test.go index 3e209a9..20f028b 100644 --- a/utils/merkletrie/internal/fsnoder/new_test.go +++ b/utils/merkletrie/internal/fsnoder/new_test.go @@ -40,15 +40,8 @@ func (s *FSNoderSuite) TestUnnamedInnerFails(c *C) { c.Assert(err, Not(IsNil)) } -func (s *FSNoderSuite) TestMalformedInnerName(c *C) { - _, err := New("(ab<>)") - c.Assert(err, Not(IsNil)) -} - func (s *FSNoderSuite) TestMalformedFile(c *C) { - _, err := New("(a<12>)") - c.Assert(err, Not(IsNil)) - _, err = New("(4<>)") + _, err := New("(4<>)") c.Assert(err, Not(IsNil)) _, err = New("(4<1>)") c.Assert(err, Not(IsNil)) @@ -66,13 +59,11 @@ func (s *FSNoderSuite) TestMalformedFile(c *C) { _, err = decodeFile([]byte("a<1?")) c.Assert(err, Not(IsNil)) - _, err = decodeEmptyFile([]byte("a<1>")) + _, err = decodeFile([]byte("a?>")) c.Assert(err, Not(IsNil)) - _, err = decodeEmptyFile([]byte("a?>")) + _, err = decodeFile([]byte("1<>")) c.Assert(err, Not(IsNil)) - _, err = decodeEmptyFile([]byte("1<>")) - c.Assert(err, Not(IsNil)) - _, err = decodeEmptyFile([]byte("a))" + + a1, err := newFile("a", "12") + c.Assert(err, IsNil) + A, err := newDir("A", []noder.Noder{a1}) + c.Assert(err, IsNil) + expected, err := newDir("", []noder.Noder{A}) + c.Assert(err, IsNil) + + check(c, input, expected) +} + +func (s *FSNoderSuite) TestDirWithFileLongName(c *C) { + input := "(A(abc<12>))" + + a1, err := newFile("abc", "12") + c.Assert(err, IsNil) + A, err := newDir("A", []noder.Noder{a1}) + c.Assert(err, IsNil) + expected, err := newDir("", []noder.Noder{A}) + c.Assert(err, IsNil) + + check(c, input, expected) +} + func (s *FSNoderSuite) TestDirWithFile(c *C) { input := "(A(a<1>))" -- cgit