authztest

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package authztest 提供 authz.SessionStore 的契约测试套件(#196):下游把 自己的 Redis 等持久存储适配器塞进 Run,同一组用例验证「键值/集合原语语义 + kitx 编排层依赖的会话注册表行为」。

套件分两层:

  • RunStore:SessionStore 原语契约(Get/SetNX/Del/SAdd/SRem/SMembers/ Expire/TTL 的返回值、TTL 语义、SetNX 原子性、集合 TTL 只延长不缩短);
  • RunRegistry:基于 authz.NewStoreRegistry 的编排契约(重复 ID/refreshHash 唯一挂载/Kick 三态/KickUser 聚合计数)。

用法(下游 store 实现):

func TestRedisStoreContract(t *testing.T) {
    authztest.Run(t, func(t *testing.T) authz.SessionStore {
        return newRedisStore(t) // 每次返回隔离命名空间的空 store
    })
}

工厂约定:每次调用返回**空且互不冲突**的 store(独立前缀/独立 DB);套件 自身也会为每个用例生成唯一键前缀,但 store 契约测试(SetNX/TTL)要求键空间 可写且无残留。TTL 用例使用短寿命 + 轮询(最长数秒),适配真实 Redis。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(t *testing.T, newStore StoreFactory)

Run 跑完整契约:原语语义 + 编排行为。

func RunRegistry

func RunRegistry(t *testing.T, newStore StoreFactory)

RunRegistry 跑基于 authz.NewStoreRegistry 的编排契约(下游 store 的最终验收面)。

func RunStore

func RunStore(t *testing.T, newStore StoreFactory)

RunStore 只跑 SessionStore 原语契约。

Types

type StoreFactory

type StoreFactory func(t *testing.T) authz.SessionStore

StoreFactory 返回一份隔离的 SessionStore(每次调用都应是空命名空间)。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL