forked from winterssy/ghttp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultipart_test.go
57 lines (47 loc) · 1.05 KB
/
multipart_test.go
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
package ghttp
import (
"io"
"io/ioutil"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestFile_Read(t *testing.T) {
const (
msg = "hello world"
)
file := FileFromReader(strings.NewReader(msg)).WithFilename("testfile.txt")
n, err := io.Copy(ioutil.Discard, file)
if assert.NoError(t, err) {
assert.Equal(t, int64(len(msg)), n)
}
}
func TestOpen(t *testing.T) {
const (
fileExist = "./testdata/testfile1.txt"
fileNotExist = "./testdata/file_not_exist.txt"
)
f, err := Open(fileExist)
if assert.NoError(t, err) {
assert.NoError(t, f.Close())
}
_, err = Open(fileNotExist)
assert.Error(t, err)
}
func TestMustOpen(t *testing.T) {
const (
fileExist = "./testdata/testfile1.txt"
fileNotExist = "./testdata/file_not_exist.txt"
mime = "text/plain; charset=utf-8"
)
var f *File
if assert.NotPanics(t, func() {
f = MustOpen(fileExist).WithMIME(mime)
}) {
assert.Equal(t, "testfile1.txt", f.filename)
assert.Equal(t, mime, f.mime)
}
assert.Panics(t, func() {
f = MustOpen(fileNotExist)
})
}