-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoogle_test.go
More file actions
59 lines (49 loc) · 1.17 KB
/
google_test.go
File metadata and controls
59 lines (49 loc) · 1.17 KB
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
package gopenid_test
import (
"fmt"
"github.com/tanopwan/gopenid"
"testing"
"time"
)
// CacheService contains business logic to the domain
type CacheService struct {
data map[string]interface{}
}
// NewCacheService return new object
func NewCacheService() *CacheService {
return &CacheService{
data: make(map[string]interface{}),
}
}
// Get key from cache
func (c *CacheService) Get(key string) interface{} {
return c.data[key]
}
// Del key from cache
func (c *CacheService) Del(key string) {
delete(c.data, key)
}
// Set key into cache
func (c *CacheService) Set(key string, value interface{}) {
c.data[key] = value
}
// SetExpire key into cache with expiry date
func (c *CacheService) SetExpire(key string, value interface{}, duration time.Duration) {
c.data[key] = value
timer := time.NewTimer(duration)
go func() {
<-timer.C
delete(c.data, key)
fmt.Println("google_public cache is expired")
}()
}
func TestValidateTokenForProd(t *testing.T) {
cc := NewCacheService()
s := gopenid.NewGoogleService(cc)
idToken := ""
claims, err := s.TokenInfoForProd(idToken)
if err != nil {
t.Errorf("failed test: %s\n", err.Error())
}
t.Logf("claims: %+v\n", claims)
}