-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobservability_test.rs
More file actions
81 lines (71 loc) · 2.08 KB
/
observability_test.rs
File metadata and controls
81 lines (71 loc) · 2.08 KB
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
use anyhow::Result;
use openapi_rs::model::parse::OpenAPI;
use openapi_rs::observability::init_logger;
use openapi_rs::request;
fn main() -> Result<()> {
init_logger();
let content = r#"
openapi: 3.1.0
info:
title: Example API
description: API definitions for example
version: '0.0.1'
x-file-identifier: example
components:
schemas:
ExampleResponse:
properties:
uuid:
type: string
description: The UUID for this example.
format: uuid
example: 00000000-0000-0000-0000-000000000000
security: [ ]
paths:
/example/{uuid}:
get:
parameters:
- name: uuid
description: The UUID for this example.
in: path
schema:
type: string
format: uuid
example: 00000000-0000-0000-0000-000000000000
responses:
'200':
description: Get a Example response
content:
application/json:
schema:
$ref: '#/components/schemas/ExampleResponse'
"#;
let openapi: OpenAPI = OpenAPI::yaml(content).expect("Failed to parse OpenAPI content");
fn make_request(uri: &str) -> request::axum::RequestData {
request::axum::RequestData {
path: "/example/{uuid}".to_string(),
inner: axum::http::Request::builder()
.method("GET")
.uri(uri)
.body(axum::body::Body::empty())
.unwrap(),
body: None,
}
}
println!("✅ Testing successful case");
match openapi.validator(make_request(
"/example/00000000-0000-0000-0000-000000000000",
)) {
Ok(_) => println!("✓ Validation successful"),
Err(e) => println!("✗ Validation failed: {}", e),
}
println!("❌ Testing failure case");
match openapi.validator(make_request(
"/example/00000000-0000-0000-0000-00000000000x",
)) {
Ok(_) => println!("✓ Validation successful"),
Err(e) => println!("✗ Validation failed: {}", e),
}
println!("🎉 Testing completed");
Ok(())
}