99e2391b2a
为 Usage/Promo/Redeem 注入认证缓存失效逻辑 删除用户与分组前先失效认证缓存降低窗口 补充回归测试验证失效调用 测试: make test
32 lines
903 B
Go
32 lines
903 B
Go
//go:build unit
|
|
|
|
package service
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestUsageService_InvalidateUsageCaches(t *testing.T) {
|
|
invalidator := &authCacheInvalidatorStub{}
|
|
svc := &UsageService{authCacheInvalidator: invalidator}
|
|
|
|
svc.invalidateUsageCaches(context.Background(), 7, false)
|
|
require.Empty(t, invalidator.userIDs)
|
|
|
|
svc.invalidateUsageCaches(context.Background(), 7, true)
|
|
require.Equal(t, []int64{7}, invalidator.userIDs)
|
|
}
|
|
|
|
func TestRedeemService_InvalidateRedeemCaches_AuthCache(t *testing.T) {
|
|
invalidator := &authCacheInvalidatorStub{}
|
|
svc := &RedeemService{authCacheInvalidator: invalidator}
|
|
|
|
svc.invalidateRedeemCaches(context.Background(), 11, &RedeemCode{Type: RedeemTypeBalance})
|
|
svc.invalidateRedeemCaches(context.Background(), 11, &RedeemCode{Type: RedeemTypeConcurrency})
|
|
|
|
require.Equal(t, []int64{11, 11}, invalidator.userIDs)
|
|
}
|