spikard 0.12.0 → 0.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Steepfile +6 -0
- data/ext/spikard_rb/extconf.rb +1 -2
- data/ext/spikard_rb/{Cargo.lock → native/Cargo.lock} +897 -451
- data/ext/spikard_rb/native/Cargo.toml +24 -0
- data/ext/spikard_rb/src/lib.rs +5366 -3
- data/lib/spikard/native.rb +86 -0
- data/lib/spikard/version.rb +6 -1
- data/lib/spikard.rb +8 -45
- data/lib/spikard_rb.so +0 -0
- data/sig/types.rbs +427 -0
- metadata +14 -242
- data/LICENSE +0 -1
- data/README.md +0 -267
- data/ext/spikard_rb/Cargo.toml +0 -17
- data/lib/spikard/app.rb +0 -428
- data/lib/spikard/background.rb +0 -58
- data/lib/spikard/config.rb +0 -506
- data/lib/spikard/converters.rb +0 -13
- data/lib/spikard/grpc.rb +0 -182
- data/lib/spikard/handler_wrapper.rb +0 -113
- data/lib/spikard/provide.rb +0 -214
- data/lib/spikard/response.rb +0 -173
- data/lib/spikard/schema.rb +0 -243
- data/lib/spikard/sse.rb +0 -111
- data/lib/spikard/streaming_response.rb +0 -44
- data/lib/spikard/testing.rb +0 -432
- data/lib/spikard/upload_file.rb +0 -131
- data/lib/spikard/websocket.rb +0 -59
- data/sig/spikard.rbs +0 -719
- data/vendor/crates/spikard-bindings-shared/Cargo.toml +0 -80
- data/vendor/crates/spikard-bindings-shared/examples/config_extraction.rs +0 -132
- data/vendor/crates/spikard-bindings-shared/src/config_extractor.rs +0 -905
- data/vendor/crates/spikard-bindings-shared/src/conversion_traits.rs +0 -210
- data/vendor/crates/spikard-bindings-shared/src/di_traits.rs +0 -252
- data/vendor/crates/spikard-bindings-shared/src/error_response.rs +0 -404
- data/vendor/crates/spikard-bindings-shared/src/grpc_metadata.rs +0 -199
- data/vendor/crates/spikard-bindings-shared/src/handler_base.rs +0 -252
- data/vendor/crates/spikard-bindings-shared/src/json_conversion.rs +0 -829
- data/vendor/crates/spikard-bindings-shared/src/lazy_cache.rs +0 -587
- data/vendor/crates/spikard-bindings-shared/src/lib.rs +0 -33
- data/vendor/crates/spikard-bindings-shared/src/lifecycle_base.rs +0 -298
- data/vendor/crates/spikard-bindings-shared/src/lifecycle_executor.rs +0 -594
- data/vendor/crates/spikard-bindings-shared/src/response_builder.rs +0 -743
- data/vendor/crates/spikard-bindings-shared/src/response_interpreter.rs +0 -944
- data/vendor/crates/spikard-bindings-shared/src/test_client_base.rs +0 -260
- data/vendor/crates/spikard-bindings-shared/src/validation_helpers.rs +0 -369
- data/vendor/crates/spikard-bindings-shared/tests/config_extractor_behavior.rs +0 -192
- data/vendor/crates/spikard-bindings-shared/tests/error_response_edge_cases.rs +0 -383
- data/vendor/crates/spikard-bindings-shared/tests/full_coverage.rs +0 -459
- data/vendor/crates/spikard-bindings-shared/tests/handler_base_integration.rs +0 -280
- data/vendor/crates/spikard-bindings-shared/tests/integration_tests.rs +0 -669
- data/vendor/crates/spikard-core/Cargo.toml +0 -60
- data/vendor/crates/spikard-core/src/bindings/mod.rs +0 -3
- data/vendor/crates/spikard-core/src/bindings/response.rs +0 -130
- data/vendor/crates/spikard-core/src/debug.rs +0 -127
- data/vendor/crates/spikard-core/src/di/container.rs +0 -702
- data/vendor/crates/spikard-core/src/di/dependency.rs +0 -273
- data/vendor/crates/spikard-core/src/di/error.rs +0 -118
- data/vendor/crates/spikard-core/src/di/factory.rs +0 -538
- data/vendor/crates/spikard-core/src/di/graph.rs +0 -507
- data/vendor/crates/spikard-core/src/di/mod.rs +0 -192
- data/vendor/crates/spikard-core/src/di/resolved.rs +0 -428
- data/vendor/crates/spikard-core/src/di/value.rs +0 -282
- data/vendor/crates/spikard-core/src/errors.rs +0 -72
- data/vendor/crates/spikard-core/src/http.rs +0 -492
- data/vendor/crates/spikard-core/src/lib.rs +0 -29
- data/vendor/crates/spikard-core/src/lifecycle.rs +0 -1273
- data/vendor/crates/spikard-core/src/metadata.rs +0 -378
- data/vendor/crates/spikard-core/src/parameters.rs +0 -2546
- data/vendor/crates/spikard-core/src/problem.rs +0 -358
- data/vendor/crates/spikard-core/src/request_data.rs +0 -1146
- data/vendor/crates/spikard-core/src/router.rs +0 -530
- data/vendor/crates/spikard-core/src/schema_registry.rs +0 -197
- data/vendor/crates/spikard-core/src/type_hints.rs +0 -311
- data/vendor/crates/spikard-core/src/validation/error_mapper.rs +0 -710
- data/vendor/crates/spikard-core/src/validation/mod.rs +0 -470
- data/vendor/crates/spikard-core/tests/bindings_response_tests.rs +0 -136
- data/vendor/crates/spikard-core/tests/di_dependency_defaults.rs +0 -37
- data/vendor/crates/spikard-core/tests/error_mapper.rs +0 -761
- data/vendor/crates/spikard-core/tests/parameters_edge_cases.rs +0 -106
- data/vendor/crates/spikard-core/tests/parameters_full.rs +0 -701
- data/vendor/crates/spikard-core/tests/parameters_schema_and_formats.rs +0 -301
- data/vendor/crates/spikard-core/tests/request_data_roundtrip.rs +0 -67
- data/vendor/crates/spikard-core/tests/validation_coverage.rs +0 -250
- data/vendor/crates/spikard-core/tests/validation_error_paths.rs +0 -45
- data/vendor/crates/spikard-http/Cargo.toml +0 -87
- data/vendor/crates/spikard-http/examples/sse-notifications.rs +0 -148
- data/vendor/crates/spikard-http/examples/websocket-chat.rs +0 -92
- data/vendor/crates/spikard-http/src/auth.rs +0 -301
- data/vendor/crates/spikard-http/src/background.rs +0 -1860
- data/vendor/crates/spikard-http/src/bindings/mod.rs +0 -3
- data/vendor/crates/spikard-http/src/bindings/response.rs +0 -1
- data/vendor/crates/spikard-http/src/body_metadata.rs +0 -8
- data/vendor/crates/spikard-http/src/cors.rs +0 -1026
- data/vendor/crates/spikard-http/src/debug.rs +0 -128
- data/vendor/crates/spikard-http/src/di_handler.rs +0 -1672
- data/vendor/crates/spikard-http/src/grpc/framing.rs +0 -469
- data/vendor/crates/spikard-http/src/grpc/handler.rs +0 -1122
- data/vendor/crates/spikard-http/src/grpc/mod.rs +0 -434
- data/vendor/crates/spikard-http/src/grpc/service.rs +0 -622
- data/vendor/crates/spikard-http/src/grpc/streaming.rs +0 -319
- data/vendor/crates/spikard-http/src/handler_response.rs +0 -901
- data/vendor/crates/spikard-http/src/handler_trait.rs +0 -1015
- data/vendor/crates/spikard-http/src/handler_trait_tests.rs +0 -290
- data/vendor/crates/spikard-http/src/jsonrpc/http_handler.rs +0 -502
- data/vendor/crates/spikard-http/src/jsonrpc/method_registry.rs +0 -648
- data/vendor/crates/spikard-http/src/jsonrpc/mod.rs +0 -58
- data/vendor/crates/spikard-http/src/jsonrpc/protocol.rs +0 -1207
- data/vendor/crates/spikard-http/src/jsonrpc/router.rs +0 -2262
- data/vendor/crates/spikard-http/src/lib.rs +0 -548
- data/vendor/crates/spikard-http/src/lifecycle/adapter.rs +0 -230
- data/vendor/crates/spikard-http/src/lifecycle.rs +0 -1193
- data/vendor/crates/spikard-http/src/middleware/mod.rs +0 -560
- data/vendor/crates/spikard-http/src/middleware/multipart.rs +0 -912
- data/vendor/crates/spikard-http/src/middleware/urlencoded.rs +0 -513
- data/vendor/crates/spikard-http/src/middleware/validation.rs +0 -768
- data/vendor/crates/spikard-http/src/openapi/mod.rs +0 -309
- data/vendor/crates/spikard-http/src/openapi/parameter_extraction.rs +0 -535
- data/vendor/crates/spikard-http/src/openapi/schema_conversion.rs +0 -1363
- data/vendor/crates/spikard-http/src/openapi/spec_generation.rs +0 -667
- data/vendor/crates/spikard-http/src/query_parser.rs +0 -793
- data/vendor/crates/spikard-http/src/response.rs +0 -720
- data/vendor/crates/spikard-http/src/server/fast_router.rs +0 -186
- data/vendor/crates/spikard-http/src/server/grpc_routing.rs +0 -858
- data/vendor/crates/spikard-http/src/server/handler.rs +0 -1661
- data/vendor/crates/spikard-http/src/server/lifecycle_execution.rs +0 -253
- data/vendor/crates/spikard-http/src/server/mod.rs +0 -1649
- data/vendor/crates/spikard-http/src/server/request_extraction.rs +0 -871
- data/vendor/crates/spikard-http/src/server/routing_factory.rs +0 -618
- data/vendor/crates/spikard-http/src/sse.rs +0 -1409
- data/vendor/crates/spikard-http/src/testing/form.rs +0 -52
- data/vendor/crates/spikard-http/src/testing/multipart.rs +0 -64
- data/vendor/crates/spikard-http/src/testing/test_client.rs +0 -787
- data/vendor/crates/spikard-http/src/testing.rs +0 -617
- data/vendor/crates/spikard-http/src/websocket.rs +0 -1477
- data/vendor/crates/spikard-http/tests/auth_integration.rs +0 -645
- data/vendor/crates/spikard-http/tests/background_behavior.rs +0 -832
- data/vendor/crates/spikard-http/tests/common/grpc_helpers.rs +0 -1012
- data/vendor/crates/spikard-http/tests/common/handlers.rs +0 -309
- data/vendor/crates/spikard-http/tests/common/mod.rs +0 -33
- data/vendor/crates/spikard-http/tests/common/test_builders.rs +0 -628
- data/vendor/crates/spikard-http/tests/di_handler_error_responses.rs +0 -162
- data/vendor/crates/spikard-http/tests/di_integration.rs +0 -192
- data/vendor/crates/spikard-http/tests/doc_snippets.rs +0 -5
- data/vendor/crates/spikard-http/tests/grpc_bidirectional_streaming.rs +0 -430
- data/vendor/crates/spikard-http/tests/grpc_client_streaming.rs +0 -738
- data/vendor/crates/spikard-http/tests/grpc_error_handling_test.rs +0 -652
- data/vendor/crates/spikard-http/tests/grpc_integration_test.rs +0 -334
- data/vendor/crates/spikard-http/tests/grpc_metadata_test.rs +0 -532
- data/vendor/crates/spikard-http/tests/grpc_server_integration.rs +0 -495
- data/vendor/crates/spikard-http/tests/grpc_server_streaming.rs +0 -974
- data/vendor/crates/spikard-http/tests/lifecycle_execution.rs +0 -1093
- data/vendor/crates/spikard-http/tests/middleware_stack_integration.rs +0 -389
- data/vendor/crates/spikard-http/tests/multipart_behavior.rs +0 -656
- data/vendor/crates/spikard-http/tests/request_extraction_full.rs +0 -513
- data/vendor/crates/spikard-http/tests/server_auth_middleware_behavior.rs +0 -328
- data/vendor/crates/spikard-http/tests/server_config_builder.rs +0 -314
- data/vendor/crates/spikard-http/tests/server_configured_router_behavior.rs +0 -200
- data/vendor/crates/spikard-http/tests/server_cors_preflight.rs +0 -83
- data/vendor/crates/spikard-http/tests/server_handler_wrappers.rs +0 -464
- data/vendor/crates/spikard-http/tests/server_method_router_additional_behavior.rs +0 -286
- data/vendor/crates/spikard-http/tests/server_method_router_coverage.rs +0 -118
- data/vendor/crates/spikard-http/tests/server_middleware_behavior.rs +0 -99
- data/vendor/crates/spikard-http/tests/server_middleware_branches.rs +0 -204
- data/vendor/crates/spikard-http/tests/server_openapi_jsonrpc_static.rs +0 -421
- data/vendor/crates/spikard-http/tests/server_router_behavior.rs +0 -121
- data/vendor/crates/spikard-http/tests/sse_behavior.rs +0 -620
- data/vendor/crates/spikard-http/tests/sse_full_behavior.rs +0 -584
- data/vendor/crates/spikard-http/tests/sse_handler_behavior.rs +0 -130
- data/vendor/crates/spikard-http/tests/test_client_requests.rs +0 -167
- data/vendor/crates/spikard-http/tests/testing_helpers.rs +0 -87
- data/vendor/crates/spikard-http/tests/testing_module_coverage.rs +0 -155
- data/vendor/crates/spikard-http/tests/urlencoded_content_type.rs +0 -82
- data/vendor/crates/spikard-http/tests/websocket_behavior.rs +0 -663
- data/vendor/crates/spikard-http/tests/websocket_full_behavior.rs +0 -440
- data/vendor/crates/spikard-http/tests/websocket_integration.rs +0 -150
- data/vendor/crates/spikard-rb/Cargo.toml +0 -68
- data/vendor/crates/spikard-rb/build.rs +0 -200
- data/vendor/crates/spikard-rb/src/background.rs +0 -63
- data/vendor/crates/spikard-rb/src/config/mod.rs +0 -5
- data/vendor/crates/spikard-rb/src/config/server_config.rs +0 -401
- data/vendor/crates/spikard-rb/src/conversion.rs +0 -688
- data/vendor/crates/spikard-rb/src/di/builder.rs +0 -100
- data/vendor/crates/spikard-rb/src/di/mod.rs +0 -375
- data/vendor/crates/spikard-rb/src/grpc/handler.rs +0 -834
- data/vendor/crates/spikard-rb/src/grpc/mod.rs +0 -13
- data/vendor/crates/spikard-rb/src/gvl.rs +0 -80
- data/vendor/crates/spikard-rb/src/handler.rs +0 -699
- data/vendor/crates/spikard-rb/src/integration/mod.rs +0 -3
- data/vendor/crates/spikard-rb/src/lib.rs +0 -2264
- data/vendor/crates/spikard-rb/src/lifecycle.rs +0 -303
- data/vendor/crates/spikard-rb/src/metadata/mod.rs +0 -5
- data/vendor/crates/spikard-rb/src/metadata/route_extraction.rs +0 -507
- data/vendor/crates/spikard-rb/src/request.rs +0 -439
- data/vendor/crates/spikard-rb/src/runtime/mod.rs +0 -5
- data/vendor/crates/spikard-rb/src/runtime/server_runner.rs +0 -344
- data/vendor/crates/spikard-rb/src/server.rs +0 -307
- data/vendor/crates/spikard-rb/src/sse.rs +0 -231
- data/vendor/crates/spikard-rb/src/testing/client.rs +0 -698
- data/vendor/crates/spikard-rb/src/testing/mod.rs +0 -7
- data/vendor/crates/spikard-rb/src/testing/sse.rs +0 -108
- data/vendor/crates/spikard-rb/src/testing/websocket.rs +0 -573
- data/vendor/crates/spikard-rb/src/websocket.rs +0 -475
- data/vendor/crates/spikard-rb-macros/Cargo.toml +0 -25
- data/vendor/crates/spikard-rb-macros/src/lib.rs +0 -51
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
//! Lifecycle hook base implementations
|
|
2
|
-
|
|
3
|
-
use std::sync::Arc;
|
|
4
|
-
|
|
5
|
-
/// Lifecycle hook types supported across all bindings
|
|
6
|
-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
7
|
-
pub enum LifecycleHookType {
|
|
8
|
-
/// Called at the start of request processing
|
|
9
|
-
OnRequest,
|
|
10
|
-
/// Called before validation
|
|
11
|
-
PreValidation,
|
|
12
|
-
/// Called before handler execution
|
|
13
|
-
PreHandler,
|
|
14
|
-
/// Called after handler execution
|
|
15
|
-
OnResponse,
|
|
16
|
-
/// Called when an error occurs
|
|
17
|
-
OnError,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/// Result type for lifecycle hooks
|
|
21
|
-
#[derive(Clone)]
|
|
22
|
-
pub enum HookResult {
|
|
23
|
-
/// Continue with normal processing
|
|
24
|
-
Continue,
|
|
25
|
-
/// Short-circuit and return this response
|
|
26
|
-
ShortCircuit(serde_json::Value),
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/// Trait for implementing lifecycle hooks in language bindings
|
|
30
|
-
pub trait LifecycleHook: Send + Sync {
|
|
31
|
-
/// Execute the lifecycle hook
|
|
32
|
-
///
|
|
33
|
-
/// # Errors
|
|
34
|
-
///
|
|
35
|
-
/// Returns an error if hook execution fails.
|
|
36
|
-
fn execute(&self, context: serde_json::Value) -> Result<HookResult, String>;
|
|
37
|
-
|
|
38
|
-
/// Get the hook type
|
|
39
|
-
fn hook_type(&self) -> LifecycleHookType;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/// Base configuration for lifecycle hooks
|
|
43
|
-
pub struct LifecycleConfig {
|
|
44
|
-
/// Registered hooks by type
|
|
45
|
-
hooks: std::collections::HashMap<LifecycleHookType, Vec<Arc<dyn LifecycleHook>>>,
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
impl LifecycleConfig {
|
|
49
|
-
/// Create a new lifecycle configuration
|
|
50
|
-
#[must_use]
|
|
51
|
-
pub fn new() -> Self {
|
|
52
|
-
Self {
|
|
53
|
-
hooks: std::collections::HashMap::new(),
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/// Register a lifecycle hook
|
|
58
|
-
pub fn register(&mut self, hook: Arc<dyn LifecycleHook>) {
|
|
59
|
-
self.hooks.entry(hook.hook_type()).or_default().push(hook);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/// Get hooks for a specific type
|
|
63
|
-
#[must_use]
|
|
64
|
-
pub fn get_hooks(&self, hook_type: LifecycleHookType) -> Vec<Arc<dyn LifecycleHook>> {
|
|
65
|
-
self.hooks.get(&hook_type).cloned().unwrap_or_default()
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
impl Default for LifecycleConfig {
|
|
70
|
-
fn default() -> Self {
|
|
71
|
-
Self::new()
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
#[cfg(test)]
|
|
76
|
-
mod tests {
|
|
77
|
-
use super::*;
|
|
78
|
-
use serde_json::json;
|
|
79
|
-
|
|
80
|
-
struct TestHook {
|
|
81
|
-
hook_type: LifecycleHookType,
|
|
82
|
-
result: HookResult,
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
impl LifecycleHook for TestHook {
|
|
86
|
-
fn execute(&self, _context: serde_json::Value) -> Result<HookResult, String> {
|
|
87
|
-
Ok(self.result.clone())
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
fn hook_type(&self) -> LifecycleHookType {
|
|
91
|
-
self.hook_type
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
#[test]
|
|
96
|
-
fn test_lifecycle_hook_type_equality() {
|
|
97
|
-
assert_eq!(LifecycleHookType::OnRequest, LifecycleHookType::OnRequest);
|
|
98
|
-
assert_ne!(LifecycleHookType::OnRequest, LifecycleHookType::OnResponse);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
#[test]
|
|
102
|
-
fn test_lifecycle_hook_type_hash() {
|
|
103
|
-
use std::collections::HashSet;
|
|
104
|
-
|
|
105
|
-
let mut set = HashSet::new();
|
|
106
|
-
set.insert(LifecycleHookType::OnRequest);
|
|
107
|
-
set.insert(LifecycleHookType::PreHandler);
|
|
108
|
-
set.insert(LifecycleHookType::OnRequest);
|
|
109
|
-
|
|
110
|
-
assert_eq!(set.len(), 2);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
#[test]
|
|
114
|
-
fn test_hook_result_continue() {
|
|
115
|
-
let result = HookResult::Continue;
|
|
116
|
-
match result {
|
|
117
|
-
HookResult::Continue => {}
|
|
118
|
-
HookResult::ShortCircuit(_) => panic!("Expected Continue"),
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
#[test]
|
|
123
|
-
fn test_hook_result_short_circuit() {
|
|
124
|
-
let response = json!({ "status": "error" });
|
|
125
|
-
let result = HookResult::ShortCircuit(response.clone());
|
|
126
|
-
match result {
|
|
127
|
-
HookResult::Continue => panic!("Expected ShortCircuit"),
|
|
128
|
-
HookResult::ShortCircuit(r) => {
|
|
129
|
-
assert_eq!(r, response);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
#[test]
|
|
135
|
-
fn test_lifecycle_config_new() {
|
|
136
|
-
let config = LifecycleConfig::new();
|
|
137
|
-
assert_eq!(config.get_hooks(LifecycleHookType::OnRequest).len(), 0);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
#[test]
|
|
141
|
-
fn test_lifecycle_config_default() {
|
|
142
|
-
let config = LifecycleConfig::default();
|
|
143
|
-
assert_eq!(config.get_hooks(LifecycleHookType::OnRequest).len(), 0);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
#[test]
|
|
147
|
-
fn test_register_single_hook() {
|
|
148
|
-
let mut config = LifecycleConfig::new();
|
|
149
|
-
let hook = Arc::new(TestHook {
|
|
150
|
-
hook_type: LifecycleHookType::OnRequest,
|
|
151
|
-
result: HookResult::Continue,
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
config.register(hook);
|
|
155
|
-
|
|
156
|
-
let hooks = config.get_hooks(LifecycleHookType::OnRequest);
|
|
157
|
-
assert_eq!(hooks.len(), 1);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
#[test]
|
|
161
|
-
fn test_register_multiple_hooks_same_type() {
|
|
162
|
-
let mut config = LifecycleConfig::new();
|
|
163
|
-
|
|
164
|
-
for i in 0..3 {
|
|
165
|
-
let hook = Arc::new(TestHook {
|
|
166
|
-
hook_type: LifecycleHookType::OnRequest,
|
|
167
|
-
result: if i == 0 {
|
|
168
|
-
HookResult::Continue
|
|
169
|
-
} else {
|
|
170
|
-
HookResult::ShortCircuit(json!({ "index": i }))
|
|
171
|
-
},
|
|
172
|
-
});
|
|
173
|
-
config.register(hook);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
let hooks = config.get_hooks(LifecycleHookType::OnRequest);
|
|
177
|
-
assert_eq!(hooks.len(), 3);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
#[test]
|
|
181
|
-
fn test_register_hooks_different_types() {
|
|
182
|
-
let mut config = LifecycleConfig::new();
|
|
183
|
-
|
|
184
|
-
let hook_on_request = Arc::new(TestHook {
|
|
185
|
-
hook_type: LifecycleHookType::OnRequest,
|
|
186
|
-
result: HookResult::Continue,
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
let hook_on_error = Arc::new(TestHook {
|
|
190
|
-
hook_type: LifecycleHookType::OnError,
|
|
191
|
-
result: HookResult::Continue,
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
config.register(hook_on_request);
|
|
195
|
-
config.register(hook_on_error);
|
|
196
|
-
|
|
197
|
-
assert_eq!(config.get_hooks(LifecycleHookType::OnRequest).len(), 1);
|
|
198
|
-
assert_eq!(config.get_hooks(LifecycleHookType::OnError).len(), 1);
|
|
199
|
-
assert_eq!(config.get_hooks(LifecycleHookType::PreHandler).len(), 0);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
#[test]
|
|
203
|
-
fn test_get_hooks_empty() {
|
|
204
|
-
let config = LifecycleConfig::new();
|
|
205
|
-
let hooks = config.get_hooks(LifecycleHookType::PreValidation);
|
|
206
|
-
assert!(hooks.is_empty());
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
#[test]
|
|
210
|
-
fn test_get_hooks_multiple_calls() {
|
|
211
|
-
let mut config = LifecycleConfig::new();
|
|
212
|
-
|
|
213
|
-
let hook_a = Arc::new(TestHook {
|
|
214
|
-
hook_type: LifecycleHookType::OnResponse,
|
|
215
|
-
result: HookResult::Continue,
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
let hook_b = Arc::new(TestHook {
|
|
219
|
-
hook_type: LifecycleHookType::OnResponse,
|
|
220
|
-
result: HookResult::Continue,
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
config.register(hook_a);
|
|
224
|
-
config.register(hook_b);
|
|
225
|
-
|
|
226
|
-
let hooks_on_response_first = config.get_hooks(LifecycleHookType::OnResponse);
|
|
227
|
-
let hooks_on_response_second = config.get_hooks(LifecycleHookType::OnResponse);
|
|
228
|
-
|
|
229
|
-
assert_eq!(hooks_on_response_first.len(), 2);
|
|
230
|
-
assert_eq!(hooks_on_response_second.len(), 2);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
#[test]
|
|
234
|
-
fn test_hook_execute() {
|
|
235
|
-
let hook = TestHook {
|
|
236
|
-
hook_type: LifecycleHookType::OnRequest,
|
|
237
|
-
result: HookResult::Continue,
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
let context = json!({ "test": "data" });
|
|
241
|
-
let result = hook.execute(context);
|
|
242
|
-
|
|
243
|
-
assert!(result.is_ok());
|
|
244
|
-
match result.unwrap() {
|
|
245
|
-
HookResult::Continue => {}
|
|
246
|
-
HookResult::ShortCircuit(_) => panic!("Expected Continue"),
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
#[test]
|
|
251
|
-
fn test_hook_type_retrieval() {
|
|
252
|
-
let hook = TestHook {
|
|
253
|
-
hook_type: LifecycleHookType::PreValidation,
|
|
254
|
-
result: HookResult::Continue,
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
assert_eq!(hook.hook_type(), LifecycleHookType::PreValidation);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
#[test]
|
|
261
|
-
fn test_all_hook_types() {
|
|
262
|
-
let hook_types = vec![
|
|
263
|
-
LifecycleHookType::OnRequest,
|
|
264
|
-
LifecycleHookType::PreValidation,
|
|
265
|
-
LifecycleHookType::PreHandler,
|
|
266
|
-
LifecycleHookType::OnResponse,
|
|
267
|
-
LifecycleHookType::OnError,
|
|
268
|
-
];
|
|
269
|
-
|
|
270
|
-
let mut config = LifecycleConfig::new();
|
|
271
|
-
|
|
272
|
-
for hook_type in &hook_types {
|
|
273
|
-
let hook = Arc::new(TestHook {
|
|
274
|
-
hook_type: *hook_type,
|
|
275
|
-
result: HookResult::Continue,
|
|
276
|
-
});
|
|
277
|
-
config.register(hook);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
for hook_type in hook_types {
|
|
281
|
-
let hooks = config.get_hooks(hook_type);
|
|
282
|
-
assert_eq!(hooks.len(), 1);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
#[test]
|
|
287
|
-
fn test_hook_result_clone() {
|
|
288
|
-
let original = HookResult::ShortCircuit(json!({ "key": "value" }));
|
|
289
|
-
let cloned = original;
|
|
290
|
-
|
|
291
|
-
match cloned {
|
|
292
|
-
HookResult::ShortCircuit(response) => {
|
|
293
|
-
assert_eq!(response["key"], "value");
|
|
294
|
-
}
|
|
295
|
-
HookResult::Continue => panic!("Expected ShortCircuit"),
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|