Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
kubo_final
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anastasiia Chirikova
kubo_final
Commits
a9d6575b
Commit
a9d6575b
authored
Dec 9, 2015
by
Jeromy Johnson
Browse files
Options
Downloads
Patches
Plain Diff
fix tests
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
d892661f
Branches
Branches containing commit
No related tags found
1 merge request
!1
New
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
commands/files/file_test.go
+30
-75
30 additions, 75 deletions
commands/files/file_test.go
commands/http/multifilereader_test.go
+30
-22
30 additions, 22 deletions
commands/http/multifilereader_test.go
with
60 additions
and
97 deletions
commands/files/file_test.go
+
30
−
75
View file @
a9d6575b
...
...
@@ -20,36 +20,38 @@ func TestSliceFiles(t *testing.T) {
sf
:=
NewSliceFile
(
name
,
name
,
files
)
if
!
sf
.
IsDirectory
()
{
t
.
Error
(
"SliceFile should always be a directory"
)
t
.
Fatal
(
"SliceFile should always be a directory"
)
}
if
n
,
err
:=
sf
.
Read
(
buf
);
n
>
0
||
err
!=
ErrNotReader
{
t
.
Error
(
"Shouldn't be able to call `Read` on a SliceFile"
)
if
n
,
err
:=
sf
.
Read
(
buf
);
n
>
0
||
err
!=
io
.
EOF
{
t
.
Fatal
(
"Shouldn't be able to read data from a SliceFile"
)
}
if
err
:=
sf
.
Close
();
err
!=
ErrNotReader
{
t
.
Error
(
"Shouldn't be able to call `Close` on a SliceFile"
)
t
.
Fatal
(
"Shouldn't be able to call `Close` on a SliceFile"
)
}
file
,
err
:=
sf
.
NextFile
()
if
file
==
nil
||
err
!=
nil
{
t
.
Error
(
"Expected a file and nil error"
)
t
.
Fatal
(
"Expected a file and nil error"
)
}
read
,
err
:=
file
.
Read
(
buf
)
if
read
!=
11
||
err
!=
nil
{
t
.
Error
(
"NextFile got a file in the wrong order"
)
t
.
Fatal
(
"NextFile got a file in the wrong order"
)
}
file
,
err
=
sf
.
NextFile
()
if
file
==
nil
||
err
!=
nil
{
t
.
Error
(
"Expected a file and nil error"
)
t
.
Fatal
(
"Expected a file and nil error"
)
}
file
,
err
=
sf
.
NextFile
()
if
file
==
nil
||
err
!=
nil
{
t
.
Error
(
"Expected a file and nil error"
)
t
.
Fatal
(
"Expected a file and nil error"
)
}
file
,
err
=
sf
.
NextFile
()
if
file
!=
nil
||
err
!=
io
.
EOF
{
t
.
Error
(
"Expected a nil file and io.EOF"
)
t
.
Fatal
(
"Expected a nil file and io.EOF"
)
}
}
...
...
@@ -59,21 +61,21 @@ func TestReaderFiles(t *testing.T) {
buf
:=
make
([]
byte
,
len
(
message
))
if
rf
.
IsDirectory
()
{
t
.
Error
(
"ReaderFile should never be a directory"
)
t
.
Fatal
(
"ReaderFile should never be a directory"
)
}
file
,
err
:=
rf
.
NextFile
()
if
file
!=
nil
||
err
!=
ErrNotDirectory
{
t
.
Error
(
"Expected a nil file and ErrNotDirectory"
)
t
.
Fatal
(
"Expected a nil file and ErrNotDirectory"
)
}
if
n
,
err
:=
rf
.
Read
(
buf
);
n
==
0
||
err
!=
nil
{
t
.
Error
(
"Expected to be able to read"
)
t
.
Fatal
(
"Expected to be able to read"
)
}
if
err
:=
rf
.
Close
();
err
!=
nil
{
t
.
Error
(
"Should be able to close"
)
t
.
Fatal
(
"Should be able to close"
)
}
if
n
,
err
:=
rf
.
Read
(
buf
);
n
!=
0
||
err
!=
io
.
EOF
{
t
.
Error
(
"Expected EOF when reading after close"
)
t
.
Fatal
(
"Expected EOF when reading after close"
)
}
}
...
...
@@ -86,23 +88,9 @@ Some-Header: beep
beep
--Boundary!
Content-Type:
multipart/mixed; boundary=OtherBounda
ry
Content-Type:
application/x-directo
ry
Content-Disposition: file; filename="dir"
--OtherBoundary
Content-Type: text/plain
Content-Disposition: file; filename="some/file/path"
test
--OtherBoundary
Content-Type: text/plain
boop
--OtherBoundary
Content-Type: text/plain
bloop
--OtherBoundary--
--Boundary!--
`
...
...
@@ -114,81 +102,48 @@ bloop
// test properties of a file created from the first part
part
,
err
:=
mpReader
.
NextPart
()
if
part
==
nil
||
err
!=
nil
{
t
.
Error
(
"Expected non-nil part, nil error"
)
t
.
Fatal
(
"Expected non-nil part, nil error"
)
}
mpf
,
err
:=
NewFileFromPart
(
part
)
if
mpf
==
nil
||
err
!=
nil
{
t
.
Error
(
"Expected non-nil MultipartFile, nil error"
)
t
.
Fatal
(
"Expected non-nil MultipartFile, nil error"
)
}
if
mpf
.
IsDirectory
()
{
t
.
Error
(
"Expected file to not be a directory"
)
t
.
Fatal
(
"Expected file to not be a directory"
)
}
if
mpf
.
FileName
()
!=
"name"
{
t
.
Error
(
"Expected filename to be
\"
name
\"
"
)
t
.
Fatal
(
"Expected filename to be
\"
name
\"
"
)
}
if
file
,
err
:=
mpf
.
NextFile
();
file
!=
nil
||
err
!=
ErrNotDirectory
{
t
.
Error
(
"Expected a nil file and ErrNotDirectory"
)
t
.
Fatal
(
"Expected a nil file and ErrNotDirectory"
)
}
if
n
,
err
:=
mpf
.
Read
(
buf
);
n
!=
4
||
err
!=
nil
{
t
.
Error
(
"Expected to be able to read 4 bytes"
)
t
.
Fatal
(
"Expected to be able to read 4 bytes"
)
}
if
err
:=
mpf
.
Close
();
err
!=
nil
{
t
.
Error
(
"Expected to be able to close file"
)
t
.
Fatal
(
"Expected to be able to close file"
)
}
// test properties of file created from second part (directory)
part
,
err
=
mpReader
.
NextPart
()
if
part
==
nil
||
err
!=
nil
{
t
.
Error
(
"Expected non-nil part, nil error"
)
t
.
Fatal
(
"Expected non-nil part, nil error"
)
}
mpf
,
err
=
NewFileFromPart
(
part
)
if
mpf
==
nil
||
err
!=
nil
{
t
.
Error
(
"Expected non-nil MultipartFile, nil error"
)
t
.
Fatal
(
"Expected non-nil MultipartFile, nil error"
)
}
if
!
mpf
.
IsDirectory
()
{
t
.
Error
(
"Expected file to be a directory"
)
t
.
Fatal
(
"Expected file to be a directory"
)
}
if
mpf
.
FileName
()
!=
"dir"
{
t
.
Error
(
"Expected filename to be
\"
dir
\"
"
)
t
.
Fatal
(
"Expected filename to be
\"
dir
\"
"
)
}
if
n
,
err
:=
mpf
.
Read
(
buf
);
n
>
0
||
err
!=
ErrNotReader
{
t
.
Error
(
"Shouldn't be able to call `Read` on a directory"
)
t
.
Fatal
(
"Shouldn't be able to call `Read` on a directory"
)
}
if
err
:=
mpf
.
Close
();
err
!=
ErrNotReader
{
t
.
Error
(
"Shouldn't be able to call `Close` on a directory"
)
}
// test properties of first child file
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
()
!=
"some/file/path"
{
t
.
Error
(
"Expected filename to be
\"
some/file/path
\"
"
)
t
.
Fatal
(
"Shouldn't be able to call `Close` on a directory"
)
}
// test processing files out of order
child
,
err
=
mpf
.
NextFile
()
if
child
==
nil
||
err
!=
nil
{
t
.
Error
(
"Expected to be able to read a child file"
)
}
child2
,
err
:=
mpf
.
NextFile
()
if
child
==
nil
||
err
!=
nil
{
t
.
Error
(
"Expected to be able to read a child file"
)
}
if
n
,
err
:=
child2
.
Read
(
buf
);
n
!=
5
||
err
!=
nil
{
t
.
Error
(
"Expected to be able to read"
)
}
if
n
,
err
:=
child
.
Read
(
buf
);
n
!=
0
||
err
==
nil
{
t
.
Error
(
"Expected to not be able to read after advancing NextFile() past this file"
)
}
// make sure the end is handled properly
child
,
err
=
mpf
.
NextFile
()
if
child
!=
nil
||
err
==
nil
{
t
.
Error
(
"Expected NextFile to return (nil, EOF)"
)
}
}
This diff is collapsed.
Click to expand it.
commands/http/multifilereader_test.go
+
30
−
22
View file @
a9d6575b
...
...
@@ -29,78 +29,86 @@ func TestOutput(t *testing.T) {
part
,
err
:=
mpReader
.
NextPart
()
if
part
==
nil
||
err
!=
nil
{
t
.
Error
(
"Expected non-nil part, nil error"
)
t
.
Fatal
(
"Expected non-nil part, nil error"
)
}
mpf
,
err
:=
files
.
NewFileFromPart
(
part
)
if
mpf
==
nil
||
err
!=
nil
{
t
.
Error
(
"Expected non-nil MultipartFile, nil error"
)
t
.
Fatal
(
"Expected non-nil MultipartFile, nil error"
)
}
if
mpf
.
IsDirectory
()
{
t
.
Error
(
"Expected file to not be a directory"
)
t
.
Fatal
(
"Expected file to not be a directory"
)
}
if
mpf
.
FileName
()
!=
"file.txt"
{
t
.
Error
(
"Expected filename to be
\"
file.txt
\"
"
)
t
.
Fatal
(
"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
)
t
.
Fatal
(
"Expected to read from file"
,
n
,
err
)
}
if
string
(
buf
[
:
len
(
text
)])
!=
text
{
t
.
Error
(
"Data read was different than expected"
)
t
.
Fatal
(
"Data read was different than expected"
)
}
part
,
err
=
mpReader
.
NextPart
()
if
part
==
nil
||
err
!=
nil
{
t
.
Error
(
"Expected non-nil part, nil error"
)
t
.
Fatal
(
"Expected non-nil part, nil error"
)
}
mpf
,
err
=
files
.
NewFileFromPart
(
part
)
if
mpf
==
nil
||
err
!=
nil
{
t
.
Error
(
"Expected non-nil MultipartFile, nil error"
)
t
.
Fatal
(
"Expected non-nil MultipartFile, nil error"
)
}
if
!
mpf
.
IsDirectory
()
{
t
.
Error
(
"Expected file to be a directory"
)
t
.
Fatal
(
"Expected file to be a directory"
)
}
if
mpf
.
FileName
()
!=
"boop"
{
t
.
Error
(
"Expected filename to be
\"
boop
\"
"
)
t
.
Fatal
(
"Expected filename to be
\"
boop
\"
"
)
}
child
,
err
:=
mpf
.
NextFile
()
part
,
err
=
mpReader
.
NextPart
()
if
part
==
nil
||
err
!=
nil
{
t
.
Fatal
(
"Expected non-nil part, nil error"
)
}
child
,
err
:=
files
.
NewFileFromPart
(
part
)
if
child
==
nil
||
err
!=
nil
{
t
.
Error
(
"Expected to be able to read a child file"
)
t
.
Fatal
(
"Expected to be able to read a child file"
)
}
if
child
.
IsDirectory
()
{
t
.
Error
(
"Expected file to not be a directory"
)
t
.
Fatal
(
"Expected file to not be a directory"
)
}
if
child
.
FileName
()
!=
"boop/a.txt"
{
t
.
Error
(
"Expected filename to be
\"
some/file/path
\"
"
)
t
.
Fatal
(
"Expected filename to be
\"
some/file/path
\"
"
)
}
child
,
err
=
mpf
.
NextFile
()
part
,
err
=
mpReader
.
NextPart
()
if
part
==
nil
||
err
!=
nil
{
t
.
Fatal
(
"Expected non-nil part, nil error"
)
}
child
,
err
=
files
.
NewFileFromPart
(
part
)
if
child
==
nil
||
err
!=
nil
{
t
.
Error
(
"Expected to be able to read a child file"
)
t
.
Fatal
(
"Expected to be able to read a child file"
)
}
if
child
.
IsDirectory
()
{
t
.
Error
(
"Expected file to not be a directory"
)
t
.
Fatal
(
"Expected file to not be a directory"
)
}
if
child
.
FileName
()
!=
"boop/b.txt"
{
t
.
Error
(
"Expected filename to be
\"
some/file/path
\"
"
)
t
.
Fatal
(
"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)"
)
t
.
Fatal
(
"Expected to get (nil, io.EOF)"
)
}
part
,
err
=
mpReader
.
NextPart
()
if
part
==
nil
||
err
!=
nil
{
t
.
Error
(
"Expected non-nil part, nil error"
)
t
.
Fatal
(
"Expected non-nil part, nil error"
)
}
mpf
,
err
=
files
.
NewFileFromPart
(
part
)
if
mpf
==
nil
||
err
!=
nil
{
t
.
Error
(
"Expected non-nil MultipartFile, nil error"
)
t
.
Fatal
(
"Expected non-nil MultipartFile, nil error"
)
}
part
,
err
=
mpReader
.
NextPart
()
if
part
!=
nil
||
err
!=
io
.
EOF
{
t
.
Error
(
"Expected to get (nil, io.EOF)"
)
t
.
Fatal
(
"Expected to get (nil, io.EOF)"
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment