-
Notifications
You must be signed in to change notification settings - Fork 3
/
token_test.go
52 lines (41 loc) · 1.11 KB
/
token_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
/*
* Go OAuth2 Client
*
* MIT License
*
* Copyright (c) 2015 Globo.com
*/
package galf
import (
"strings"
"time"
"gopkg.in/check.v1"
)
type tokenSuite struct{}
var _ = check.Suite(&tokenSuite{})
func (s *tokenSuite) TestCreateNewToken(c *check.C) {
bodyToken := strings.NewReader(
`{"access_token": "nonenone", "token_type": "bearer", "expires_in": 15}`,
)
token, err := newToken(bodyToken)
c.Assert(err, check.IsNil)
c.Assert(token.TokenType, check.Equals, "Bearer")
c.Assert(token.Authorization, check.Equals, "Bearer nonenone")
}
func (s *tokenSuite) TestTokenIsValid(c *check.C) {
bodyToken := strings.NewReader(
`{"access_token": "nonenone", "token_type": "bearer", "expires_in": 1}`,
)
token, err := newToken(bodyToken)
c.Assert(err, check.IsNil)
c.Assert(token.isValid(), check.Equals, true)
}
func (s *tokenSuite) TestTokenNotIsValid(c *check.C) {
bodyToken := strings.NewReader(
`{"access_token": "nonenone", "token_type": "bearer", "expires_in": 1}`,
)
token, err := newToken(bodyToken)
time.Sleep(1 * time.Second)
c.Assert(err, check.IsNil)
c.Assert(token.isValid(), check.Equals, false)
}