-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClientCredential_test.go
52 lines (42 loc) · 1.08 KB
/
ClientCredential_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
package oauth2go
import (
"context"
"net/http"
"net/url"
"testing"
"time"
"github.com/stretchr/testify/assert"
config "github.com/syncfuture/go/sconfig"
)
var (
_cc *ClientCredential
)
func init() {
http.DefaultClient.Transport = &http.Transport{
Proxy: func(*http.Request) (*url.URL, error) {
return url.Parse("http://localhost:8888")
},
}
cp := config.NewJsonConfigProvider()
cp.GetStruct("OAuth", &_cc)
}
func TestClientCredential_Token(t *testing.T) {
token, err := _cc.Token()
assert.NoError(t, err)
t.Log(token)
}
func TestClientCredential_Client(t *testing.T) {
httpClient := _cc.Client(context.Background())
_, err := httpClient.Get("https://di.dreamvat.com/posts/new")
assert.NoError(t, err)
t1 := _cc.AccessToken
_, err = httpClient.Get("https://di.dreamvat.com/posts/new")
assert.NoError(t, err)
t2 := _cc.AccessToken
assert.Equal(t, t1.AccessToken, t2.AccessToken)
time.Sleep(5 * time.Second)
_, err = httpClient.Get("https://di.dreamvat.com/posts/new")
assert.NoError(t, err)
t3 := _cc.AccessToken
assert.NotEqual(t, t1.AccessToken, t3.AccessToken)
}