-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathfile_upload_test.go
More file actions
66 lines (51 loc) · 1.27 KB
/
file_upload_test.go
File metadata and controls
66 lines (51 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package grequests
import (
"fmt"
"testing"
"github.com/stretchr/testify/suite"
)
type FileUploadSuite struct {
suite.Suite
}
func (s *FileUploadSuite) TestErrorOpenFile() {
fd, err := FileUploadFromDisk("I am Not A File")
if err == nil {
s.Fail("We are not getting an error back from our non existent file: ")
}
if fd != nil {
s.Fail("We actually got back a pointer: ", fd)
}
}
func (s *FileUploadSuite) TestGLOBFiles() {
fd, err := FileUploadFromGlob("testdata/*")
if err != nil {
s.Fail("Got an invalid GLOB: %v", err)
}
if len(fd) != 2 {
s.Fail("Some how we have more than two files in our glob %v %v", len(fd), fd)
}
}
func (s *FileUploadSuite) TestInvalidGlob() {
if _, err := FileUploadFromGlob("[-]"); err == nil {
s.Fail("Somehow the glob worked")
}
}
func (s *FileUploadSuite) TestNoGlobFiles() {
if _, err := FileUploadFromGlob("notapath"); err == nil {
s.Fail("Somehow got a valid GLOB")
}
}
func (s *FileUploadSuite) TestGlobWithDir() {
fd, err := FileUploadFromGlob("*test*")
if err != nil {
s.Fail("Glob failed %v", err)
}
for _, f := range fd {
if f.FileName == "test_files" {
s.Fail(fmt.Sprintf("%v is a dir (which cannot be uploaded)", f))
}
}
}
func TestFileUploadSuite(t *testing.T) {
suite.Run(t, new(FileUploadSuite))
}