-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsuite_test.go
55 lines (44 loc) · 1.03 KB
/
suite_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
/*
* Go OAuth2 Client
*
* MIT License
*
* Copyright (c) 2015 Globo.com
*/
package galf
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
"gopkg.in/check.v1"
)
func TestAlf(t *testing.T) {
check.TestingT(t)
}
func newTestServerCustom(handle func(w http.ResponseWriter, r *http.Request)) *httptest.Server {
handlerWrapper := func(w http.ResponseWriter, r *http.Request) {
println("Url: " + r.RequestURI)
handle(w, r)
}
return httptest.NewServer(http.HandlerFunc(handlerWrapper))
}
func newTestServerToken(expireIn ...int) *httptest.Server {
expire := 15
if len(expireIn) > 0 {
expire = expireIn[0]
}
ts := newTestServerCustom(handleToken(expire))
tm := NewTokenManager(
ts.URL+"/token",
"ClientId",
"ClientSecret",
)
SetDefaultTokenManager(tm)
return ts
}
func handleToken(expire int) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, fmt.Sprintf(`{"access_token": "nonenoenoe", "token_type": "bearer", "expires_in": %d}`, expire))
}
}