| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package auth | 5 package auth |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "math/rand" | 8 "math/rand" |
| 9 "testing" | 9 "testing" |
| 10 "time" | 10 "time" |
| 11 | 11 |
| 12 "golang.org/x/net/context" | 12 "golang.org/x/net/context" |
| 13 | 13 |
| 14 "github.com/luci/luci-go/common/clock" | 14 "github.com/luci/luci-go/common/clock" |
| 15 "github.com/luci/luci-go/common/clock/testclock" | 15 "github.com/luci/luci-go/common/clock/testclock" |
| 16 "github.com/luci/luci-go/common/data/rand/mathrand" | 16 "github.com/luci/luci-go/common/data/rand/mathrand" |
| 17 | 17 |
| 18 . "github.com/smartystreets/goconvey/convey" | 18 . "github.com/smartystreets/goconvey/convey" |
| 19 ) | 19 ) |
| 20 | 20 |
| 21 func TestTokenCache(t *testing.T) { | 21 func TestTokenCache(t *testing.T) { |
| 22 t.Parallel() |
| 23 |
| 22 Convey("with mocked cache", t, func() { | 24 Convey("with mocked cache", t, func() { |
| 23 cache := &mockedCache{} | 25 cache := &mockedCache{} |
| 24 | 26 |
| 25 ctx := context.Background() | 27 ctx := context.Background() |
| 26 ctx, _ = testclock.UseTime(ctx, testclock.TestRecentTimeUTC) | 28 ctx, _ = testclock.UseTime(ctx, testclock.TestRecentTimeUTC) |
| 27 ctx = mathrand.Set(ctx, rand.New(rand.NewSource(12345))) | 29 ctx = mathrand.Set(ctx, rand.New(rand.NewSource(12345))) |
| 28 ctx = SetConfig(ctx, Config{GlobalCache: cache}) | 30 ctx = SetConfig(ctx, Config{GlobalCache: cache}) |
| 29 | 31 |
| 30 tc := tokenCache{ | 32 tc := tokenCache{ |
| 31 Kind: "testing", | 33 Kind: "testing", |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 return mc.data[key], nil | 105 return mc.data[key], nil |
| 104 } | 106 } |
| 105 | 107 |
| 106 func (mc *mockedCache) Set(c context.Context, key string, value []byte, exp time
.Duration) error { | 108 func (mc *mockedCache) Set(c context.Context, key string, value []byte, exp time
.Duration) error { |
| 107 if mc.data == nil { | 109 if mc.data == nil { |
| 108 mc.data = map[string][]byte{} | 110 mc.data = map[string][]byte{} |
| 109 } | 111 } |
| 110 mc.data[key] = value | 112 mc.data[key] = value |
| 111 return nil | 113 return nil |
| 112 } | 114 } |
| OLD | NEW |