Skip to content

Commit 9747331

Browse files
authored
Merge pull request #2646 from cuipinghuo/add-ut-for-internal-cache
test: add unit test suite for policy cache implementation
2 parents 519d66f + ad45800 commit 9747331

File tree

3 files changed

+425
-51
lines changed

3 files changed

+425
-51
lines changed

internal/policy/cache/cache.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ package cache
1919
import (
2020
"context"
2121
"sync"
22-
23-
log "github.com/sirupsen/logrus"
2422
)
2523

2624
// policyCacheKey is the key for PolicyCache values in Context.
@@ -72,25 +70,15 @@ func (c *PolicyCache) Set(key string, value string, err error) {
7270
}
7371

7472
// NewPolicyCache creates and returns a new PolicyCache instance.
75-
func NewPolicyCache(ctx context.Context) (*PolicyCache, error) {
73+
func NewPolicyCache(ctx context.Context) *PolicyCache {
7674
cache, ok := ctx.Value(policyCacheKey).(*PolicyCache)
7775
if ok && cache != nil {
78-
return cache, nil
79-
}
80-
81-
c, err := CreatePolicyCache()
82-
if err != nil {
83-
log.Debug("Failed to create PolicyCache")
84-
return nil, err
76+
return cache
8577
}
8678

87-
return c, nil
88-
}
89-
90-
func CreatePolicyCache() (*PolicyCache, error) {
9179
return &PolicyCache{
9280
Data: sync.Map{},
93-
}, nil
81+
}
9482
}
9583

9684
// PolicyCacheFromContext retrieves the PolicyCache from the context.

0 commit comments

Comments
 (0)