fix tests
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Dec 8, 2015 at 22:48 UTC
a9d6575b7cc1c19663e839b5ef44cd9ba0ecb0d2
2 files changed
+60
-97
commands/files/file_test.go
+30
-75
@@ -20,36 +20,38 @@ func TestSliceFiles(t *testing.T) {
20
sf := NewSliceFile(name, name, files)
21
22
if !sf.IsDirectory() {
23
- t.Error("SliceFile should always be a directory")
23
+ t.Fatal("SliceFile should always be a directory")
24
}
25
- if n, err := sf.Read(buf); n > 0 || err != ErrNotReader {
26
- t.Error("Shouldn't be able to call `Read` on a SliceFile")
25
+
26
+ if n, err := sf.Read(buf); n > 0 || err != io.EOF {
27
+ t.Fatal("Shouldn't be able to read data from a SliceFile")
28
}
29
+
30
if err := sf.Close(); err != ErrNotReader {
29
- t.Error("Shouldn't be able to call `Close` on a SliceFile")
31
+ t.Fatal("Shouldn't be able to call `Close` on a SliceFile")
32
}
33
34
file, err := sf.NextFile()
35
if file == nil || err != nil {
34
- t.Error("Expected a file and nil error")
36
+ t.Fatal("Expected a file and nil error")
37
}
38
read, err := file.Read(buf)
39
if read != 11 || err != nil {
38
- t.Error("NextFile got a file in the wrong order")
40
+ t.Fatal("NextFile got a file in the wrong order")
41
}
42
43
file, err = sf.NextFile()
44
if file == nil || err != nil {
43
- t.Error("Expected a file and nil error")
45
+ t.Fatal("Expected a file and nil error")
46
}
47
file, err = sf.NextFile()
48
if file == nil || err != nil {
47
- t.Error("Expected a file and nil error")
49
+ t.Fatal("Expected a file and nil error")
50
}
51
52
file, err = sf.NextFile()
53
if file != nil || err != io.EOF {
52
- t.Error("Expected a nil file and io.EOF")
54
+ t.Fatal("Expected a nil file and io.EOF")
55
}
56
}
57
@@ -59,21 +61,21 @@ func TestReaderFiles(t *testing.T) {
61
buf := make([]byte, len(message))
62
63
if rf.IsDirectory() {
62
- t.Error("ReaderFile should never be a directory")
64
+ t.Fatal("ReaderFile should never be a directory")
65
}
66
file, err := rf.NextFile()
67
if file != nil || err != ErrNotDirectory {
66
- t.Error("Expected a nil file and ErrNotDirectory")
68
+ t.Fatal("Expected a nil file and ErrNotDirectory")
69
}
70
71
if n, err := rf.Read(buf); n == 0 || err != nil {
70
- t.Error("Expected to be able to read")
72
+ t.Fatal("Expected to be able to read")
73
}
74
if err := rf.Close(); err != nil {
73
- t.Error("Should be able to close")
75
+ t.Fatal("Should be able to close")
76
}
77
if n, err := rf.Read(buf); n != 0 || err != io.EOF {
76
- t.Error("Expected EOF when reading after close")
78
+ t.Fatal("Expected EOF when reading after close")
79
}
80
}
81
@@ -86,23 +88,9 @@ Some-Header: beep
88
89
beep
90
--Boundary!
89
-Content-Type: multipart/mixed; boundary=OtherBoundary
91
+Content-Type: application/x-directory
92
Content-Disposition: file; filename="dir"
93
92
---OtherBoundary
93
-Content-Type: text/plain
94
-Content-Disposition: file; filename="some/file/path"
95
-
96
-test
97
---OtherBoundary
98
-Content-Type: text/plain
99
-
100
-boop
101
---OtherBoundary
102
-Content-Type: text/plain
103
-
104
-bloop
105
---OtherBoundary--
94
--Boundary!--
95
96
`
@@ -114,81 +102,48 @@ bloop
102
// test properties of a file created from the first part
103
part, err := mpReader.NextPart()
104
if part == nil || err != nil {
117
- t.Error("Expected non-nil part, nil error")
105
+ t.Fatal("Expected non-nil part, nil error")
106
}
107
mpf, err := NewFileFromPart(part)
108
if mpf == nil || err != nil {
121
- t.Error("Expected non-nil MultipartFile, nil error")
109
+ t.Fatal("Expected non-nil MultipartFile, nil error")
110
}
111
if mpf.IsDirectory() {
124
- t.Error("Expected file to not be a directory")
112
+ t.Fatal("Expected file to not be a directory")
113
}
114
if mpf.FileName() != "name" {
127
- t.Error("Expected filename to be \"name\"")
115
+ t.Fatal("Expected filename to be \"name\"")
116
}
117
if file, err := mpf.NextFile(); file != nil || err != ErrNotDirectory {
130
- t.Error("Expected a nil file and ErrNotDirectory")
118
+ t.Fatal("Expected a nil file and ErrNotDirectory")
119
}
120
if n, err := mpf.Read(buf); n != 4 || err != nil {
133
- t.Error("Expected to be able to read 4 bytes")
121
+ t.Fatal("Expected to be able to read 4 bytes")
122
}
123
if err := mpf.Close(); err != nil {
136
- t.Error("Expected to be able to close file")
124
+ t.Fatal("Expected to be able to close file")
125
}
126
127
// test properties of file created from second part (directory)
128
part, err = mpReader.NextPart()
129
if part == nil || err != nil {
142
- t.Error("Expected non-nil part, nil error")
130
+ t.Fatal("Expected non-nil part, nil error")
131
}
132
mpf, err = NewFileFromPart(part)
133
if mpf == nil || err != nil {
146
- t.Error("Expected non-nil MultipartFile, nil error")
134
+ t.Fatal("Expected non-nil MultipartFile, nil error")
135
}
136
if !mpf.IsDirectory() {
149
- t.Error("Expected file to be a directory")
137
+ t.Fatal("Expected file to be a directory")
138
}
139
if mpf.FileName() != "dir" {
152
- t.Error("Expected filename to be \"dir\"")
140
+ t.Fatal("Expected filename to be \"dir\"")
141
}
142
if n, err := mpf.Read(buf); n > 0 || err != ErrNotReader {
155
- t.Error("Shouldn't be able to call `Read` on a directory")
143
+ t.Fatal("Shouldn't be able to call `Read` on a directory")
144
}
145
if err := mpf.Close(); err != ErrNotReader {
158
- t.Error("Shouldn't be able to call `Close` on a directory")
159
- }
160
-
161
- // test properties of first child file
162
- child, err := mpf.NextFile()
163
- if child == nil || err != nil {
164
- t.Error("Expected to be able to read a child file")
165
- }
166
- if child.IsDirectory() {
167
- t.Error("Expected file to not be a directory")
168
- }
169
- if child.FileName() != "some/file/path" {
170
- t.Error("Expected filename to be \"some/file/path\"")
146
+ t.Fatal("Shouldn't be able to call `Close` on a directory")
147
}
148
173
- // test processing files out of order
174
- child, err = mpf.NextFile()
175
- if child == nil || err != nil {
176
- t.Error("Expected to be able to read a child file")
177
- }
178
- child2, err := mpf.NextFile()
179
- if child == nil || err != nil {
180
- t.Error("Expected to be able to read a child file")
181
- }
182
- if n, err := child2.Read(buf); n != 5 || err != nil {
183
- t.Error("Expected to be able to read")
184
- }
185
- if n, err := child.Read(buf); n != 0 || err == nil {
186
- t.Error("Expected to not be able to read after advancing NextFile() past this file")
187
- }
188
-
189
- // make sure the end is handled properly
190
- child, err = mpf.NextFile()
191
- if child != nil || err == nil {
192
- t.Error("Expected NextFile to return (nil, EOF)")
193
- }
149
}
commands/http/multifilereader_test.go
+30
-22
@@ -29,78 +29,86 @@ func TestOutput(t *testing.T) {
29
30
part, err := mpReader.NextPart()
31
if part == nil || err != nil {
32
- t.Error("Expected non-nil part, nil error")
32
+ t.Fatal("Expected non-nil part, nil error")
33
}
34
mpf, err := files.NewFileFromPart(part)
35
if mpf == nil || err != nil {
36
- t.Error("Expected non-nil MultipartFile, nil error")
36
+ t.Fatal("Expected non-nil MultipartFile, nil error")
37
}
38
if mpf.IsDirectory() {
39
- t.Error("Expected file to not be a directory")
39
+ t.Fatal("Expected file to not be a directory")
40
}
41
if mpf.FileName() != "file.txt" {
42
- t.Error("Expected filename to be \"file.txt\"")
42
+ t.Fatal("Expected filename to be \"file.txt\"")
43
}
44
if n, err := mpf.Read(buf); n != len(text) || err != nil {
45
- t.Error("Expected to read from file", n, err)
45
+ t.Fatal("Expected to read from file", n, err)
46
}
47
if string(buf[:len(text)]) != text {
48
- t.Error("Data read was different than expected")
48
+ t.Fatal("Data read was different than expected")
49
}
50
51
part, err = mpReader.NextPart()
52
if part == nil || err != nil {
53
- t.Error("Expected non-nil part, nil error")
53
+ t.Fatal("Expected non-nil part, nil error")
54
}
55
mpf, err = files.NewFileFromPart(part)
56
if mpf == nil || err != nil {
57
- t.Error("Expected non-nil MultipartFile, nil error")
57
+ t.Fatal("Expected non-nil MultipartFile, nil error")
58
}
59
if !mpf.IsDirectory() {
60
- t.Error("Expected file to be a directory")
60
+ t.Fatal("Expected file to be a directory")
61
}
62
if mpf.FileName() != "boop" {
63
- t.Error("Expected filename to be \"boop\"")
63
+ t.Fatal("Expected filename to be \"boop\"")
64
}
65
66
- child, err := mpf.NextFile()
66
+ part, err = mpReader.NextPart()
67
+ if part == nil || err != nil {
68
+ t.Fatal("Expected non-nil part, nil error")
69
+ }
70
+ child, err := files.NewFileFromPart(part)
71
if child == nil || err != nil {
68
- t.Error("Expected to be able to read a child file")
72
+ t.Fatal("Expected to be able to read a child file")
73
}
74
if child.IsDirectory() {
71
- t.Error("Expected file to not be a directory")
75
+ t.Fatal("Expected file to not be a directory")
76
}
77
if child.FileName() != "boop/a.txt" {
74
- t.Error("Expected filename to be \"some/file/path\"")
78
+ t.Fatal("Expected filename to be \"some/file/path\"")
79
}
80
77
- child, err = mpf.NextFile()
81
+ part, err = mpReader.NextPart()
82
+ if part == nil || err != nil {
83
+ t.Fatal("Expected non-nil part, nil error")
84
+ }
85
+ child, err = files.NewFileFromPart(part)
86
if child == nil || err != nil {
79
- t.Error("Expected to be able to read a child file")
87
+ t.Fatal("Expected to be able to read a child file")
88
}
89
if child.IsDirectory() {
82
- t.Error("Expected file to not be a directory")
90
+ t.Fatal("Expected file to not be a directory")
91
}
92
if child.FileName() != "boop/b.txt" {
85
- t.Error("Expected filename to be \"some/file/path\"")
93
+ t.Fatal("Expected filename to be \"some/file/path\"")
94
}
95
96
child, err = mpf.NextFile()
97
if child != nil || err != io.EOF {
90
- t.Error("Expected to get (nil, io.EOF)")
98
+ t.Fatal("Expected to get (nil, io.EOF)")
99
}
100
101
part, err = mpReader.NextPart()
102
if part == nil || err != nil {
95
- t.Error("Expected non-nil part, nil error")
103
+ t.Fatal("Expected non-nil part, nil error")
104
}
105
mpf, err = files.NewFileFromPart(part)
106
if mpf == nil || err != nil {
99
- t.Error("Expected non-nil MultipartFile, nil error")
107
+ t.Fatal("Expected non-nil MultipartFile, nil error")
108
}
109
110
part, err = mpReader.NextPart()
111
if part != nil || err != io.EOF {
104
- t.Error("Expected to get (nil, io.EOF)")
112
+ t.Fatal("Expected to get (nil, io.EOF)")
113
}
114
}