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
c14bd98f
Commit
c14bd98f
authored
Nov 17, 2014
by
Matt Bell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands/http: Added MultiFileReader test
parent
c904e6c4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
105 additions
and
0 deletions
+105
-0
commands/http/multifilereader_test.go
commands/http/multifilereader_test.go
+105
-0
No files found.
commands/http/multifilereader_test.go
0 → 100644
View file @
c14bd98f
package
http
import
(
"io"
"mime/multipart"
"strings"
"testing"
cmds
"github.com/jbenet/go-ipfs/commands"
)
func
TestOutput
(
t
*
testing
.
T
)
{
text
:=
"Some text! :)"
files
:=
[]
cmds
.
File
{
&
cmds
.
ReaderFile
{
"file.txt"
,
strings
.
NewReader
(
text
)},
&
cmds
.
SliceFile
{
"boop"
,
[]
cmds
.
File
{
&
cmds
.
ReaderFile
{
"boop/a.txt"
,
strings
.
NewReader
(
"bleep"
)},
&
cmds
.
ReaderFile
{
"boop/b.txt"
,
strings
.
NewReader
(
"bloop"
)},
}},
&
cmds
.
ReaderFile
{
"beep.txt"
,
strings
.
NewReader
(
"beep"
)},
}
sf
:=
&
cmds
.
SliceFile
{
""
,
files
}
buf
:=
make
([]
byte
,
20
)
// testing output by reading it with the go stdlib "mime/multipart" Reader
mfr
:=
NewMultiFileReader
(
sf
,
true
)
mpReader
:=
multipart
.
NewReader
(
mfr
,
mfr
.
Boundary
())
part
,
err
:=
mpReader
.
NextPart
()
if
part
==
nil
||
err
!=
nil
{
t
.
Error
(
"Expected non-nil part, nil error"
)
}
mpf
,
err
:=
cmds
.
NewFileFromPart
(
part
)
if
mpf
==
nil
||
err
!=
nil
{
t
.
Error
(
"Expected non-nil MultipartFile, nil error"
)
}
if
mpf
.
IsDirectory
()
{
t
.
Error
(
"Expected file to not be a directory"
)
}
if
mpf
.
FileName
()
!=
"file.txt"
{
t
.
Error
(
"Expected filename to be
\"
file.txt
\"
"
)
}
if
n
,
err
:=
mpf
.
Read
(
buf
);
n
!=
len
(
text
)
||
err
!=
nil
{
t
.
Error
(
"Expected to read from file"
,
n
,
err
)
}
if
string
(
buf
[
:
len
(
text
)])
!=
text
{
t
.
Error
(
"Data read was different than expected"
)
}
part
,
err
=
mpReader
.
NextPart
()
if
part
==
nil
||
err
!=
nil
{
t
.
Error
(
"Expected non-nil part, nil error"
)
}
mpf
,
err
=
cmds
.
NewFileFromPart
(
part
)
if
mpf
==
nil
||
err
!=
nil
{
t
.
Error
(
"Expected non-nil MultipartFile, nil error"
)
}
if
!
mpf
.
IsDirectory
()
{
t
.
Error
(
"Expected file to be a directory"
)
}
if
mpf
.
FileName
()
!=
"boop"
{
t
.
Error
(
"Expected filename to be
\"
boop
\"
"
)
}
child
,
err
:=
mpf
.
NextFile
()
if
child
==
nil
||
err
!=
nil
{
t
.
Error
(
"Expected to be able to read a child file"
)
}
if
child
.
IsDirectory
()
{
t
.
Error
(
"Expected file to not be a directory"
)
}
if
child
.
FileName
()
!=
"boop/a.txt"
{
t
.
Error
(
"Expected filename to be
\"
some/file/path
\"
"
)
}
child
,
err
=
mpf
.
NextFile
()
if
child
==
nil
||
err
!=
nil
{
t
.
Error
(
"Expected to be able to read a child file"
)
}
if
child
.
IsDirectory
()
{
t
.
Error
(
"Expected file to not be a directory"
)
}
if
child
.
FileName
()
!=
"boop/b.txt"
{
t
.
Error
(
"Expected filename to be
\"
some/file/path
\"
"
)
}
child
,
err
=
mpf
.
NextFile
()
if
child
!=
nil
||
err
!=
io
.
EOF
{
t
.
Error
(
"Expected to get (nil, io.EOF)"
)
}
part
,
err
=
mpReader
.
NextPart
()
if
part
==
nil
||
err
!=
nil
{
t
.
Error
(
"Expected non-nil part, nil error"
)
}
mpf
,
err
=
cmds
.
NewFileFromPart
(
part
)
if
mpf
==
nil
||
err
!=
nil
{
t
.
Error
(
"Expected non-nil MultipartFile, nil error"
)
}
part
,
err
=
mpReader
.
NextPart
()
if
part
!=
nil
||
err
!=
io
.
EOF
{
t
.
Error
(
"Expected to get (nil, io.EOF)"
)
}
}
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