forked from igungor/go-putio
-
Notifications
You must be signed in to change notification settings - Fork 8
/
events_test.go
70 lines (61 loc) · 1.39 KB
/
events_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
58
59
60
61
62
63
64
65
66
67
68
69
70
package putio
import (
"context"
"fmt"
"net/http"
"testing"
)
func TestEvents_List(t *testing.T) {
setup()
defer teardown()
fixture := `
{
"events": [
{
"created_at": "2016-06-16 11:12:57",
"file_id": 409621890,
"id": 26494492,
"transfer_name": "Ubuntu 16.04.LTS.iso",
"transfer_size": 334014003,
"type": "transfer_completed"
},
{
"created_at": "2016-06-16 05:44:24",
"file_id": 409583253,
"id": 26490777,
"transfer_name": "Big.Buck.Bunny.mkv",
"transfer_size": 613389392,
"type": "transfer_completed"
}
],
"status": "OK"
}
`
mux.HandleFunc("/v2/events/list", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprintln(w, fixture)
})
events, err := client.Events.List(context.Background())
if err != nil {
t.Error(err)
}
if len(events) != 2 {
t.Errorf("got: %v, want 2", len(events))
}
if events[0].ID != 26494492 {
t.Errorf("got: %v, want: 26494492", events[0].ID)
}
}
func TestEvents_Delete(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/events/delete", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
testHeader(t, r, "Content-Type", "application/x-www-form-urlencoded")
fmt.Fprintln(w, `{"status":"OK"}`)
})
err := client.Events.Delete(context.Background())
if err != nil {
t.Error(err)
}
}