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-cmds
Commits
0b97387e
Commit
0b97387e
authored
Dec 28, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add more tests for multipart parsing
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
734fd1c5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
0 deletions
+54
-0
files/file_test.go
files/file_test.go
+54
-0
No files found.
files/file_test.go
View file @
0b97387e
...
@@ -91,6 +91,16 @@ beep
...
@@ -91,6 +91,16 @@ beep
Content-Type: application/x-directory
Content-Type: application/x-directory
Content-Disposition: file; filename="dir"
Content-Disposition: file; filename="dir"
--Boundary!
Content-Type: text/plain
Content-Disposition: file; filename="dir/nested"
some content
--Boundary!
Content-Type: application/symlink
Content-Disposition: file; filename="dir/simlynk"
anotherfile
--Boundary!--
--Boundary!--
`
`
...
@@ -146,4 +156,48 @@ Content-Disposition: file; filename="dir"
...
@@ -146,4 +156,48 @@ Content-Disposition: file; filename="dir"
t
.
Fatal
(
"Shouldn't be able to call `Close` on a directory"
)
t
.
Fatal
(
"Shouldn't be able to call `Close` on a directory"
)
}
}
// test properties of file created from third part (nested file)
part
,
err
=
mpReader
.
NextPart
()
if
part
==
nil
||
err
!=
nil
{
t
.
Fatal
(
"Expected non-nil part, nil error"
)
}
mpf
,
err
=
NewFileFromPart
(
part
)
if
mpf
==
nil
||
err
!=
nil
{
t
.
Fatal
(
"Expected non-nil MultipartFile, nil error"
)
}
if
mpf
.
IsDirectory
()
{
t
.
Fatal
(
"Expected file, got directory"
)
}
if
mpf
.
FileName
()
!=
"dir/nested"
{
t
.
Fatalf
(
"Expected filename to be
\"
nested
\"
, got %s"
,
mpf
.
FileName
())
}
if
n
,
err
:=
mpf
.
Read
(
buf
);
n
!=
12
||
err
!=
nil
{
t
.
Fatalf
(
"expected to be able to read 12 bytes from file: %s (got %d)"
,
err
,
n
)
}
if
err
:=
mpf
.
Close
();
err
!=
nil
{
t
.
Fatal
(
"should be able to close file: %s"
,
err
)
}
// test properties of symlink created from fourth part (symlink)
part
,
err
=
mpReader
.
NextPart
()
if
part
==
nil
||
err
!=
nil
{
t
.
Fatal
(
"Expected non-nil part, nil error"
)
}
mpf
,
err
=
NewFileFromPart
(
part
)
if
mpf
==
nil
||
err
!=
nil
{
t
.
Fatal
(
"Expected non-nil MultipartFile, nil error"
)
}
if
mpf
.
IsDirectory
()
{
t
.
Fatal
(
"Expected file to be a symlink"
)
}
if
mpf
.
FileName
()
!=
"dir/simlynk"
{
t
.
Fatal
(
"Expected filename to be
\"
dir/simlynk
\"
"
)
}
slink
,
ok
:=
mpf
.
(
*
Symlink
)
if
!
ok
{
t
.
Fatalf
(
"expected file to be a symlink"
)
}
if
slink
.
Target
!=
"anotherfile"
{
t
.
Fatal
(
"expected link to point to anotherfile"
)
}
}
}
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