-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
file_test.go
54 lines (45 loc) · 1.2 KB
/
file_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
package backlog
import (
"fmt"
"net/http"
"path/filepath"
"reflect"
"testing"
)
func getTestUploadFile() *FileUploadResponse {
return &FileUploadResponse{
ID: Int(1),
Name: String("test.txt"),
Size: Int(8857),
}
}
func TestUploadFile(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/space/attachment", func(w http.ResponseWriter, r *http.Request) {
if _, err := fmt.Fprint(w, `{"id": 1, "name": "test.txt", "size": 8857}`); err != nil {
t.Fatal(err)
}
})
fpath := filepath.Clean(filepath.Join("testdata", "test.jpg"))
fileUploadResponse, err := client.UploadFile(fpath)
if err != nil {
t.Errorf("Unexpected error: %s", err)
return
}
want := getTestUploadFile()
if !reflect.DeepEqual(want, fileUploadResponse) {
t.Fatal(ErrIncorrectResponse)
}
}
func TestUploadFileFailed(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/space/attachment", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
})
fpath := filepath.Clean(filepath.Join("testdata", "test.jpg"))
if _, err := client.UploadFile(fpath); err == nil {
t.Fatal("expected an error but got none")
}
}