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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//! Copyright (c) 2026 Kirky.X. All rights reserved.
//! See LICENSE for full license text.
//! 声明式 JSON 测试套件。
//!
//! 提供从 JSON 文件加载测试用例并运行 [`Authorizer`] trait 的能力,
//! 输出 [`TestReport`] 报告。
//!
//! # 启用方式
//!
//! 启用 `garrison-testing` feature(依赖 `authorize-api`):
//!
//! ```toml
//! [dependencies]
//! garrison = { version = "0.5", features = ["garrison-testing"] }
//! ```
//!
//! # JSON 格式
//!
//! ```json
//! {
//! "name": "rbac-basic",
//! "cases": [
//! {
//! "name": "admin_can_read",
//! "request": {"login_id": 1, "tenant_id": 0, "action": "read", "resource": null, "context": null},
//! "expected": {"allowed": true, "reason": "explicit_allow"}
//! }
//! ]
//! }
//! ```
//!
//! # 使用示例
//!
//! ```ignore
//! use garrison::testing::JsonTestSuite;
//! use garrison::core::permission::Authorizer;
//!
//! let json = std::fs::read_to_string("tests/rbac.json")?;
//! let suite = JsonTestSuite::from_json(&json)?;
//! let authorizer: Box<dyn Authorizer> = /* 你的 Authorizer 实现 */;
//! let report = suite.run(&*authorizer).await?;
//! println!("passed: {}/{}", report.passed, report.total);
//! ```
//!
//! [`Authorizer`]: crate::core::permission::Authorizer
use ;
use crate;
/// 声明式 JSON 测试套件。
///
/// 从 JSON 文件加载一组 [`JsonTestCase`],运行 [`Authorizer::authorize`],
/// 比较实际决策与期望决策,输出 [`TestReport`]。
///
/// # JSON 格式
///
/// ```json
/// {
/// "name": "rbac-basic",
/// "cases": [
/// {
/// "name": "admin_can_read",
/// "request": {"login_id": 1, "tenant_id": 0, "action": "read", "resource": null, "context": null},
/// "expected": {"allowed": true, "reason": "explicit_allow"}
/// }
/// ]
/// }
/// ```
/// 单个声明式测试用例。
///
/// 包含一个 [`AuthRequest`] 输入和期望的 [`Decision`] 输出。
/// 测试套件运行报告。
///
/// 由 [`JsonTestSuite::run`] 返回,包含通过/失败计数与失败详情。
/// 单个失败用例详情。
///
/// 记录期望决策、实际决策与可选错误消息(当 [`Authorizer::authorize`] 返回 `Err` 时)。