Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
c6f8e7e2
Commit
c6f8e7e2
authored
Oct 03, 2018
by
Łukasz Magiera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
coreapi unixfs: test recursive adding
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
parent
8dda6957
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
21 deletions
+92
-21
core/coreapi/unixfile.go
core/coreapi/unixfile.go
+1
-2
core/coreapi/unixfs_test.go
core/coreapi/unixfs_test.go
+89
-17
core/coreunix/add.go
core/coreunix/add.go
+2
-2
No files found.
core/coreapi/unixfile.go
View file @
c6f8e7e2
...
...
@@ -163,7 +163,7 @@ func newUnixfsFile(ctx context.Context, dserv ipld.DAGService, nd ipld.Node, nam
switch
dn
:=
nd
.
(
type
)
{
case
*
dag
.
ProtoNode
:
fsn
,
err
:=
ft
.
FSNodeFromBytes
(
nd
.
Raw
Data
())
fsn
,
err
:=
ft
.
FSNodeFromBytes
(
dn
.
Data
())
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -172,7 +172,6 @@ func newUnixfsFile(ctx context.Context, dserv ipld.DAGService, nd ipld.Node, nam
}
case
*
dag
.
RawNode
:
r
:=
ioutil
.
NopCloser
(
bytes
.
NewReader
(
dn
.
RawData
()))
fi
:=
&
sizeInfo
{
size
:
int64
(
len
(
dn
.
RawData
())),
...
...
core/coreapi/unixfs_test.go
View file @
c6f8e7e2
...
...
@@ -142,11 +142,12 @@ func TestAdd(t *testing.T) {
}
cases
:=
[]
struct
{
name
string
data
func
()
files
.
File
path
string
err
string
opts
[]
options
.
UnixfsAddOption
name
string
data
func
()
files
.
File
path
string
err
string
recursive
bool
opts
[]
options
.
UnixfsAddOption
}{
// Simple cases
{
...
...
@@ -231,11 +232,45 @@ func TestAdd(t *testing.T) {
path
:
hello
,
opts
:
[]
options
.
UnixfsAddOption
{
options
.
Unixfs
.
Local
(
true
)},
},
// multi file
{
name
:
"simpleDir"
,
data
:
func
()
files
.
File
{
return
files
.
NewSliceFile
(
"t"
,
"t"
,
[]
files
.
File
{
files
.
NewReaderFile
(
"t/bar"
,
"t/bar"
,
ioutil
.
NopCloser
(
strings
.
NewReader
(
"hello2"
)),
nil
),
files
.
NewReaderFile
(
"t/foo"
,
"t/foo"
,
ioutil
.
NopCloser
(
strings
.
NewReader
(
"hello1"
)),
nil
),
})
},
recursive
:
true
,
path
:
"/ipfs/QmRKGpFfR32FVXdvJiHfo4WJ5TDYBsM1P9raAp1p6APWSp"
,
},
{
name
:
"twoLevelDir"
,
data
:
func
()
files
.
File
{
return
files
.
NewSliceFile
(
"t"
,
"t"
,
[]
files
.
File
{
files
.
NewSliceFile
(
"t/abc"
,
"t/abc"
,
[]
files
.
File
{
files
.
NewReaderFile
(
"t/abc/def"
,
"t/abc/def"
,
ioutil
.
NopCloser
(
strings
.
NewReader
(
"world"
)),
nil
),
}),
files
.
NewReaderFile
(
"t/bar"
,
"t/bar"
,
ioutil
.
NopCloser
(
strings
.
NewReader
(
"hello2"
)),
nil
),
files
.
NewReaderFile
(
"t/foo"
,
"t/foo"
,
ioutil
.
NopCloser
(
strings
.
NewReader
(
"hello1"
)),
nil
),
})
},
recursive
:
true
,
path
:
"/ipfs/QmVG2ZYCkV1S4TK8URA3a4RupBF17A8yAr4FqsRDXVJASr"
,
},
}
for
_
,
testCase
:=
range
cases
{
t
.
Run
(
testCase
.
name
,
func
(
t
*
testing
.
T
)
{
p
,
err
:=
api
.
Unixfs
()
.
Add
(
ctx
,
testCase
.
data
(),
testCase
.
opts
...
)
data
:=
testCase
.
data
()
if
testCase
.
recursive
{
data
=
files
.
NewSliceFile
(
""
,
""
,
[]
files
.
File
{
data
,
})
}
p
,
err
:=
api
.
Unixfs
()
.
Add
(
ctx
,
data
,
testCase
.
opts
...
)
if
testCase
.
err
!=
""
{
if
err
==
nil
{
t
.
Fatalf
(
"expected an error: %s"
,
testCase
.
err
)
...
...
@@ -246,27 +281,64 @@ func TestAdd(t *testing.T) {
return
}
if
err
!=
nil
{
t
.
Error
(
err
)
t
.
Fatal
(
err
)
}
if
p
.
String
()
!=
testCase
.
path
{
t
.
Errorf
(
"expected path %s, got: %s"
,
testCase
.
path
,
p
)
}
/*r, err := api.Unixfs().Cat(ctx, p)
if err != nil {
t.Fatal(err)
var
cmpFile
func
(
orig
files
.
File
,
got
files
.
File
)
cmpFile
=
func
(
orig
files
.
File
,
got
files
.
File
)
{
if
orig
.
IsDirectory
()
!=
got
.
IsDirectory
()
{
t
.
Fatal
(
"file type mismatch"
)
}
if
!
orig
.
IsDirectory
()
{
defer
orig
.
Close
()
defer
got
.
Close
()
do
,
err
:=
ioutil
.
ReadAll
(
orig
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
dg
,
err
:=
ioutil
.
ReadAll
(
got
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
bytes
.
Equal
(
do
,
dg
)
{
t
.
Fatal
(
"data not equal"
)
}
return
}
for
{
fo
,
err
:=
orig
.
NextFile
()
fg
,
err2
:=
got
.
NextFile
()
if
err
!=
nil
{
if
err
==
io
.
EOF
&&
err2
==
io
.
EOF
{
break
}
t
.
Fatal
(
err
)
}
if
err2
!=
nil
{
t
.
Fatal
(
err
)
}
cmpFile
(
fo
,
fg
)
}
}
buf := make([]byte, len(testCase.data))
_
, err =
io.ReadFull(r, buf
)
f
,
err
:
=
api
.
Unixfs
()
.
Get
(
ctx
,
p
)
if
err
!=
nil
{
t.
Error
(err)
t
.
Fatal
(
err
)
}
if string(buf) != testCase.data {
t.Fatalf("expected [%s], got [%s] [err=%s]", helloStr, string(buf), err)
}*/
cmpFile
(
testCase
.
data
(),
f
)
})
}
}
...
...
core/coreunix/add.go
View file @
c6f8e7e2
...
...
@@ -415,14 +415,14 @@ func (adder *Adder) AddAllAndPin(file files.File) (ipld.Node, error) {
// single files.File f is treated as a directory, affecting hidden file
// semantics.
for
{
f
ile
,
err
:=
file
.
NextFile
()
f
,
err
:=
file
.
NextFile
()
if
err
==
io
.
EOF
{
// Finished the list of files.
break
}
else
if
err
!=
nil
{
return
nil
,
err
}
if
err
:=
adder
.
addFile
(
f
ile
);
err
!=
nil
{
if
err
:=
adder
.
addFile
(
f
);
err
!=
nil
{
return
nil
,
err
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment