taubyte_sdk/http/event/
return.rs1use super::{imports, Event};
2use crate::errno::Error;
3
4impl Event {
5 fn return_code_unsafe(&self, code: u32) -> Error {
6 #[allow(unused_unsafe)]
7 unsafe {
8 imports::eventHttpRetCode(self.event, code)
9 }
10 }
11
12 pub fn return_code(&self, code: u32) -> Result<(), Box<dyn std::error::Error>> {
13 let err0 = self.return_code_unsafe(code);
14 if err0.is_err() {
15 Err(format!("return code failed with: {}", err0).into())
16 } else {
17 Ok(())
18 }
19 }
20}
21
22#[cfg(test)]
23pub mod test {
24 pub static EXPECTED_ID: u32 = 0;
25 pub static EXPECTED_CODE: u32 = 200;
26
27 #[test]
28 fn test_return() {
29 use crate::http::Event;
30
31 let http: Event = Event {
32 event: (EXPECTED_ID),
33 };
34
35 let wrong_http: Event = Event { event: (1) };
36 let wrong_id = wrong_http.return_code(EXPECTED_CODE);
37 assert!(wrong_id.is_err());
38
39 let wrong_code = http.return_code(404);
40 assert!(wrong_code.is_err());
41
42 let success = http.return_code(EXPECTED_CODE);
43 assert!(success.is_ok());
44 }
45}