forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileupload_test.go
56 lines (46 loc) · 1.16 KB
/
fileupload_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
package stripe
import (
"encoding/json"
"os"
"testing"
assert "github.com/stretchr/testify/require"
)
func TestFileUpload_UnmarshalJSON(t *testing.T) {
// Unmarshals from a JSON string
{
var v FileUpload
err := json.Unmarshal([]byte(`"file_123"`), &v)
assert.NoError(t, err)
assert.Equal(t, "file_123", v.ID)
}
// Unmarshals from a JSON object
{
v := FileUpload{ID: "file_123"}
data, err := json.Marshal(&v)
assert.NoError(t, err)
err = json.Unmarshal(data, &v)
assert.NoError(t, err)
assert.Equal(t, "file_123", v.ID)
}
}
func TestFileUploadParams_GetBody(t *testing.T) {
f, err := os.Open("fileupload/test_data.pdf")
if err != nil {
t.Errorf("Unable to open test file upload file %v\n", err)
}
p := &FileUploadParams{
FileReader: f,
Filename: String(f.Name()),
}
buffer, boundary, err := p.GetBody()
assert.NoError(t, err)
assert.NotEqual(t, 0, buffer.Len())
// Copied from the check performed by `multipart.Writer.SetBoundary`. A
// very basic check that the string we got back indeed looks like a
// boundary.
//
// rfc2046#section-5.1.1
if len(boundary) < 1 || len(boundary) > 70 {
t.Errorf("invalid boundary length")
}
}