-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload_test.go
45 lines (37 loc) · 1.15 KB
/
upload_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
package apiclient
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
"fmt"
"net/http"
)
func TestUpload(t *testing.T) {
// Create the test server and shut it down when the test ends
c, teardown := setupTestServer()
defer teardown()
// Add restapi endpoint to retrieve a document
mux.HandleFunc("/folder/1/document", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
// ... return the JSON
fmt.Fprint(w, fixture("upload.json"))
})
c.Login("admin", "admin")
extraParams := map[string]string{
"name": "Document uploaded with go api-client",
"keywords": "go restapi",
"filename": "upload.txt",
}
file, err := os.Open("upload.go")
if err != nil {
return
}
defer file.Close()
res, err := c.Upload(file, extraParams, 1)
assert.Nil(t, err, "expecting nil error")
assert.NotNil(t, res, "expecting non-nil result")
if res != nil {
assert.Equal(t, extraParams["name"], res.Data.Name, "expecting name of uploaded document")
}
}