-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclient_test.go
103 lines (90 loc) · 1.81 KB
/
client_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package apivideosdk
import (
"fmt"
"log"
"net/http"
"net/http/httptest"
"net/url"
"os"
"testing"
)
var (
mux *http.ServeMux
client *Client
server *httptest.Server
)
var paginationJSON = `{
"currentPage": 1,
"pageSize": 25,
"pagesTotal": 1,
"itemsTotal": 11,
"currentPageItems": 11,
"links": [
{
"rel": "self",
"uri": "https://ws.api.video"
},
{
"rel": "first",
"uri": "https://ws.api.video"
},
{
"rel": "last",
"uri": "https://ws.api.video"
}
]
}`
var paginationStruct = Pagination{
CurrentPage: PtrInt32(1),
PageSize: PtrInt32(25),
PagesTotal: PtrInt32(1),
ItemsTotal: PtrInt32(11),
CurrentPageItems: PtrInt32(11),
Links: []PaginationLink{
{
Rel: PtrString("self"),
Uri: PtrString("https://ws.api.video"),
},
{
Rel: PtrString("first"),
Uri: PtrString("https://ws.api.video"),
},
{
Rel: PtrString("last"),
Uri: PtrString("https://ws.api.video"),
},
},
}
func setup() {
mux = http.NewServeMux()
server = httptest.NewServer(mux)
mux.HandleFunc("/auth/api-key", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `{
"token_type": "Bearer",
"expires_in": 3600,
"access_token": "fakeToken",
"refresh_token": "fakeToken"
}`)
})
client = ClientBuilder("apiKey").Build()
url, _ := url.Parse(server.URL)
client.BaseURL = url
}
func teardown() {
server.Close()
}
func testMethod(t *testing.T, r *http.Request, expected string) {
if expected != r.Method {
t.Errorf("Request method = %v, expected %v", r.Method, expected)
}
}
func createTempFile(filename string, size int64) *os.File {
f, err := os.Create(filename)
if err != nil {
log.Fatal(err)
}
if err := f.Truncate(size); err != nil {
log.Fatal(err)
}
return f
}