Skip to content

Commit 5d39024

Browse files
committed
add ValidationErrorInfo serialization test
1 parent 61c4f95 commit 5d39024

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

crates/secrets/src/model/secret_result.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,45 @@ impl ValidationErrorType {
9595
}
9696
}
9797
}
98+
99+
#[cfg(test)]
100+
mod tests {
101+
use super::*;
102+
use serde_json;
103+
104+
#[test]
105+
fn test_serialize_validation_error_info() {
106+
let error_info = ValidationErrorInfo {
107+
error_type: ValidationErrorType::HttpError,
108+
status_code: 400,
109+
message: "Invalid token".to_string(),
110+
};
111+
112+
let expected = serde_json::json!({
113+
"type": "HttpError",
114+
"statusCode": 400,
115+
"message": "Invalid token"
116+
});
117+
118+
let actual = serde_json::to_value(&error_info).unwrap();
119+
assert_eq!(actual, expected);
120+
}
121+
122+
#[test]
123+
fn test_deserialize_validation_error_info() {
124+
let json = serde_json::json!({
125+
"type": "HttpError",
126+
"statusCode": 401,
127+
"message": "Unauthorized access"
128+
});
129+
130+
let expected = ValidationErrorInfo {
131+
error_type: ValidationErrorType::HttpError,
132+
status_code: 401,
133+
message: "Unauthorized access".to_string(),
134+
};
135+
136+
let actual: ValidationErrorInfo = serde_json::from_value(json).unwrap();
137+
assert_eq!(actual, expected);
138+
}
139+
}

0 commit comments

Comments
 (0)