style: simplify string formatting (#4260)

Co-authored-by: Tobie Morgan Hitchcock <tobie@surrealdb.com>
This commit is contained in:
Hamir Mahal 2024-07-18 05:19:28 -07:00 committed by GitHub
parent c73435a881
commit b37929b6ab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 360 additions and 407 deletions

View file

@ -565,19 +565,16 @@ mod tests {
let res = res.unwrap().remove(0).output(); let res = res.unwrap().remove(0).output();
let res = if succeeds { let res = if succeeds {
assert!(res.is_ok(), "Unexpected error for test case {}: {:?}", idx, res); assert!(res.is_ok(), "Unexpected error for test case {idx}: {res:?}");
res.unwrap().to_string() res.unwrap().to_string()
} else { } else {
assert!(res.is_err(), "Unexpected success for test case {}: {:?}", idx, res); assert!(res.is_err(), "Unexpected success for test case {idx}: {res:?}");
res.unwrap_err().to_string() res.unwrap_err().to_string()
}; };
assert!( assert!(
res.contains(&contains), res.contains(&contains),
"Unexpected result for test case {}: expected to contain = `{}`, got `{}`", "Unexpected result for test case {idx}: expected to contain = `{contains}`, got `{res}`"
idx,
contains,
res
); );
} }

View file

@ -231,7 +231,7 @@ impl Drop for HttpCallMetricTracker {
} }
ResultState::Result(s, v, size) => { ResultState::Result(s, v, size) => {
self.status_code = Some(s); self.status_code = Some(s);
self.version = format!("{:?}", v); self.version = format!("{v:?}");
self.response_size = size; self.response_size = size;
} }
}; };

View file

@ -135,7 +135,7 @@ mod tests {
let (addr, mut req_rx) = telemetry::traces::tests::mock_otlp_server().await; let (addr, mut req_rx) = telemetry::traces::tests::mock_otlp_server().await;
{ {
let otlp_endpoint = format!("http://{}", addr); let otlp_endpoint = format!("http://{addr}");
temp_env::with_vars( temp_env::with_vars(
vec![ vec![
("SURREAL_TRACING_TRACER", Some("otlp")), ("SURREAL_TRACING_TRACER", Some("otlp")),
@ -176,7 +176,7 @@ mod tests {
let (addr, mut req_rx) = telemetry::traces::tests::mock_otlp_server().await; let (addr, mut req_rx) = telemetry::traces::tests::mock_otlp_server().await;
{ {
let otlp_endpoint = format!("http://{}", addr); let otlp_endpoint = format!("http://{addr}");
temp_env::with_vars( temp_env::with_vars(
vec![ vec![
("SURREAL_TRACING_TRACER", Some("otlp")), ("SURREAL_TRACING_TRACER", Some("otlp")),

View file

@ -26,7 +26,7 @@ where
Some(otlp::new(filter)) Some(otlp::new(filter))
} }
tracer => { tracer => {
panic!("unsupported tracer {}", tracer); panic!("unsupported tracer {tracer}");
} }
} }
} }

View file

@ -468,8 +468,7 @@ mod cli_integration {
.clone() .clone()
.unwrap_err() .unwrap_err()
.contains("Namespace is needed for authentication but it was not provided"), .contains("Namespace is needed for authentication but it was not provided"),
"auth level namespace requires providing a namespace: {:?}", "auth level namespace requires providing a namespace: {output:?}"
output
); );
} }
@ -484,8 +483,7 @@ mod cli_integration {
.clone() .clone()
.unwrap_err() .unwrap_err()
.contains("Database is needed for authentication but it was not provided"), .contains("Database is needed for authentication but it was not provided"),
"auth level database requires providing a namespace and database: {:?}", "auth level database requires providing a namespace and database: {output:?}"
output
); );
} }
server.finish().unwrap(); server.finish().unwrap();
@ -832,7 +830,7 @@ mod cli_integration {
let args = format!("{sql_args} {creds}"); let args = format!("{sql_args} {creds}");
let input = ""; let input = "";
let output = common::run(&args).input(input).output(); let output = common::run(&args).input(input).output();
assert!(output.is_ok(), "anonymous user should be able to query: {:?}", output); assert!(output.is_ok(), "anonymous user should be able to query: {output:?}");
} }
info!("* Query over WS"); info!("* Query over WS");
@ -840,7 +838,7 @@ mod cli_integration {
let args = format!("sql --conn ws://{addr} --multi --pretty {creds}"); let args = format!("sql --conn ws://{addr} --multi --pretty {creds}");
let input = ""; let input = "";
let output = common::run(&args).input(input).output(); let output = common::run(&args).input(input).output();
assert!(output.is_ok(), "anonymous user should be able to query: {:?}", output); assert!(output.is_ok(), "anonymous user should be able to query: {output:?}");
} }
info!("* Can't do exports"); info!("* Can't do exports");
@ -852,8 +850,7 @@ mod cli_integration {
let output = common::run(&args).output(); let output = common::run(&args).output();
assert!( assert!(
output.clone().unwrap_err().contains("Forbidden"), output.clone().unwrap_err().contains("Forbidden"),
"anonymous user shouldn't be able to export: {:?}", "anonymous user shouldn't be able to export: {output:?}"
output
); );
} }
@ -868,8 +865,7 @@ mod cli_integration {
let output = common::run(&args).output(); let output = common::run(&args).output();
assert!( assert!(
output.clone().unwrap_err().contains("Forbidden"), output.clone().unwrap_err().contains("Forbidden"),
"anonymous user shouldn't be able to import: {:?}", "anonymous user shouldn't be able to import: {output:?}"
output
); );
} }
server.finish().unwrap(); server.finish().unwrap();
@ -1028,7 +1024,7 @@ mod cli_integration {
const WRONG_GLOB_PATTERN: &str = "**/*{.txt"; const WRONG_GLOB_PATTERN: &str = "**/*{.txt";
let args = format!("validate \"{}\"", WRONG_GLOB_PATTERN); let args = format!("validate \"{WRONG_GLOB_PATTERN}\"");
assert!(common::run_in_dir(&args, &temp_dir).output().is_err()); assert!(common::run_in_dir(&args, &temp_dir).output().is_err());
} }
@ -1104,10 +1100,7 @@ mod cli_integration {
tokio::time::timeout(time::Duration::from_secs(10), async { tokio::time::timeout(time::Duration::from_secs(10), async {
loop { loop {
if let Ok(Some(exit)) = server.status() { if let Ok(Some(exit)) = server.status() {
panic!( panic!("Server unexpectedly exited after receiving first SIGINT: {exit:?}");
"Server unexpectedly exited after receiving first SIGINT: {:?}",
exit
);
} }
tokio::time::sleep(time::Duration::from_millis(100)).await; tokio::time::sleep(time::Duration::from_millis(100)).await;
} }
@ -1190,7 +1183,7 @@ mod cli_integration {
throwaway = Ulid::new() throwaway = Ulid::new()
); );
let query = format!("RETURN http::get('http://{}/version');\n\n", addr); let query = format!("RETURN http::get('http://{addr}/version');\n\n");
let output = common::run(&cmd).input(&query).output().unwrap(); let output = common::run(&cmd).input(&query).output().unwrap();
assert!( assert!(
output.contains("Function 'http::get' is not allowed"), output.contains("Function 'http::get' is not allowed"),
@ -1222,7 +1215,7 @@ mod cli_integration {
throwaway = Ulid::new() throwaway = Ulid::new()
); );
let query = format!("RETURN http::get('http://{}/version');\n\n", addr); let query = format!("RETURN http::get('http://{addr}/version');\n\n");
let output = common::run(&cmd).input(&query).output().unwrap(); let output = common::run(&cmd).input(&query).output().unwrap();
assert!(output.contains("['surrealdb-"), "unexpected output: {output:?}"); assert!(output.contains("['surrealdb-"), "unexpected output: {output:?}");
@ -1271,7 +1264,7 @@ mod cli_integration {
throwaway = Ulid::new() throwaway = Ulid::new()
); );
let query = format!("RETURN http::get('http://{}/version');\n\n", addr); let query = format!("RETURN http::get('http://{addr}/version');\n\n");
let output = common::run(&cmd).input(&query).output().unwrap(); let output = common::run(&cmd).input(&query).output().unwrap();
assert!( assert!(
output.contains( output.contains(
@ -1298,7 +1291,7 @@ mod cli_integration {
throwaway = Ulid::new() throwaway = Ulid::new()
); );
let query = format!("RETURN http::get('http://{}/version');\n\n", addr); let query = format!("RETURN http::get('http://{addr}/version');\n\n");
let output = common::run(&cmd).input(&query).output().unwrap(); let output = common::run(&cmd).input(&query).output().unwrap();
assert!(output.contains("['surrealdb-"), "unexpected output: {output:?}"); assert!(output.contains("['surrealdb-"), "unexpected output: {output:?}");
server.finish().unwrap(); server.finish().unwrap();
@ -1412,7 +1405,7 @@ mod cli_integration {
panic!("Should not be ok!"); panic!("Should not be ok!");
} }
Err(e) => { Err(e) => {
assert_eq!(e.to_string(), "server failed to start", "{:?}", e); assert_eq!(e.to_string(), "server failed to start", "{e:?}");
} }
} }
} }
@ -1434,7 +1427,7 @@ mod cli_integration {
panic!("Should not be ok!"); panic!("Should not be ok!");
} }
Err(e) => { Err(e) => {
assert_eq!(e.to_string(), "server failed to start", "{:?}", e); assert_eq!(e.to_string(), "server failed to start", "{e:?}");
} }
} }
temp_file.close().unwrap(); temp_file.close().unwrap();

View file

@ -54,7 +54,7 @@ impl DockerContainer {
if !output.stderr.is_empty() { if !output.stderr.is_empty() {
error!("{}", String::from_utf8(output.stderr).unwrap()); error!("{}", String::from_utf8(output.stderr).unwrap());
} }
assert_eq!(output.status.code(), Some(0), "Docker command failure: {:?}", command); assert_eq!(output.status.code(), Some(0), "Docker command failure: {command:?}");
std_out std_out
} }
} }

View file

@ -10,11 +10,11 @@ impl Expected {
match self { match self {
Expected::Any => {} Expected::Any => {}
Expected::One(expected) => { Expected::One(expected) => {
assert_eq!(results.len(), 1, "Wrong number of result for {}", q); assert_eq!(results.len(), 1, "Wrong number of result for {q}");
Self::check_json(q, &results[0], expected); Self::check_json(q, &results[0], expected);
} }
Expected::Two(expected1, expected2) => { Expected::Two(expected1, expected2) => {
assert_eq!(results.len(), 2, "Wrong number of result for {}", q); assert_eq!(results.len(), 2, "Wrong number of result for {q}");
Self::check_json(q, &results[0], expected1); Self::check_json(q, &results[0], expected1);
Self::check_json(q, &results[1], expected2); Self::check_json(q, &results[1], expected2);
} }
@ -23,6 +23,6 @@ impl Expected {
pub fn check_json(q: &str, result: &JsonValue, expected: &str) { pub fn check_json(q: &str, result: &JsonValue, expected: &str) {
let expected: JsonValue = serde_json::from_str(expected).expect(expected); let expected: JsonValue = serde_json::from_str(expected).expect(expected);
assert_eq!(result, &expected, "Unexpected result on query {}", q); assert_eq!(result, &expected, "Unexpected result on query {q}");
} }
} }

View file

@ -38,7 +38,7 @@ impl Child {
let a = self let a = self
.inner .inner
.as_mut() .as_mut()
.map(|child| child.kill().map_err(|e| format!("failed to kill: {}", e))) .map(|child| child.kill().map_err(|e| format!("failed to kill: {e}")))
.unwrap_or(Err("no inner".to_string())); .unwrap_or(Err("no inner".to_string()));
a.map(|_ok| self) a.map(|_ok| self)
} }
@ -85,10 +85,10 @@ impl Drop for Child {
let _ = inner.kill(); let _ = inner.kill();
let stdout = let stdout =
std::fs::read_to_string(&self.stdout_path).expect("Failed to read the stdout file"); std::fs::read_to_string(&self.stdout_path).expect("Failed to read the stdout file");
println!("Server STDOUT: \n{}", stdout); println!("Server STDOUT: \n{stdout}");
let stderr = let stderr =
std::fs::read_to_string(&self.stderr_path).expect("Failed to read the stderr file"); std::fs::read_to_string(&self.stderr_path).expect("Failed to read the stderr file");
println!("Server STDERR: \n{}", stderr); println!("Server STDERR: \n{stderr}");
} }
let _ = std::fs::remove_file(&self.stdout_path); let _ = std::fs::remove_file(&self.stdout_path);
let _ = std::fs::remove_file(&self.stderr_path); let _ = std::fs::remove_file(&self.stderr_path);

View file

@ -83,7 +83,7 @@ impl Socket {
/// Connect to a WebSocket server using a specific format /// Connect to a WebSocket server using a specific format
pub async fn connect(addr: &str, format: Option<Format>, msg_format: Format) -> Result<Self> { pub async fn connect(addr: &str, format: Option<Format>, msg_format: Format) -> Result<Self> {
let url = format!("ws://{}/rpc", addr); let url = format!("ws://{addr}/rpc");
let mut req = url.into_client_request().unwrap(); let mut req = url.into_client_request().unwrap();
if let Some(v) = format.map(|v| v.to_string()) { if let Some(v) = format.map(|v| v.to_string()) {
req.headers_mut().insert("Sec-WebSocket-Protocol", v.parse().unwrap()); req.headers_mut().insert("Sec-WebSocket-Protocol", v.parse().unwrap());
@ -340,14 +340,13 @@ impl Socket {
.get("result") .get("result")
.ok_or(TestError::AssertionError { .ok_or(TestError::AssertionError {
message: format!( message: format!(
"expected a result from the received object, got this instead: {:?}", "expected a result from the received object, got this instead: {obj:?}"
obj
), ),
})? })?
.to_owned()), .to_owned()),
_ => { _ => {
error!("{:?}", msg.as_object().unwrap().keys().collect::<Vec<_>>()); error!("{:?}", msg.as_object().unwrap().keys().collect::<Vec<_>>());
Err(format!("unexpected response: {:?}", msg).into()) Err(format!("unexpected response: {msg:?}").into())
} }
} }
} }
@ -364,7 +363,7 @@ impl Socket {
Some(obj) if obj.keys().all(|k| ["id", "result"].contains(&k.as_str())) => Ok(obj Some(obj) if obj.keys().all(|k| ["id", "result"].contains(&k.as_str())) => Ok(obj
.get("result") .get("result")
.ok_or(TestError::AssertionError { .ok_or(TestError::AssertionError {
message: format!("expected a result from the received object, got this instead: {:?}", obj), message: format!("expected a result from the received object, got this instead: {obj:?}"),
})? })?
.as_array() .as_array()
.ok_or(TestError::AssertionError { .ok_or(TestError::AssertionError {
@ -373,7 +372,7 @@ impl Socket {
.to_owned()), .to_owned()),
_ => { _ => {
error!("{:?}", msg.as_object().unwrap().keys().collect::<Vec<_>>()); error!("{:?}", msg.as_object().unwrap().keys().collect::<Vec<_>>());
Err(format!("unexpected response: {:?}", msg).into()) Err(format!("unexpected response: {msg:?}").into())
} }
} }
} }
@ -408,7 +407,7 @@ impl Socket {
Some(obj) if obj.keys().all(|k| ["id", "result"].contains(&k.as_str())) => Ok(obj Some(obj) if obj.keys().all(|k| ["id", "result"].contains(&k.as_str())) => Ok(obj
.get("result") .get("result")
.ok_or(TestError::AssertionError { .ok_or(TestError::AssertionError {
message: format!("expected a result from the received object, got this instead: {:?}", obj), message: format!("expected a result from the received object, got this instead: {obj:?}"),
})? })?
.as_str() .as_str()
.ok_or(TestError::AssertionError { .ok_or(TestError::AssertionError {
@ -417,7 +416,7 @@ impl Socket {
.to_owned()), .to_owned()),
_ => { _ => {
error!("{:?}", msg.as_object().unwrap().keys().collect::<Vec<_>>()); error!("{:?}", msg.as_object().unwrap().keys().collect::<Vec<_>>());
Err(format!("unexpected response: {:?}", msg).into()) Err(format!("unexpected response: {msg:?}").into())
} }
} }
} }
@ -439,14 +438,13 @@ impl Socket {
.get("result") .get("result")
.ok_or(TestError::AssertionError { .ok_or(TestError::AssertionError {
message: format!( message: format!(
"expected a result from the received object, got this instead: {:?}", "expected a result from the received object, got this instead: {obj:?}"
obj
), ),
})? })?
.to_owned()), .to_owned()),
_ => { _ => {
error!("{:?}", msg.as_object().unwrap().keys().collect::<Vec<_>>()); error!("{:?}", msg.as_object().unwrap().keys().collect::<Vec<_>>());
Err(format!("unexpected response: {:?}", msg).into()) Err(format!("unexpected response: {msg:?}").into())
} }
} }
} }
@ -473,14 +471,13 @@ impl Socket {
.get("result") .get("result")
.ok_or(TestError::AssertionError { .ok_or(TestError::AssertionError {
message: format!( message: format!(
"expected a result from the received object, got this instead: {:?}", "expected a result from the received object, got this instead: {obj:?}"
obj
), ),
})? })?
.to_owned()), .to_owned()),
_ => { _ => {
error!("{:?}", msg.as_object().unwrap().keys().collect::<Vec<_>>()); error!("{:?}", msg.as_object().unwrap().keys().collect::<Vec<_>>());
Err(format!("unexpected response: {:?}", msg).into()) Err(format!("unexpected response: {msg:?}").into())
} }
} }
} }

View file

@ -14,11 +14,11 @@ async fn ping() -> Result<(), Box<dyn std::error::Error>> {
let socket = Socket::connect(&addr, SERVER, FORMAT).await?; let socket = Socket::connect(&addr, SERVER, FORMAT).await?;
// Send INFO command // Send INFO command
let res = socket.send_request("ping", json!([])).await; let res = socket.send_request("ping", json!([])).await;
assert!(res.is_ok(), "result: {:?}", res); assert!(res.is_ok(), "result: {res:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {:?}", res); assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {res:?}");
// Test passed // Test passed
server.finish().unwrap(); server.finish().unwrap();
Ok(()) Ok(())
@ -63,9 +63,9 @@ async fn info() -> Result<(), Box<dyn std::error::Error>> {
socket.send_message_signin("user", "pass", Some(NS), Some(DB), Some("user")).await?; socket.send_message_signin("user", "pass", Some(NS), Some(DB), Some("user")).await?;
// Send INFO command // Send INFO command
let res = socket.send_request("info", json!([])).await?; let res = socket.send_request("info", json!([])).await?;
assert!(res["result"].is_object(), "result: {:?}", res); assert!(res["result"].is_object(), "result: {res:?}");
let res = res["result"].as_object().unwrap(); let res = res["result"].as_object().unwrap();
assert_eq!(res["user"], "user", "result: {:?}", res); assert_eq!(res["user"], "user", "result: {res:?}");
// Test passed // Test passed
server.finish().unwrap(); server.finish().unwrap();
Ok(()) Ok(())
@ -105,16 +105,16 @@ async fn signup() -> Result<(), Box<dyn std::error::Error>> {
}]), }]),
) )
.await; .await;
assert!(res.is_ok(), "result: {:?}", res); assert!(res.is_ok(), "result: {res:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
// Verify response contains no error // Verify response contains no error
assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {:?}", res); assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {res:?}");
// Verify it returns a token // Verify it returns a token
assert!(res["result"].is_string(), "result: {:?}", res); assert!(res["result"].is_string(), "result: {res:?}");
let res = res["result"].as_str().unwrap(); let res = res["result"].as_str().unwrap();
assert!(res.starts_with("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9"), "result: {}", res); assert!(res.starts_with("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9"), "result: {res}");
// Test passed // Test passed
server.finish().unwrap(); server.finish().unwrap();
Ok(()) Ok(())
@ -156,16 +156,16 @@ async fn signin() -> Result<(), Box<dyn std::error::Error>> {
), ),
) )
.await; .await;
assert!(res.is_ok(), "result: {:?}", res); assert!(res.is_ok(), "result: {res:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
// Verify response contains no error // Verify response contains no error
assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {:?}", res); assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {res:?}");
// Verify it returns a token // Verify it returns a token
assert!(res["result"].is_string(), "result: {:?}", res); assert!(res["result"].is_string(), "result: {res:?}");
let res = res["result"].as_str().unwrap(); let res = res["result"].as_str().unwrap();
assert!(res.starts_with("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9"), "result: {}", res); assert!(res.starts_with("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9"), "result: {res}");
// Send SIGNIN command // Send SIGNIN command
let res = socket let res = socket
.send_request( .send_request(
@ -180,16 +180,16 @@ async fn signin() -> Result<(), Box<dyn std::error::Error>> {
}]), }]),
) )
.await; .await;
assert!(res.is_ok(), "result: {:?}", res); assert!(res.is_ok(), "result: {res:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
// Verify response contains no error // Verify response contains no error
assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {:?}", res); assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {res:?}");
// Verify it returns a token // Verify it returns a token
assert!(res["result"].is_string(), "result: {:?}", res); assert!(res["result"].is_string(), "result: {res:?}");
let res = res["result"].as_str().unwrap(); let res = res["result"].as_str().unwrap();
assert!(res.starts_with("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9"), "result: {}", res); assert!(res.starts_with("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9"), "result: {res}");
// Test passed // Test passed
server.finish().unwrap(); server.finish().unwrap();
Ok(()) Ok(())
@ -207,7 +207,7 @@ async fn invalidate() -> Result<(), Box<dyn std::error::Error>> {
socket.send_message_use(Some(NS), Some(DB)).await?; socket.send_message_use(Some(NS), Some(DB)).await?;
// Verify we have an authenticated session // Verify we have an authenticated session
let res = socket.send_message_query("DEFINE NAMESPACE test").await?; let res = socket.send_message_query("DEFINE NAMESPACE test").await?;
assert_eq!(res[0]["status"], "OK", "result: {:?}", res); assert_eq!(res[0]["status"], "OK", "result: {res:?}");
// Send INVALIDATE command // Send INVALIDATE command
socket.send_request("invalidate", json!([])).await?; socket.send_request("invalidate", json!([])).await?;
// Verify we have an invalidated session // Verify we have an invalidated session
@ -215,7 +215,7 @@ async fn invalidate() -> Result<(), Box<dyn std::error::Error>> {
assert_eq!( assert_eq!(
res["error"]["message"], res["error"]["message"],
"There was a problem with the database: IAM error: Not enough permissions to perform this action", "There was a problem with the database: IAM error: Not enough permissions to perform this action",
"result: {:?}", res "result: {res:?}"
); );
// Test passed // Test passed
server.finish().unwrap(); server.finish().unwrap();
@ -238,7 +238,7 @@ async fn authenticate() -> Result<(), Box<dyn std::error::Error>> {
socket.send_request("authenticate", json!([token,])).await?; socket.send_request("authenticate", json!([token,])).await?;
// Verify we have an authenticated session // Verify we have an authenticated session
let res = socket.send_message_query("DEFINE NAMESPACE test").await?; let res = socket.send_message_query("DEFINE NAMESPACE test").await?;
assert_eq!(res[0]["status"], "OK", "result: {:?}", res); assert_eq!(res[0]["status"], "OK", "result: {res:?}");
// Test passed // Test passed
server.finish().unwrap(); server.finish().unwrap();
Ok(()) Ok(())
@ -260,7 +260,7 @@ async fn letset() -> Result<(), Box<dyn std::error::Error>> {
socket.send_request("set", json!(["set_var", "set_value",])).await?; socket.send_request("set", json!(["set_var", "set_value",])).await?;
// Verify the variables are set // Verify the variables are set
let res = socket.send_message_query("SELECT * FROM $let_var, $set_var").await?; let res = socket.send_message_query("SELECT * FROM $let_var, $set_var").await?;
assert_eq!(res[0]["result"], json!(["let_value", "set_value"]), "result: {:?}", res); assert_eq!(res[0]["result"], json!(["let_value", "set_value"]), "result: {res:?}");
server.finish().unwrap(); server.finish().unwrap();
Ok(()) Ok(())
} }
@ -279,12 +279,12 @@ async fn unset() -> Result<(), Box<dyn std::error::Error>> {
socket.send_request("let", json!(["let_var", "let_value",])).await?; socket.send_request("let", json!(["let_var", "let_value",])).await?;
// Verify the variable is set // Verify the variable is set
let res = socket.send_message_query("SELECT * FROM $let_var").await?; let res = socket.send_message_query("SELECT * FROM $let_var").await?;
assert_eq!(res[0]["result"], json!(["let_value"]), "result: {:?}", res); assert_eq!(res[0]["result"], json!(["let_value"]), "result: {res:?}");
// Send UNSET command // Send UNSET command
socket.send_request("unset", json!(["let_var",])).await?; socket.send_request("unset", json!(["let_var",])).await?;
// Verify the variable is unset // Verify the variable is unset
let res = socket.send_message_query("SELECT * FROM $let_var").await?; let res = socket.send_message_query("SELECT * FROM $let_var").await?;
assert_eq!(res[0]["result"], json!([null]), "result: {:?}", res); assert_eq!(res[0]["result"], json!([null]), "result: {res:?}");
// Test passed // Test passed
server.finish().unwrap(); server.finish().unwrap();
Ok(()) Ok(())
@ -304,12 +304,12 @@ async fn select() -> Result<(), Box<dyn std::error::Error>> {
socket.send_message_query("CREATE tester SET name = 'foo', value = 'bar'").await?; socket.send_message_query("CREATE tester SET name = 'foo', value = 'bar'").await?;
// Send SELECT command // Send SELECT command
let res = socket.send_request("select", json!(["tester",])).await?; let res = socket.send_request("select", json!(["tester",])).await?;
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
assert!(res["result"].is_array(), "result: {:?}", res); assert!(res["result"].is_array(), "result: {res:?}");
let res = res["result"].as_array().unwrap(); let res = res["result"].as_array().unwrap();
assert_eq!(res.len(), 1, "result: {:?}", res); assert_eq!(res.len(), 1, "result: {res:?}");
assert_eq!(res[0]["name"], "foo", "result: {:?}", res); assert_eq!(res[0]["name"], "foo", "result: {res:?}");
assert_eq!(res[0]["value"], "bar", "result: {:?}", res); assert_eq!(res[0]["value"], "bar", "result: {res:?}");
// Test passed // Test passed
server.finish().unwrap(); server.finish().unwrap();
Ok(()) Ok(())
@ -338,19 +338,19 @@ async fn insert() -> Result<(), Box<dyn std::error::Error>> {
]), ]),
) )
.await?; .await?;
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
assert!(res["result"].is_array(), "result: {:?}", res); assert!(res["result"].is_array(), "result: {res:?}");
let res = res["result"].as_array().unwrap(); let res = res["result"].as_array().unwrap();
assert_eq!(res.len(), 1, "result: {:?}", res); assert_eq!(res.len(), 1, "result: {res:?}");
assert_eq!(res[0]["name"], "foo", "result: {:?}", res); assert_eq!(res[0]["name"], "foo", "result: {res:?}");
assert_eq!(res[0]["value"], "bar", "result: {:?}", res); assert_eq!(res[0]["value"], "bar", "result: {res:?}");
// Verify the data was inserted and can be queried // Verify the data was inserted and can be queried
let res = socket.send_message_query("SELECT * FROM tester").await?; let res = socket.send_message_query("SELECT * FROM tester").await?;
assert!(res[0]["result"].is_array(), "result: {:?}", res); assert!(res[0]["result"].is_array(), "result: {res:?}");
let res = res[0]["result"].as_array().unwrap(); let res = res[0]["result"].as_array().unwrap();
assert_eq!(res.len(), 1, "result: {:?}", res); assert_eq!(res.len(), 1, "result: {res:?}");
assert_eq!(res[0]["name"], "foo", "result: {:?}", res); assert_eq!(res[0]["name"], "foo", "result: {res:?}");
assert_eq!(res[0]["value"], "bar", "result: {:?}", res); assert_eq!(res[0]["value"], "bar", "result: {res:?}");
// Test passed // Test passed
server.finish().unwrap(); server.finish().unwrap();
Ok(()) Ok(())
@ -378,17 +378,17 @@ async fn create() -> Result<(), Box<dyn std::error::Error>> {
]), ]),
) )
.await?; .await?;
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
assert!(res["result"].is_array(), "result: {:?}", res); assert!(res["result"].is_array(), "result: {res:?}");
let res = res["result"].as_array().unwrap(); let res = res["result"].as_array().unwrap();
assert_eq!(res.len(), 1, "result: {:?}", res); assert_eq!(res.len(), 1, "result: {res:?}");
assert_eq!(res[0]["value"], "bar", "result: {:?}", res); assert_eq!(res[0]["value"], "bar", "result: {res:?}");
// Verify the data was created // Verify the data was created
let res = socket.send_message_query("SELECT * FROM tester").await?; let res = socket.send_message_query("SELECT * FROM tester").await?;
assert!(res[0]["result"].is_array(), "result: {:?}", res); assert!(res[0]["result"].is_array(), "result: {res:?}");
let res = res[0]["result"].as_array().unwrap(); let res = res[0]["result"].as_array().unwrap();
assert_eq!(res.len(), 1, "result: {:?}", res); assert_eq!(res.len(), 1, "result: {res:?}");
assert_eq!(res[0]["value"], "bar", "result: {:?}", res); assert_eq!(res[0]["value"], "bar", "result: {res:?}");
// Test passed // Test passed
server.finish().unwrap(); server.finish().unwrap();
Ok(()) Ok(())
@ -418,18 +418,18 @@ async fn update() -> Result<(), Box<dyn std::error::Error>> {
]), ]),
) )
.await?; .await?;
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
assert!(res["result"].is_array(), "result: {:?}", res); assert!(res["result"].is_array(), "result: {res:?}");
let res = res["result"].as_array().unwrap(); let res = res["result"].as_array().unwrap();
assert_eq!(res.len(), 1, "result: {:?}", res); assert_eq!(res.len(), 1, "result: {res:?}");
assert_eq!(res[0]["value"], "bar", "result: {:?}", res); assert_eq!(res[0]["value"], "bar", "result: {res:?}");
// Verify the data was updated // Verify the data was updated
let res = socket.send_message_query("SELECT * FROM tester").await?; let res = socket.send_message_query("SELECT * FROM tester").await?;
assert!(res[0]["result"].is_array(), "result: {:?}", res); assert!(res[0]["result"].is_array(), "result: {res:?}");
let res = res[0]["result"].as_array().unwrap(); let res = res[0]["result"].as_array().unwrap();
assert_eq!(res.len(), 1, "result: {:?}", res); assert_eq!(res.len(), 1, "result: {res:?}");
assert_eq!(res[0]["name"], json!(null), "result: {:?}", res); assert_eq!(res[0]["name"], json!(null), "result: {res:?}");
assert_eq!(res[0]["value"], "bar", "result: {:?}", res); assert_eq!(res[0]["value"], "bar", "result: {res:?}");
// Test passed // Test passed
server.finish().unwrap(); server.finish().unwrap();
Ok(()) Ok(())
@ -459,19 +459,19 @@ async fn merge() -> Result<(), Box<dyn std::error::Error>> {
]), ]),
) )
.await?; .await?;
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
assert!(res["result"].is_array(), "result: {:?}", res); assert!(res["result"].is_array(), "result: {res:?}");
let res = res["result"].as_array().unwrap(); let res = res["result"].as_array().unwrap();
assert_eq!(res.len(), 1, "result: {:?}", res); assert_eq!(res.len(), 1, "result: {res:?}");
assert_eq!(res[0]["name"], "foo", "result: {:?}", res); assert_eq!(res[0]["name"], "foo", "result: {res:?}");
assert_eq!(res[0]["value"], "bar", "result: {:?}", res); assert_eq!(res[0]["value"], "bar", "result: {res:?}");
// Verify the data was merged // Verify the data was merged
let res = socket.send_message_query("SELECT * FROM tester").await?; let res = socket.send_message_query("SELECT * FROM tester").await?;
assert!(res[0]["result"].is_array(), "result: {:?}", res); assert!(res[0]["result"].is_array(), "result: {res:?}");
let res = res[0]["result"].as_array().unwrap(); let res = res[0]["result"].as_array().unwrap();
assert_eq!(res.len(), 1, "result: {:?}", res); assert_eq!(res.len(), 1, "result: {res:?}");
assert_eq!(res[0]["name"], "foo", "result: {:?}", res); assert_eq!(res[0]["name"], "foo", "result: {res:?}");
assert_eq!(res[0]["value"], "bar", "result: {:?}", res); assert_eq!(res[0]["value"], "bar", "result: {res:?}");
// Test passed // Test passed
server.finish().unwrap(); server.finish().unwrap();
Ok(()) Ok(())
@ -509,16 +509,16 @@ async fn patch() -> Result<(), Box<dyn std::error::Error>> {
]), ]),
) )
.await?; .await?;
assert!(res["result"].is_object(), "result: {:?}", res); assert!(res["result"].is_object(), "result: {res:?}");
let res = res["result"].as_object().unwrap(); let res = res["result"].as_object().unwrap();
assert_eq!(res.get("value"), Some(json!("bar")).as_ref(), "result: {:?}", res); assert_eq!(res.get("value"), Some(json!("bar")).as_ref(), "result: {res:?}");
// Verify the data was patched // Verify the data was patched
let res = socket.send_message_query("SELECT * FROM tester").await?; let res = socket.send_message_query("SELECT * FROM tester").await?;
assert!(res[0]["result"].is_array(), "result: {:?}", res); assert!(res[0]["result"].is_array(), "result: {res:?}");
let res = res[0]["result"].as_array().unwrap(); let res = res[0]["result"].as_array().unwrap();
assert_eq!(res.len(), 1, "result: {:?}", res); assert_eq!(res.len(), 1, "result: {res:?}");
assert_eq!(res[0]["name"], json!(null), "result: {:?}", res); assert_eq!(res[0]["name"], json!(null), "result: {res:?}");
assert_eq!(res[0]["value"], "bar", "result: {:?}", res); assert_eq!(res[0]["value"], "bar", "result: {res:?}");
// Test passed // Test passed
server.finish().unwrap(); server.finish().unwrap();
Ok(()) Ok(())
@ -538,24 +538,24 @@ async fn delete() -> Result<(), Box<dyn std::error::Error>> {
socket.send_message_query("CREATE tester:id").await?; socket.send_message_query("CREATE tester:id").await?;
// Send DELETE command // Send DELETE command
let res = socket.send_request("delete", json!(["tester"])).await?; let res = socket.send_request("delete", json!(["tester"])).await?;
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
assert!(res["result"].is_array(), "result: {:?}", res); assert!(res["result"].is_array(), "result: {res:?}");
let res = res["result"].as_array().unwrap(); let res = res["result"].as_array().unwrap();
assert_eq!(res.len(), 1, "result: {:?}", res); assert_eq!(res.len(), 1, "result: {res:?}");
assert_eq!(res[0]["id"], "tester:id", "result: {:?}", res); assert_eq!(res[0]["id"], "tester:id", "result: {res:?}");
// Create a test record // Create a test record
socket.send_message_query("CREATE tester:id").await?; socket.send_message_query("CREATE tester:id").await?;
// Send DELETE command // Send DELETE command
let res = socket.send_request("delete", json!(["tester:id"])).await?; let res = socket.send_request("delete", json!(["tester:id"])).await?;
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
assert!(res["result"].is_object(), "result: {:?}", res); assert!(res["result"].is_object(), "result: {res:?}");
let res = res["result"].as_object().unwrap(); let res = res["result"].as_object().unwrap();
assert_eq!(res["id"], "tester:id", "result: {:?}", res); assert_eq!(res["id"], "tester:id", "result: {res:?}");
// Verify the data was merged // Verify the data was merged
let res = socket.send_message_query("SELECT * FROM tester").await?; let res = socket.send_message_query("SELECT * FROM tester").await?;
assert!(res[0]["result"].is_array(), "result: {:?}", res); assert!(res[0]["result"].is_array(), "result: {res:?}");
let res = res[0]["result"].as_array().unwrap(); let res = res[0]["result"].as_array().unwrap();
assert_eq!(res.len(), 0, "result: {:?}", res); assert_eq!(res.len(), 0, "result: {res:?}");
// Test passed // Test passed
server.finish().unwrap(); server.finish().unwrap();
Ok(()) Ok(())
@ -574,15 +574,15 @@ async fn query() -> Result<(), Box<dyn std::error::Error>> {
// Send QUERY command // Send QUERY command
let res = let res =
socket.send_request("query", json!(["CREATE tester; SELECT * FROM tester;",])).await?; socket.send_request("query", json!(["CREATE tester; SELECT * FROM tester;",])).await?;
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
assert!(res["result"].is_array(), "result: {:?}", res); assert!(res["result"].is_array(), "result: {res:?}");
let res = res["result"].as_array().unwrap(); let res = res["result"].as_array().unwrap();
assert_eq!(res.len(), 2, "result: {:?}", res); assert_eq!(res.len(), 2, "result: {res:?}");
// Verify the data was created // Verify the data was created
let res = socket.send_message_query("SELECT * FROM tester").await?; let res = socket.send_message_query("SELECT * FROM tester").await?;
assert!(res[0]["result"].is_array(), "result: {:?}", res); assert!(res[0]["result"].is_array(), "result: {res:?}");
let res = res[0]["result"].as_array().unwrap(); let res = res[0]["result"].as_array().unwrap();
assert_eq!(res.len(), 1, "result: {:?}", res); assert_eq!(res.len(), 1, "result: {res:?}");
// Test passed // Test passed
server.finish().unwrap(); server.finish().unwrap();
Ok(()) Ok(())
@ -596,9 +596,9 @@ async fn version() -> Result<(), Box<dyn std::error::Error>> {
let socket = Socket::connect(&addr, SERVER, FORMAT).await?; let socket = Socket::connect(&addr, SERVER, FORMAT).await?;
// Send version command // Send version command
let res = socket.send_request("version", json!([])).await?; let res = socket.send_request("version", json!([])).await?;
assert!(res["result"].is_string(), "result: {:?}", res); assert!(res["result"].is_string(), "result: {res:?}");
let res = res["result"].as_str().unwrap(); let res = res["result"].as_str().unwrap();
assert!(res.starts_with("surrealdb-"), "result: {}", res); assert!(res.starts_with("surrealdb-"), "result: {res}");
// Test passed // Test passed
server.finish().unwrap(); server.finish().unwrap();
Ok(()) Ok(())
@ -637,7 +637,7 @@ async fn concurrency() -> Result<(), Box<dyn std::error::Error>> {
}, },
)?; )?;
assert!(res.iter().all(|v| v["error"].is_null()), "Unexpected error received: {:#?}", res); assert!(res.iter().all(|v| v["error"].is_null()), "Unexpected error received: {res:#?}");
// Test passed // Test passed
server.finish().unwrap(); server.finish().unwrap();
Ok(()) Ok(())
@ -655,23 +655,23 @@ async fn live() -> Result<(), Box<dyn std::error::Error>> {
socket.send_message_use(Some(NS), Some(DB)).await?; socket.send_message_use(Some(NS), Some(DB)).await?;
// Send LIVE command // Send LIVE command
let res = socket.send_request("live", json!(["tester"])).await?; let res = socket.send_request("live", json!(["tester"])).await?;
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
assert!(res["result"].is_string(), "result: {:?}", res); assert!(res["result"].is_string(), "result: {res:?}");
let live1 = res["result"].as_str().unwrap(); let live1 = res["result"].as_str().unwrap();
// Send QUERY command // Send QUERY command
let res = socket.send_request("query", json!(["LIVE SELECT * FROM tester"])).await?; let res = socket.send_request("query", json!(["LIVE SELECT * FROM tester"])).await?;
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
assert!(res["result"].is_array(), "result: {:?}", res); assert!(res["result"].is_array(), "result: {res:?}");
let res = res["result"].as_array().unwrap(); let res = res["result"].as_array().unwrap();
assert_eq!(res.len(), 1, "result: {:?}", res); assert_eq!(res.len(), 1, "result: {res:?}");
assert!(res[0]["result"].is_string(), "result: {:?}", res); assert!(res[0]["result"].is_string(), "result: {res:?}");
let live2 = res[0]["result"].as_str().unwrap(); let live2 = res[0]["result"].as_str().unwrap();
// Create a new test record // Create a new test record
let res = socket.send_request("query", json!(["CREATE tester:id SET name = 'foo'"])).await?; let res = socket.send_request("query", json!(["CREATE tester:id SET name = 'foo'"])).await?;
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
assert!(res["result"].is_array(), "result: {:?}", res); assert!(res["result"].is_array(), "result: {res:?}");
let res = res["result"].as_array().unwrap(); let res = res["result"].as_array().unwrap();
assert_eq!(res.len(), 1, "result: {:?}", res); assert_eq!(res.len(), 1, "result: {res:?}");
// Wait some time for all messages to arrive, and then search for the notification message // Wait some time for all messages to arrive, and then search for the notification message
let msgs: Result<_, Box<dyn std::error::Error>> = let msgs: Result<_, Box<dyn std::error::Error>> =
tokio::time::timeout(Duration::from_secs(1), async { tokio::time::timeout(Duration::from_secs(1), async {
@ -679,32 +679,32 @@ async fn live() -> Result<(), Box<dyn std::error::Error>> {
}) })
.await?; .await?;
let msgs = msgs?; let msgs = msgs?;
assert!(msgs.iter().all(|v| v["error"].is_null()), "Unexpected error received: {:?}", msgs); assert!(msgs.iter().all(|v| v["error"].is_null()), "Unexpected error received: {msgs:?}");
// Check for first live query notifcation // Check for first live query notifcation
let res = msgs.iter().find(|v| common::is_notification_from_lq(v, live1)); let res = msgs.iter().find(|v| common::is_notification_from_lq(v, live1));
assert!(res.is_some(), "Expected to find a notification for LQ id {}: {:?}", live1, msgs); assert!(res.is_some(), "Expected to find a notification for LQ id {live1}: {msgs:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
assert!(res["result"].is_object(), "result: {:?}", res); assert!(res["result"].is_object(), "result: {res:?}");
let res = res["result"].as_object().unwrap(); let res = res["result"].as_object().unwrap();
assert!(res["action"].is_string(), "result: {:?}", res); assert!(res["action"].is_string(), "result: {res:?}");
assert_eq!(res["action"], "CREATE", "result: {:?}", res); assert_eq!(res["action"], "CREATE", "result: {res:?}");
assert!(res["result"].is_object(), "result: {:?}", res); assert!(res["result"].is_object(), "result: {res:?}");
let res = res["result"].as_object().unwrap(); let res = res["result"].as_object().unwrap();
assert_eq!(res["id"], "tester:id", "result: {:?}", res); assert_eq!(res["id"], "tester:id", "result: {res:?}");
// Check for second live query notifcation // Check for second live query notifcation
let res = msgs.iter().find(|v| common::is_notification_from_lq(v, live2)); let res = msgs.iter().find(|v| common::is_notification_from_lq(v, live2));
assert!(res.is_some(), "Expected to find a notification for LQ id {}: {:?}", live2, msgs); assert!(res.is_some(), "Expected to find a notification for LQ id {live2}: {msgs:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
assert!(res["result"].is_object(), "result: {:?}", res); assert!(res["result"].is_object(), "result: {res:?}");
let res = res["result"].as_object().unwrap(); let res = res["result"].as_object().unwrap();
assert_eq!(res["action"], "CREATE", "result: {:?}", res); assert_eq!(res["action"], "CREATE", "result: {res:?}");
assert!(res["result"].is_object(), "result: {:?}", res); assert!(res["result"].is_object(), "result: {res:?}");
let res = res["result"].as_object().unwrap(); let res = res["result"].as_object().unwrap();
assert_eq!(res["id"], "tester:id", "result: {:?}", res); assert_eq!(res["id"], "tester:id", "result: {res:?}");
// Test passed // Test passed
server.finish().unwrap(); server.finish().unwrap();
Ok(()) Ok(())
@ -722,92 +722,92 @@ async fn kill() -> Result<(), Box<dyn std::error::Error>> {
socket.send_message_use(Some(NS), Some(DB)).await?; socket.send_message_use(Some(NS), Some(DB)).await?;
// Send LIVE command // Send LIVE command
let res = socket.send_request("live", json!(["tester"])).await?; let res = socket.send_request("live", json!(["tester"])).await?;
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
assert!(res["result"].is_string(), "result: {:?}", res); assert!(res["result"].is_string(), "result: {res:?}");
let live1 = res["result"].as_str().unwrap(); let live1 = res["result"].as_str().unwrap();
// Send QUERY command // Send QUERY command
let res = socket.send_request("query", json!(["LIVE SELECT * FROM tester"])).await?; let res = socket.send_request("query", json!(["LIVE SELECT * FROM tester"])).await?;
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
assert!(res["result"].is_array(), "result: {:?}", res); assert!(res["result"].is_array(), "result: {res:?}");
let res = res["result"].as_array().unwrap(); let res = res["result"].as_array().unwrap();
assert_eq!(res.len(), 1, "result: {:?}", res); assert_eq!(res.len(), 1, "result: {res:?}");
assert!(res[0]["result"].is_string(), "result: {:?}", res); assert!(res[0]["result"].is_string(), "result: {res:?}");
let live2 = res[0]["result"].as_str().unwrap(); let live2 = res[0]["result"].as_str().unwrap();
// Create a new test record // Create a new test record
let res = socket.send_request("query", json!(["CREATE tester:one SET name = 'one'"])).await?; let res = socket.send_request("query", json!(["CREATE tester:one SET name = 'one'"])).await?;
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
assert!(res["result"].is_array(), "result: {:?}", res); assert!(res["result"].is_array(), "result: {res:?}");
let res = res["result"].as_array().unwrap(); let res = res["result"].as_array().unwrap();
assert_eq!(res.len(), 1, "result: {:?}", res); assert_eq!(res.len(), 1, "result: {res:?}");
// Wait some time for all messages to arrive, and then search for the notification message // Wait some time for all messages to arrive, and then search for the notification message
let msgs = socket.receive_all_other_messages(2, Duration::from_secs(1)).await?; let msgs = socket.receive_all_other_messages(2, Duration::from_secs(1)).await?;
assert!(msgs.iter().all(|v| v["error"].is_null()), "Unexpected error received: {:?}", msgs); assert!(msgs.iter().all(|v| v["error"].is_null()), "Unexpected error received: {msgs:?}");
// Check for first live query notifcation // Check for first live query notifcation
let res = msgs.iter().find(|v| common::is_notification_from_lq(v, live1)); let res = msgs.iter().find(|v| common::is_notification_from_lq(v, live1));
assert!(res.is_some(), "Expected to find a notification for LQ id {}: {:?}", live1, msgs); assert!(res.is_some(), "Expected to find a notification for LQ id {live1}: {msgs:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
assert!(res["result"].is_object(), "result: {:?}", res); assert!(res["result"].is_object(), "result: {res:?}");
let res = res["result"].as_object().unwrap(); let res = res["result"].as_object().unwrap();
assert!(res["action"].is_string(), "result: {:?}", res); assert!(res["action"].is_string(), "result: {res:?}");
assert_eq!(res["action"], "CREATE", "result: {:?}", res); assert_eq!(res["action"], "CREATE", "result: {res:?}");
assert!(res["result"].is_object(), "result: {:?}", res); assert!(res["result"].is_object(), "result: {res:?}");
let res = res["result"].as_object().unwrap(); let res = res["result"].as_object().unwrap();
assert_eq!(res["id"], "tester:one", "result: {:?}", res); assert_eq!(res["id"], "tester:one", "result: {res:?}");
// Check for second live query notifcation // Check for second live query notifcation
let res = msgs.iter().find(|v| common::is_notification_from_lq(v, live2)); let res = msgs.iter().find(|v| common::is_notification_from_lq(v, live2));
assert!(res.is_some(), "Expected to find a notification for LQ id {}: {:?}", live2, msgs); assert!(res.is_some(), "Expected to find a notification for LQ id {live2}: {msgs:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
assert!(res["result"].is_object(), "result: {:?}", res); assert!(res["result"].is_object(), "result: {res:?}");
let res = res["result"].as_object().unwrap(); let res = res["result"].as_object().unwrap();
assert_eq!(res["action"], "CREATE", "result: {:?}", res); assert_eq!(res["action"], "CREATE", "result: {res:?}");
assert!(res["result"].is_object(), "result: {:?}", res); assert!(res["result"].is_object(), "result: {res:?}");
let res = res["result"].as_object().unwrap(); let res = res["result"].as_object().unwrap();
assert_eq!(res["id"], "tester:one", "result: {:?}", res); assert_eq!(res["id"], "tester:one", "result: {res:?}");
// Send KILL command // Send KILL command
let res = socket.send_request("kill", json!([live1])).await?; let res = socket.send_request("kill", json!([live1])).await?;
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
assert!(res["result"].is_null(), "result: {:?}", res); assert!(res["result"].is_null(), "result: {res:?}");
// Create a new test record // Create a new test record
let res = socket.send_request("query", json!(["CREATE tester:two SET name = 'two'"])).await?; let res = socket.send_request("query", json!(["CREATE tester:two SET name = 'two'"])).await?;
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
assert!(res["result"].is_array(), "result: {:?}", res); assert!(res["result"].is_array(), "result: {res:?}");
let res = res["result"].as_array().unwrap(); let res = res["result"].as_array().unwrap();
assert_eq!(res.len(), 1, "result: {:?}", res); assert_eq!(res.len(), 1, "result: {res:?}");
// Wait some time for all messages to arrive, and then search for the notification message // Wait some time for all messages to arrive, and then search for the notification message
let msgs = socket.receive_all_other_messages(1, Duration::from_secs(1)).await?; let msgs = socket.receive_all_other_messages(1, Duration::from_secs(1)).await?;
assert!(msgs.iter().all(|v| v["error"].is_null()), "Unexpected error received: {:?}", msgs); assert!(msgs.iter().all(|v| v["error"].is_null()), "Unexpected error received: {msgs:?}");
// Check for second live query notifcation // Check for second live query notifcation
let res = msgs.iter().find(|v| common::is_notification_from_lq(v, live2)); let res = msgs.iter().find(|v| common::is_notification_from_lq(v, live2));
assert!(res.is_some(), "Expected to find a notification for LQ id {}: {:?}", live2, msgs); assert!(res.is_some(), "Expected to find a notification for LQ id {live2}: {msgs:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
assert!(res["result"].is_object(), "result: {:?}", res); assert!(res["result"].is_object(), "result: {res:?}");
let res = res["result"].as_object().unwrap(); let res = res["result"].as_object().unwrap();
assert_eq!(res["action"], "CREATE", "result: {:?}", res); assert_eq!(res["action"], "CREATE", "result: {res:?}");
assert!(res["result"].is_object(), "result: {:?}", res); assert!(res["result"].is_object(), "result: {res:?}");
let res = res["result"].as_object().unwrap(); let res = res["result"].as_object().unwrap();
assert_eq!(res["id"], "tester:two", "result: {:?}", res); assert_eq!(res["id"], "tester:two", "result: {res:?}");
// Send QUERY command // Send QUERY command
let res = socket.send_request("query", json!([format!("KILL u'{live2}'")])).await?; let res = socket.send_request("query", json!([format!("KILL u'{live2}'")])).await?;
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
assert!(res["result"].is_array(), "result: {:?}", res); assert!(res["result"].is_array(), "result: {res:?}");
let res = res["result"].as_array().unwrap(); let res = res["result"].as_array().unwrap();
assert_eq!(res.len(), 1, "result: {:?}", res); assert_eq!(res.len(), 1, "result: {res:?}");
assert!(res[0]["result"].is_null(), "result: {:?}", res); assert!(res[0]["result"].is_null(), "result: {res:?}");
// Create a new test record // Create a new test record
let res = socket.send_request("query", json!(["CREATE tester:tre SET name = 'two'"])).await?; let res = socket.send_request("query", json!(["CREATE tester:tre SET name = 'two'"])).await?;
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
assert!(res["result"].is_array(), "result: {:?}", res); assert!(res["result"].is_array(), "result: {res:?}");
let res = res["result"].as_array().unwrap(); let res = res["result"].as_array().unwrap();
assert_eq!(res.len(), 1, "result: {:?}", res); assert_eq!(res.len(), 1, "result: {res:?}");
// Wait some time for all messages to arrive, and then search for the notification message // Wait some time for all messages to arrive, and then search for the notification message
let msgs = socket.receive_all_other_messages(0, Duration::from_secs(1)).await?; let msgs = socket.receive_all_other_messages(0, Duration::from_secs(1)).await?;
assert!(msgs.iter().all(|v| v["error"].is_null()), "Unexpected error received: {:?}", msgs); assert!(msgs.iter().all(|v| v["error"].is_null()), "Unexpected error received: {msgs:?}");
// Test passed // Test passed
server.finish().unwrap(); server.finish().unwrap();
Ok(()) Ok(())
@ -825,8 +825,8 @@ async fn live_second_connection() -> Result<(), Box<dyn std::error::Error>> {
socket1.send_message_use(Some(NS), Some(DB)).await?; socket1.send_message_use(Some(NS), Some(DB)).await?;
// Send LIVE command // Send LIVE command
let res = socket1.send_request("live", json!(["tester"])).await?; let res = socket1.send_request("live", json!(["tester"])).await?;
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
assert!(res["result"].is_string(), "result: {:?}", res); assert!(res["result"].is_string(), "result: {res:?}");
let liveid = res["result"].as_str().unwrap(); let liveid = res["result"].as_str().unwrap();
// Connect to WebSocket // Connect to WebSocket
let mut socket2 = Socket::connect(&addr, SERVER, FORMAT).await?; let mut socket2 = Socket::connect(&addr, SERVER, FORMAT).await?;
@ -836,26 +836,26 @@ async fn live_second_connection() -> Result<(), Box<dyn std::error::Error>> {
socket2.send_message_use(Some(NS), Some(DB)).await?; socket2.send_message_use(Some(NS), Some(DB)).await?;
// Create a new test record // Create a new test record
let res = socket2.send_request("query", json!(["CREATE tester:id SET name = 'foo'"])).await?; let res = socket2.send_request("query", json!(["CREATE tester:id SET name = 'foo'"])).await?;
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
assert!(res["result"].is_array(), "result: {:?}", res); assert!(res["result"].is_array(), "result: {res:?}");
let res = res["result"].as_array().unwrap(); let res = res["result"].as_array().unwrap();
assert_eq!(res.len(), 1, "result: {:?}", res); assert_eq!(res.len(), 1, "result: {res:?}");
// Wait some time for all messages to arrive, and then search for the notification message // Wait some time for all messages to arrive, and then search for the notification message
let msgs = socket1.receive_all_other_messages(1, Duration::from_secs(1)).await?; let msgs = socket1.receive_all_other_messages(1, Duration::from_secs(1)).await?;
assert!(msgs.iter().all(|v| v["error"].is_null()), "Unexpected error received: {:?}", msgs); assert!(msgs.iter().all(|v| v["error"].is_null()), "Unexpected error received: {msgs:?}");
// Check for live query notifcation // Check for live query notifcation
let res = msgs.iter().find(|v| common::is_notification_from_lq(v, liveid)); let res = msgs.iter().find(|v| common::is_notification_from_lq(v, liveid));
assert!(res.is_some(), "Expected to find a notification for LQ id {}: {:?}", liveid, msgs); assert!(res.is_some(), "Expected to find a notification for LQ id {liveid}: {msgs:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
assert!(res["result"].is_object(), "result: {:?}", res); assert!(res["result"].is_object(), "result: {res:?}");
let res = res["result"].as_object().unwrap(); let res = res["result"].as_object().unwrap();
assert!(res["action"].is_string(), "result: {:?}", res); assert!(res["action"].is_string(), "result: {res:?}");
assert_eq!(res["action"], "CREATE", "result: {:?}", res); assert_eq!(res["action"], "CREATE", "result: {res:?}");
assert!(res["result"].is_object(), "result: {:?}", res); assert!(res["result"].is_object(), "result: {res:?}");
let res = res["result"].as_object().unwrap(); let res = res["result"].as_object().unwrap();
assert_eq!(res["id"], "tester:id", "result: {:?}", res); assert_eq!(res["id"], "tester:id", "result: {res:?}");
// Test passed // Test passed
server.finish().unwrap(); server.finish().unwrap();
Ok(()) Ok(())
@ -897,31 +897,31 @@ async fn variable_auth_live_query() -> Result<(), Box<dyn std::error::Error>> {
}]), }]),
) )
.await; .await;
assert!(res.is_ok(), "result: {:?}", res); assert!(res.is_ok(), "result: {res:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
// Verify response contains no error // Verify response contains no error
assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {:?}", res); assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {res:?}");
// Authenticate the connection // Authenticate the connection
socket_expiring_auth.send_message_signin(USER, PASS, None, None, None).await?; socket_expiring_auth.send_message_signin(USER, PASS, None, None, None).await?;
// Send LIVE command // Send LIVE command
let res = socket_expiring_auth.send_request("live", json!(["tester"])).await?; let res = socket_expiring_auth.send_request("live", json!(["tester"])).await?;
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
assert!(res["result"].is_string(), "result: {:?}", res); assert!(res["result"].is_string(), "result: {res:?}");
// Wait 2 seconds for auth to expire // Wait 2 seconds for auth to expire
tokio::time::sleep(Duration::from_secs(1)).await; tokio::time::sleep(Duration::from_secs(1)).await;
// Create a new test record // Create a new test record
let res = socket_permanent let res = socket_permanent
.send_request("query", json!(["CREATE tester:id SET name = 'foo'"])) .send_request("query", json!(["CREATE tester:id SET name = 'foo'"]))
.await?; .await?;
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
assert!(res["result"].is_array(), "result: {:?}", res); assert!(res["result"].is_array(), "result: {res:?}");
let res = res["result"].as_array().unwrap(); let res = res["result"].as_array().unwrap();
assert_eq!(res.len(), 1, "result: {:?}", res); assert_eq!(res.len(), 1, "result: {res:?}");
// Wait some time for all messages to arrive, and then search for the notification message // Wait some time for all messages to arrive, and then search for the notification message
let msgs = socket_expiring_auth.receive_all_other_messages(0, Duration::from_secs(1)).await?; let msgs = socket_expiring_auth.receive_all_other_messages(0, Duration::from_secs(1)).await?;
assert!(msgs.iter().all(|v| v["error"].is_null()), "Unexpected error received: {:?}", msgs); assert!(msgs.iter().all(|v| v["error"].is_null()), "Unexpected error received: {msgs:?}");
// Test passed // Test passed
server.finish().unwrap(); server.finish().unwrap();
Ok(()) Ok(())
@ -982,28 +982,28 @@ async fn session_expiration() {
), ),
) )
.await; .await;
assert!(res.is_ok(), "result: {:?}", res); assert!(res.is_ok(), "result: {res:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
// Verify response contains no error // Verify response contains no error
assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {:?}", res); assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {res:?}");
// Verify it returns a token // Verify it returns a token
assert!(res["result"].is_string(), "result: {:?}", res); assert!(res["result"].is_string(), "result: {res:?}");
let res = res["result"].as_str().unwrap(); let res = res["result"].as_str().unwrap();
assert!(res.starts_with("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9"), "result: {}", res); assert!(res.starts_with("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9"), "result: {res}");
// Authenticate using the token, which expires in a day // Authenticate using the token, which expires in a day
socket.send_request("authenticate", json!([res,])).await.unwrap(); socket.send_request("authenticate", json!([res,])).await.unwrap();
// Check if the session is now authenticated // Check if the session is now authenticated
let res = socket.send_message_query("SELECT VALUE working FROM test:1").await.unwrap(); let res = socket.send_message_query("SELECT VALUE working FROM test:1").await.unwrap();
assert_eq!(res[0]["result"], json!(["yes"]), "result: {:?}", res); assert_eq!(res[0]["result"], json!(["yes"]), "result: {res:?}");
// Wait two seconds for the session to expire // Wait two seconds for the session to expire
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await; tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
// Check that the session has expired and queries fail // Check that the session has expired and queries fail
let res = socket.send_request("query", json!(["SELECT VALUE working FROM test:1",])).await; let res = socket.send_request("query", json!(["SELECT VALUE working FROM test:1",])).await;
assert!(res.is_ok(), "result: {:?}", res); assert!(res.is_ok(), "result: {res:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
assert_eq!( assert_eq!(
res["error"], res["error"],
@ -1024,15 +1024,15 @@ async fn session_expiration() {
), ),
) )
.await; .await;
assert!(res.is_ok(), "result: {:?}", res); assert!(res.is_ok(), "result: {res:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
// Verify response contains no error // Verify response contains no error
assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {:?}", res); assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {res:?}");
// Check that the session is now valid again and queries succeed // Check that the session is now valid again and queries succeed
let res = socket.send_message_query("SELECT VALUE working FROM test:1").await.unwrap(); let res = socket.send_message_query("SELECT VALUE working FROM test:1").await.unwrap();
assert_eq!(res[0]["result"], json!(["yes"]), "result: {:?}", res); assert_eq!(res[0]["result"], json!(["yes"]), "result: {res:?}");
// Test passed // Test passed
server.finish().unwrap(); server.finish().unwrap();
} }
@ -1093,28 +1093,28 @@ async fn session_expiration_operations() {
), ),
) )
.await; .await;
assert!(res.is_ok(), "result: {:?}", res); assert!(res.is_ok(), "result: {res:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
// Verify response contains no error // Verify response contains no error
assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {:?}", res); assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {res:?}");
// Verify it returns a token // Verify it returns a token
assert!(res["result"].is_string(), "result: {:?}", res); assert!(res["result"].is_string(), "result: {res:?}");
let res = res["result"].as_str().unwrap(); let res = res["result"].as_str().unwrap();
assert!(res.starts_with("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9"), "result: {}", res); assert!(res.starts_with("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9"), "result: {res}");
// Authenticate using the token, which expires in a day // Authenticate using the token, which expires in a day
socket.send_request("authenticate", json!([res,])).await.unwrap(); socket.send_request("authenticate", json!([res,])).await.unwrap();
// Check if the session is now authenticated // Check if the session is now authenticated
let res = socket.send_message_query("SELECT VALUE working FROM test:1").await.unwrap(); let res = socket.send_message_query("SELECT VALUE working FROM test:1").await.unwrap();
assert_eq!(res[0]["result"], json!(["yes"]), "result: {:?}", res); assert_eq!(res[0]["result"], json!(["yes"]), "result: {res:?}");
// Wait two seconds for the session to expire // Wait two seconds for the session to expire
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await; tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
// Check if the session is now expired // Check if the session is now expired
let res = socket.send_request("query", json!(["SELECT VALUE working FROM test:1",])).await; let res = socket.send_request("query", json!(["SELECT VALUE working FROM test:1",])).await;
assert!(res.is_ok(), "result: {:?}", res); assert!(res.is_ok(), "result: {res:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
assert_eq!( assert_eq!(
res["error"], res["error"],
@ -1187,9 +1187,9 @@ async fn session_expiration_operations() {
// Futures are executed sequentially as some operations rely on the previous state // Futures are executed sequentially as some operations rely on the previous state
for operation in operations_ko { for operation in operations_ko {
let res = operation.await; let res = operation.await;
assert!(res.is_ok(), "result: {:?}", res); assert!(res.is_ok(), "result: {res:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
assert_eq!( assert_eq!(
res["error"], res["error"],
@ -1207,12 +1207,12 @@ async fn session_expiration_operations() {
// Futures are executed sequentially as some operations rely on the previous state // Futures are executed sequentially as some operations rely on the previous state
for operation in operations_ok { for operation in operations_ok {
let res = operation.await; let res = operation.await;
assert!(res.is_ok(), "result: {:?}", res); assert!(res.is_ok(), "result: {res:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
// Verify response contains no error // Verify response contains no error
assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {:?}", res); assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {res:?}");
} }
// Test operations that SHOULD work with an expired session // Test operations that SHOULD work with an expired session
@ -1229,19 +1229,19 @@ async fn session_expiration_operations() {
}]), }]),
) )
.await; .await;
assert!(res.is_ok(), "result: {:?}", res); assert!(res.is_ok(), "result: {res:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
// Verify response contains no error // Verify response contains no error
assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {:?}", res); assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {res:?}");
// Wait two seconds for the session to expire // Wait two seconds for the session to expire
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await; tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
// The session must be expired now or we fail the test // The session must be expired now or we fail the test
let res = socket.send_request("query", json!(["SELECT VALUE working FROM test:1",])).await; let res = socket.send_request("query", json!(["SELECT VALUE working FROM test:1",])).await;
assert!(res.is_ok(), "result: {:?}", res); assert!(res.is_ok(), "result: {res:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
assert_eq!( assert_eq!(
res["error"], res["error"],
@ -1261,19 +1261,19 @@ async fn session_expiration_operations() {
), ),
) )
.await; .await;
assert!(res.is_ok(), "result: {:?}", res); assert!(res.is_ok(), "result: {res:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
// Verify response contains no error // Verify response contains no error
assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {:?}", res); assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {res:?}");
// Wait two seconds for the session to expire // Wait two seconds for the session to expire
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await; tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
// The session must be expired now or we fail the test // The session must be expired now or we fail the test
let res = socket.send_request("query", json!(["SELECT VALUE working FROM test:1",])).await; let res = socket.send_request("query", json!(["SELECT VALUE working FROM test:1",])).await;
assert!(res.is_ok(), "result: {:?}", res); assert!(res.is_ok(), "result: {res:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
assert_eq!( assert_eq!(
res["error"], res["error"],
@ -1282,12 +1282,12 @@ async fn session_expiration_operations() {
// This needs to be last operation as the session will no longer expire afterwards // This needs to be last operation as the session will no longer expire afterwards
let res = socket.send_request("authenticate", json!([root_token,])).await; let res = socket.send_request("authenticate", json!([root_token,])).await;
assert!(res.is_ok(), "result: {:?}", res); assert!(res.is_ok(), "result: {res:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
// Verify response contains no error // Verify response contains no error
assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {:?}", res); assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {res:?}");
// Test passed // Test passed
server.finish().unwrap(); server.finish().unwrap();
@ -1350,34 +1350,33 @@ async fn session_reauthentication() {
), ),
) )
.await; .await;
assert!(res.is_ok(), "result: {:?}", res); assert!(res.is_ok(), "result: {res:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
// Verify response contains no error // Verify response contains no error
assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {:?}", res); assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {res:?}");
// Verify it returns a token // Verify it returns a token
assert!(res["result"].is_string(), "result: {:?}", res); assert!(res["result"].is_string(), "result: {res:?}");
let res = res["result"].as_str().unwrap(); let res = res["result"].as_str().unwrap();
assert!(res.starts_with("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9"), "result: {}", res); assert!(res.starts_with("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9"), "result: {res}");
// Authenticate using the token // Authenticate using the token
socket.send_request("authenticate", json!([res,])).await.unwrap(); socket.send_request("authenticate", json!([res,])).await.unwrap();
// Check that we do not have root access // Check that we do not have root access
let res = socket.send_message_query("INFO FOR ROOT").await.unwrap(); let res = socket.send_message_query("INFO FOR ROOT").await.unwrap();
assert_eq!(res[0]["status"], "ERR", "result: {:?}", res); assert_eq!(res[0]["status"], "ERR", "result: {res:?}");
assert_eq!( assert_eq!(
res[0]["result"], "IAM error: Not enough permissions to perform this action", res[0]["result"], "IAM error: Not enough permissions to perform this action",
"result: {:?}", "result: {res:?}"
res
); );
// Check if the session is authenticated // Check if the session is authenticated
let res = socket.send_message_query("SELECT VALUE working FROM test:1").await.unwrap(); let res = socket.send_message_query("SELECT VALUE working FROM test:1").await.unwrap();
assert_eq!(res[0]["result"], json!(["yes"]), "result: {:?}", res); assert_eq!(res[0]["result"], json!(["yes"]), "result: {res:?}");
// Authenticate using the root token // Authenticate using the root token
socket.send_request("authenticate", json!([root_token,])).await.unwrap(); socket.send_request("authenticate", json!([root_token,])).await.unwrap();
// Check that we have root access again // Check that we have root access again
let res = socket.send_message_query("INFO FOR ROOT").await.unwrap(); let res = socket.send_message_query("INFO FOR ROOT").await.unwrap();
assert_eq!(res[0]["status"], "OK", "result: {:?}", res); assert_eq!(res[0]["status"], "OK", "result: {res:?}");
// Test passed // Test passed
server.finish().unwrap(); server.finish().unwrap();
} }
@ -1439,25 +1438,25 @@ async fn session_reauthentication_expired() {
), ),
) )
.await; .await;
assert!(res.is_ok(), "result: {:?}", res); assert!(res.is_ok(), "result: {res:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
// Verify response contains no error // Verify response contains no error
assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {:?}", res); assert!(res.keys().all(|k| ["id", "result"].contains(&k.as_str())), "result: {res:?}");
// Verify it returns a token // Verify it returns a token
assert!(res["result"].is_string(), "result: {:?}", res); assert!(res["result"].is_string(), "result: {res:?}");
let res = res["result"].as_str().unwrap(); let res = res["result"].as_str().unwrap();
assert!(res.starts_with("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9"), "result: {}", res); assert!(res.starts_with("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9"), "result: {res}");
// Authenticate using the token, which will expire soon // Authenticate using the token, which will expire soon
socket.send_request("authenticate", json!([res,])).await.unwrap(); socket.send_request("authenticate", json!([res,])).await.unwrap();
// Wait two seconds for token to expire // Wait two seconds for token to expire
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await; tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
// Verify that the session has expired // Verify that the session has expired
let res = socket.send_request("query", json!(["SELECT VALUE working FROM test:1",])).await; let res = socket.send_request("query", json!(["SELECT VALUE working FROM test:1",])).await;
assert!(res.is_ok(), "result: {:?}", res); assert!(res.is_ok(), "result: {res:?}");
let res = res.unwrap(); let res = res.unwrap();
assert!(res.is_object(), "result: {:?}", res); assert!(res.is_object(), "result: {res:?}");
let res = res.as_object().unwrap(); let res = res.as_object().unwrap();
assert_eq!( assert_eq!(
res["error"], res["error"],
@ -1467,7 +1466,7 @@ async fn session_reauthentication_expired() {
socket.send_request("authenticate", json!([root_token,])).await.unwrap(); socket.send_request("authenticate", json!([root_token,])).await.unwrap();
// Check that we have root access and the session is not expired // Check that we have root access and the session is not expired
let res = socket.send_message_query("INFO FOR ROOT").await.unwrap(); let res = socket.send_message_query("INFO FOR ROOT").await.unwrap();
assert_eq!(res[0]["status"], "OK", "result: {:?}", res); assert_eq!(res[0]["status"], "OK", "result: {res:?}");
// Test passed // Test passed
server.finish().unwrap(); server.finish().unwrap();
} }

View file

@ -328,7 +328,7 @@ mod database_upgrade {
} }
async fn new_local_instance(file_path: &String) -> Surreal<Any> { async fn new_local_instance(file_path: &String) -> Surreal<Any> {
let db = connect(format!("file:{}", file_path)).await.unwrap(); let db = connect(format!("file:{file_path}")).await.unwrap();
db.use_ns(NS).await.unwrap(); db.use_ns(NS).await.unwrap();
db.use_db(DB).await.unwrap(); db.use_db(DB).await.unwrap();
db db

View file

@ -35,7 +35,7 @@ mod http_integration {
let res = client.post(url).body("CREATE foo").send().await?; let res = client.post(url).body("CREATE foo").send().await?;
assert_eq!(res.status(), 200); assert_eq!(res.status(), 200);
let body = res.text().await?; let body = res.text().await?;
assert!(body.contains("Not enough permissions"), "body: {}", body); assert!(body.contains("Not enough permissions"), "body: {body}");
} }
// Request with invalid credentials, returns 401 // Request with invalid credentials, returns 401
@ -51,7 +51,7 @@ mod http_integration {
client.post(url).basic_auth(USER, Some(PASS)).body("CREATE foo").send().await?; client.post(url).basic_auth(USER, Some(PASS)).body("CREATE foo").send().await?;
assert_eq!(res.status(), 200); assert_eq!(res.status(), 200);
let body = res.text().await?; let body = res.text().await?;
assert!(body.contains(r#"[{"result":[{"id":"foo:"#), "body: {}", body); assert!(body.contains(r#"[{"result":[{"id":"foo:"#), "body: {body}");
} }
// Prepare users with identical credentials on ROOT, NAMESPACE and DATABASE levels // Prepare users with identical credentials on ROOT, NAMESPACE and DATABASE levels
@ -71,7 +71,7 @@ mod http_integration {
client.post(url).basic_auth(USER, Some(PASS)).body("INFO FOR ROOT").send().await?; client.post(url).basic_auth(USER, Some(PASS)).body("INFO FOR ROOT").send().await?;
assert_eq!(res.status(), 200); assert_eq!(res.status(), 200);
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["status"], "OK", "body: {}", body); assert_eq!(body[0]["status"], "OK", "body: {body}");
} }
// Request with ROOT level access to access NS, returns 200 and succeeds // Request with ROOT level access to access NS, returns 200 and succeeds
@ -80,7 +80,7 @@ mod http_integration {
client.post(url).basic_auth(USER, Some(PASS)).body("INFO FOR NS").send().await?; client.post(url).basic_auth(USER, Some(PASS)).body("INFO FOR NS").send().await?;
assert_eq!(res.status(), 200); assert_eq!(res.status(), 200);
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["status"], "OK", "body: {}", body); assert_eq!(body[0]["status"], "OK", "body: {body}");
} }
// Request with ROOT level access to access DB, returns 200 and succeeds // Request with ROOT level access to access DB, returns 200 and succeeds
@ -89,7 +89,7 @@ mod http_integration {
client.post(url).basic_auth(USER, Some(PASS)).body("INFO FOR DB").send().await?; client.post(url).basic_auth(USER, Some(PASS)).body("INFO FOR DB").send().await?;
assert_eq!(res.status(), 200); assert_eq!(res.status(), 200);
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["status"], "OK", "body: {}", body); assert_eq!(body[0]["status"], "OK", "body: {body}");
} }
// Request with NS level access to access ROOT, returns 200 but fails // Request with NS level access to access ROOT, returns 200 but fails
@ -103,11 +103,10 @@ mod http_integration {
.await?; .await?;
assert_eq!(res.status(), 200); assert_eq!(res.status(), 200);
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["status"], "ERR", "body: {}", body); assert_eq!(body[0]["status"], "ERR", "body: {body}");
assert_eq!( assert_eq!(
body[0]["result"], "IAM error: Not enough permissions to perform this action", body[0]["result"], "IAM error: Not enough permissions to perform this action",
"body: {}", "body: {body}"
body
); );
} }
@ -122,7 +121,7 @@ mod http_integration {
.await?; .await?;
assert_eq!(res.status(), 200); assert_eq!(res.status(), 200);
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["status"], "OK", "body: {}", body); assert_eq!(body[0]["status"], "OK", "body: {body}");
} }
// Request with NS level access to access DB, returns 200 and succeeds // Request with NS level access to access DB, returns 200 and succeeds
@ -136,7 +135,7 @@ mod http_integration {
.await?; .await?;
assert_eq!(res.status(), 200); assert_eq!(res.status(), 200);
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["status"], "OK", "body: {}", body); assert_eq!(body[0]["status"], "OK", "body: {body}");
} }
// Request with DB level access to access ROOT, returns 200 but fails // Request with DB level access to access ROOT, returns 200 but fails
@ -151,11 +150,10 @@ mod http_integration {
.await?; .await?;
assert_eq!(res.status(), 200); assert_eq!(res.status(), 200);
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["status"], "ERR", "body: {}", body); assert_eq!(body[0]["status"], "ERR", "body: {body}");
assert_eq!( assert_eq!(
body[0]["result"], "IAM error: Not enough permissions to perform this action", body[0]["result"], "IAM error: Not enough permissions to perform this action",
"body: {}", "body: {body}"
body
); );
} }
@ -171,11 +169,10 @@ mod http_integration {
.await?; .await?;
assert_eq!(res.status(), 200); assert_eq!(res.status(), 200);
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["status"], "ERR", "body: {}", body); assert_eq!(body[0]["status"], "ERR", "body: {body}");
assert_eq!( assert_eq!(
body[0]["result"], "IAM error: Not enough permissions to perform this action", body[0]["result"], "IAM error: Not enough permissions to perform this action",
"body: {}", "body: {body}"
body
); );
} }
@ -191,7 +188,7 @@ mod http_integration {
.await?; .await?;
assert_eq!(res.status(), 200); assert_eq!(res.status(), 200);
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["status"], "OK", "body: {}", body); assert_eq!(body[0]["status"], "OK", "body: {body}");
} }
// Request with DB level access missing NS level header, returns 401 // Request with DB level access missing NS level header, returns 401
@ -236,7 +233,7 @@ mod http_integration {
.send() .send()
.await?; .await?;
let body = res.text().await?; let body = res.text().await?;
assert!(body.contains(r#""status":"OK"#), "body: {}", body); assert!(body.contains(r#""status":"OK"#), "body: {body}");
} }
// Signin with user and get the token // Signin with user and get the token
@ -266,7 +263,7 @@ mod http_integration {
let res = client.post(url).bearer_auth(&token).body("CREATE foo").send().await?; let res = client.post(url).bearer_auth(&token).body("CREATE foo").send().await?;
assert_eq!(res.status(), 200, "body: {}", res.text().await?); assert_eq!(res.status(), 200, "body: {}", res.text().await?);
let body = res.text().await?; let body = res.text().await?;
assert!(body.contains(r#"[{"result":[{"id":"foo:"#), "body: {}", body); assert!(body.contains(r#"[{"result":[{"id":"foo:"#), "body: {body}");
// Check the selected namespace and database // Check the selected namespace and database
let res = client let res = client
@ -279,8 +276,8 @@ mod http_integration {
.await?; .await?;
assert_eq!(res.status(), 200, "body: {}", res.text().await?); assert_eq!(res.status(), 200, "body: {}", res.text().await?);
let body = res.text().await?; let body = res.text().await?;
assert!(body.contains(&format!(r#""result":["{ns}"]"#)), "body: {}", body); assert!(body.contains(&format!(r#""result":["{ns}"]"#)), "body: {body}");
assert!(body.contains(&format!(r#""result":["{db}"]"#)), "body: {}", body); assert!(body.contains(&format!(r#""result":["{db}"]"#)), "body: {body}");
} }
// Request with invalid token, returns 401 // Request with invalid token, returns 401
@ -335,7 +332,7 @@ mod http_integration {
let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?; let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?;
assert_eq!(res.status(), 200, "body: {}", res.text().await?); assert_eq!(res.status(), 200, "body: {}", res.text().await?);
let body = res.text().await?; let body = res.text().await?;
assert!(body.contains("DEFINE TABLE foo"), "body: {}", body); assert!(body.contains("DEFINE TABLE foo"), "body: {body}");
} }
Ok(()) Ok(())
@ -347,7 +344,7 @@ mod http_integration {
let url = &format!("http://{addr}/health"); let url = &format!("http://{addr}/health");
let res = Client::default().get(url).send().await?; let res = Client::default().get(url).send().await?;
assert_eq!(res.status(), 200, "response: {:#?}", res); assert_eq!(res.status(), 200, "response: {res:#?}");
Ok(()) Ok(())
} }
@ -445,7 +442,7 @@ mod http_integration {
.await?; .await?;
assert_eq!(res.status(), 200, "body: {}", res.text().await?); assert_eq!(res.status(), 200, "body: {}", res.text().await?);
let body = res.text().await?; let body = res.text().await?;
assert!(body.contains("foo:bvklxkhtxumyrfzqoc5i"), "body: {}", body); assert!(body.contains("foo:bvklxkhtxumyrfzqoc5i"), "body: {body}");
} }
Ok(()) Ok(())
@ -531,7 +528,7 @@ mod http_integration {
assert_eq!(res.status(), 200, "body: {}", res.text().await?); assert_eq!(res.status(), 200, "body: {}", res.text().await?);
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert!(!body["token"].as_str().unwrap().to_string().is_empty(), "body: {}", body); assert!(!body["token"].as_str().unwrap().to_string().is_empty(), "body: {body}");
} }
// Signin with invalid DB credentials returns 401 // Signin with invalid DB credentials returns 401
@ -599,7 +596,7 @@ mod http_integration {
assert_eq!(res.status(), 200, "body: {}", res.text().await?); assert_eq!(res.status(), 200, "body: {}", res.text().await?);
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert!(!body["token"].as_str().unwrap().to_string().is_empty(), "body: {}", body); assert!(!body["token"].as_str().unwrap().to_string().is_empty(), "body: {body}");
} }
// Signin with invalid NS credentials returns 401 // Signin with invalid NS credentials returns 401
@ -684,7 +681,7 @@ mod http_integration {
assert_eq!(res.status(), 200, "body: {}", res.text().await?); assert_eq!(res.status(), 200, "body: {}", res.text().await?);
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert!(!body["token"].as_str().unwrap().to_string().is_empty(), "body: {}", body); assert!(!body["token"].as_str().unwrap().to_string().is_empty(), "body: {body}");
} }
// Signin with invalid ROOT credentials returns 401 // Signin with invalid ROOT credentials returns 401
@ -766,8 +763,7 @@ mod http_integration {
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert!( assert!(
body["token"].as_str().unwrap().starts_with("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9"), body["token"].as_str().unwrap().starts_with("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9"),
"body: {}", "body: {body}"
body
); );
} }
@ -802,7 +798,7 @@ mod http_integration {
assert_eq!(res.status(), 200); assert_eq!(res.status(), 200);
let body = res.text().await?; let body = res.text().await?;
assert!(body.contains("Not enough permissions"), "body: {}", body); assert!(body.contains("Not enough permissions"), "body: {body}");
} }
// Creating a record with Accept JSON encoding is allowed // Creating a record with Accept JSON encoding is allowed
@ -812,7 +808,7 @@ mod http_integration {
assert_eq!(res.status(), 200); assert_eq!(res.status(), 200);
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["status"], "OK", "body: {}", body); assert_eq!(body[0]["status"], "OK", "body: {body}");
} }
// Creating a record with Accept CBOR encoding is allowed // Creating a record with Accept CBOR encoding is allowed
@ -941,14 +937,14 @@ mod http_integration {
let res = client.get(url).send().await?; let res = client.get(url).send().await?;
assert_eq!(res.status(), 200, "body: {}", res.text().await?); assert_eq!(res.status(), 200, "body: {}", res.text().await?);
let body = res.text().await?; let body = res.text().await?;
assert_eq!(body, r#"Save"#, "body: {}", body); assert_eq!(body, r#"Save"#, "body: {body}");
} }
// POST // POST
{ {
let res = client.post(url).body("").send().await?; let res = client.post(url).body("").send().await?;
assert_eq!(res.status(), 200, "body: {}", res.text().await?); assert_eq!(res.status(), 200, "body: {}", res.text().await?);
let body = res.text().await?; let body = res.text().await?;
assert_eq!(body, r#"Load"#, "body: {}", body); assert_eq!(body, r#"Load"#, "body: {body}");
} }
Ok(()) Ok(())
@ -960,9 +956,9 @@ mod http_integration {
let url = &format!("http://{addr}/version"); let url = &format!("http://{addr}/version");
let res = Client::default().get(url).send().await?; let res = Client::default().get(url).send().await?;
assert_eq!(res.status(), 200, "response: {:#?}", res); assert_eq!(res.status(), 200, "response: {res:#?}");
let body = res.text().await?; let body = res.text().await?;
assert!(body.starts_with("surrealdb-"), "body: {}", body); assert!(body.starts_with("surrealdb-"), "body: {body}");
Ok(()) Ok(())
} }
@ -988,8 +984,7 @@ mod http_integration {
assert_eq!( assert_eq!(
body[0]["result"].as_array().unwrap().len(), body[0]["result"].as_array().unwrap().len(),
num_records, num_records,
"error seeding the table: {}", "error seeding the table: {body}"
body
); );
Ok(()) Ok(())
@ -1021,57 +1016,46 @@ mod http_integration {
assert_eq!(res.status(), 200, "body: {}", res.text().await?); assert_eq!(res.status(), 200, "body: {}", res.text().await?);
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap().len(), num_records, "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap().len(), num_records, "body: {body}");
} }
// GET records with a limit // GET records with a limit
{ {
let res = let res =
client.get(format!("{}?limit=10", url)).basic_auth(USER, Some(PASS)).send().await?; client.get(format!("{url}?limit=10")).basic_auth(USER, Some(PASS)).send().await?;
assert_eq!(res.status(), 200, "body: {}", res.text().await?); assert_eq!(res.status(), 200, "body: {}", res.text().await?);
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap().len(), 10, "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap().len(), 10, "body: {body}");
} }
// GET records with a start // GET records with a start
{ {
let res = let res =
client.get(format!("{}?start=10", url)).basic_auth(USER, Some(PASS)).send().await?; client.get(format!("{url}?start=10")).basic_auth(USER, Some(PASS)).send().await?;
assert_eq!(res.status(), 200, "body: {}", res.text().await?); assert_eq!(res.status(), 200, "body: {}", res.text().await?);
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!( assert_eq!(
body[0]["result"].as_array().unwrap().len(), body[0]["result"].as_array().unwrap().len(),
num_records - 10, num_records - 10,
"body: {}", "body: {body}"
body
);
assert_eq!(
body[0]["result"].as_array().unwrap()[0]["id"],
"table:11",
"body: {}",
body
); );
assert_eq!(body[0]["result"].as_array().unwrap()[0]["id"], "table:11", "body: {body}");
} }
// GET records with a start and limit // GET records with a start and limit
{ {
let res = client let res = client
.get(format!("{}?start=10&limit=10", url)) .get(format!("{url}?start=10&limit=10"))
.basic_auth(USER, Some(PASS)) .basic_auth(USER, Some(PASS))
.send() .send()
.await?; .await?;
assert_eq!(res.status(), 200, "body: {}", res.text().await?); assert_eq!(res.status(), 200, "body: {}", res.text().await?);
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap().len(), 10, "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap().len(), 10, "body: {body}");
assert_eq!( assert_eq!(body[0]["result"].as_array().unwrap()[0]["id"], "table:11", "body: {body}");
body[0]["result"].as_array().unwrap()[0]["id"],
"table:11",
"body: {}",
body
);
} }
// GET without authentication returns no records // GET without authentication returns no records
@ -1080,7 +1064,7 @@ mod http_integration {
assert_eq!(res.status(), 200, "body: {}", res.text().await?); assert_eq!(res.status(), 200, "body: {}", res.text().await?);
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap().len(), 0, "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap().len(), 0, "body: {body}");
} }
Ok(()) Ok(())
@ -1108,7 +1092,7 @@ mod http_integration {
// Verify there are no records // Verify there are no records
let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?; let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?;
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap().len(), 0, "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap().len(), 0, "body: {body}");
// Try to create the record // Try to create the record
let res = client let res = client
@ -1121,12 +1105,11 @@ mod http_integration {
// Verify the record was created // Verify the record was created
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap().len(), 1, "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap().len(), 1, "body: {body}");
assert_eq!( assert_eq!(
body[0]["result"].as_array().unwrap()[0]["name"], body[0]["result"].as_array().unwrap()[0]["name"],
"record_name", "record_name",
"body: {}", "body: {body}"
body
); );
} }
@ -1142,7 +1125,7 @@ mod http_integration {
// Verify the table is empty // Verify the table is empty
let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?; let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?;
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap().len(), 0, "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap().len(), 0, "body: {body}");
} }
Ok(()) Ok(())
@ -1181,15 +1164,15 @@ mod http_integration {
// Verify the records were updated // Verify the records were updated
let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?; let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?;
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap().len(), num_records, "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap().len(), num_records, "body: {body}");
// Verify the records have the new data // Verify the records have the new data
for record in body[0]["result"].as_array().unwrap() { for record in body[0]["result"].as_array().unwrap() {
assert_eq!(record["name"], "record_name", "body: {}", body); assert_eq!(record["name"], "record_name", "body: {body}");
} }
// Verify the records don't have the original data // Verify the records don't have the original data
for record in body[0]["result"].as_array().unwrap() { for record in body[0]["result"].as_array().unwrap() {
assert!(record["default"].is_null(), "body: {}", body); assert!(record["default"].is_null(), "body: {body}");
} }
} }
@ -1202,15 +1185,15 @@ mod http_integration {
// Verify the records were not updated // Verify the records were not updated
let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?; let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?;
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap().len(), num_records, "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap().len(), num_records, "body: {body}");
// Verify the records don't have the new data // Verify the records don't have the new data
for record in body[0]["result"].as_array().unwrap() { for record in body[0]["result"].as_array().unwrap() {
assert!(record["noauth"].is_null(), "body: {}", body); assert!(record["noauth"].is_null(), "body: {body}");
} }
// Verify the records have the original data // Verify the records have the original data
for record in body[0]["result"].as_array().unwrap() { for record in body[0]["result"].as_array().unwrap() {
assert_eq!(record["name"], "record_name", "body: {}", body); assert_eq!(record["name"], "record_name", "body: {body}");
} }
} }
@ -1250,15 +1233,15 @@ mod http_integration {
// Verify the records were modified // Verify the records were modified
let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?; let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?;
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap().len(), num_records, "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap().len(), num_records, "body: {body}");
// Verify the records have the new data // Verify the records have the new data
for record in body[0]["result"].as_array().unwrap() { for record in body[0]["result"].as_array().unwrap() {
assert_eq!(record["name"], "record_name", "body: {}", body); assert_eq!(record["name"], "record_name", "body: {body}");
} }
// Verify the records also have the original data // Verify the records also have the original data
for record in body[0]["result"].as_array().unwrap() { for record in body[0]["result"].as_array().unwrap() {
assert_eq!(record["default"], "content", "body: {}", body); assert_eq!(record["default"], "content", "body: {body}");
} }
} }
@ -1271,15 +1254,15 @@ mod http_integration {
// Verify the records were not modified // Verify the records were not modified
let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?; let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?;
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap().len(), num_records, "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap().len(), num_records, "body: {body}");
// Verify the records don't have the new data // Verify the records don't have the new data
for record in body[0]["result"].as_array().unwrap() { for record in body[0]["result"].as_array().unwrap() {
assert!(record["noauth"].is_null(), "body: {}", body); assert!(record["noauth"].is_null(), "body: {body}");
} }
// Verify the records have the original data // Verify the records have the original data
for record in body[0]["result"].as_array().unwrap() { for record in body[0]["result"].as_array().unwrap() {
assert_eq!(record["name"], "record_name", "body: {}", body); assert_eq!(record["name"], "record_name", "body: {body}");
} }
} }
@ -1310,7 +1293,7 @@ mod http_integration {
// Verify there are records // Verify there are records
let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?; let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?;
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap().len(), num_records, "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap().len(), num_records, "body: {body}");
// Try to delete the records // Try to delete the records
let res = client.delete(url).basic_auth(USER, Some(PASS)).send().await?; let res = client.delete(url).basic_auth(USER, Some(PASS)).send().await?;
@ -1319,7 +1302,7 @@ mod http_integration {
// Verify the records were deleted // Verify the records were deleted
let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?; let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?;
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap().len(), 0, "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap().len(), 0, "body: {body}");
} }
// Delete all records without authentication // Delete all records without authentication
@ -1333,7 +1316,7 @@ mod http_integration {
// Verify the records were not deleted // Verify the records were not deleted
let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?; let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?;
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap().len(), num_records, "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap().len(), num_records, "body: {body}");
} }
Ok(()) Ok(())
@ -1364,7 +1347,7 @@ mod http_integration {
assert_eq!(res.status(), 200, "body: {}", res.text().await?); assert_eq!(res.status(), 200, "body: {}", res.text().await?);
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap().len(), 1, "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap().len(), 1, "body: {body}");
} }
// GET without authentication returns no record // GET without authentication returns no record
@ -1373,7 +1356,7 @@ mod http_integration {
assert_eq!(res.status(), 200, "body: {}", res.text().await?); assert_eq!(res.status(), 200, "body: {}", res.text().await?);
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap().len(), 0, "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap().len(), 0, "body: {body}");
} }
Ok(()) Ok(())
@ -1409,12 +1392,11 @@ mod http_integration {
// Verify the record was created with the given ID // Verify the record was created with the given ID
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap().len(), 1, "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap().len(), 1, "body: {body}");
assert_eq!( assert_eq!(
body[0]["result"].as_array().unwrap()[0]["id"], body[0]["result"].as_array().unwrap()[0]["id"],
"table:new_id", "table:new_id",
"body: {}", "body: {body}"
body
); );
} }
@ -1436,25 +1418,22 @@ mod http_integration {
// Verify the record was created with the given ID // Verify the record was created with the given ID
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap().len(), 1, "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap().len(), 1, "body: {body}");
assert_eq!( assert_eq!(
body[0]["result"].as_array().unwrap()[0]["id"], body[0]["result"].as_array().unwrap()[0]["id"],
"table:new_id_query", "table:new_id_query",
"body: {}", "body: {body}"
body
); );
assert_eq!(body[0]["result"].as_array().unwrap()[0]["age"], 45, "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap()[0]["age"], 45, "body: {body}");
assert_eq!( assert_eq!(
body[0]["result"].as_array().unwrap()[0]["elems"].as_array().unwrap().len(), body[0]["result"].as_array().unwrap()[0]["elems"].as_array().unwrap().len(),
3, 3,
"body: {}", "body: {body}"
body
); );
assert_eq!( assert_eq!(
body[0]["result"].as_array().unwrap()[0]["other"].as_object().unwrap()["test"], body[0]["result"].as_array().unwrap()[0]["other"].as_object().unwrap()["test"],
true, true,
"body: {}", "body: {body}"
body
); );
} }
@ -1469,7 +1448,7 @@ mod http_integration {
// Verify the table is empty // Verify the table is empty
let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?; let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?;
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap().len(), 0, "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap().len(), 0, "body: {body}");
} }
Ok(()) Ok(())
@ -1507,22 +1486,17 @@ mod http_integration {
// Verify the record was updated // Verify the record was updated
let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?; let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?;
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap()[0]["id"], "table:1", "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap()[0]["id"], "table:1", "body: {body}");
// Verify the record has the new data // Verify the record has the new data
assert_eq!( assert_eq!(
body[0]["result"].as_array().unwrap()[0]["name"], body[0]["result"].as_array().unwrap()[0]["name"],
"record_name", "record_name",
"body: {}", "body: {body}"
body
); );
// Verify the record doesn't have the original data // Verify the record doesn't have the original data
assert!( assert!(body[0]["result"].as_array().unwrap()[0]["default"].is_null(), "body: {body}");
body[0]["result"].as_array().unwrap()[0]["default"].is_null(),
"body: {}",
body
);
} }
// Update one record without authentication // Update one record without authentication
@ -1534,17 +1508,16 @@ mod http_integration {
// Verify the record was not updated // Verify the record was not updated
let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?; let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?;
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap()[0]["id"], "table:1", "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap()[0]["id"], "table:1", "body: {body}");
// Verify the record doesn't have the new data // Verify the record doesn't have the new data
assert!(body[0]["result"].as_array().unwrap()[0]["noauth"].is_null(), "body: {}", body); assert!(body[0]["result"].as_array().unwrap()[0]["noauth"].is_null(), "body: {body}");
// Verify the record has the original data // Verify the record has the original data
assert_eq!( assert_eq!(
body[0]["result"].as_array().unwrap()[0]["name"], body[0]["result"].as_array().unwrap()[0]["name"],
"record_name", "record_name",
"body: {}", "body: {body}"
body
); );
} }
@ -1583,22 +1556,20 @@ mod http_integration {
// Verify the records were modified // Verify the records were modified
let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?; let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?;
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap()[0]["id"], "table:1", "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap()[0]["id"], "table:1", "body: {body}");
// Verify the record has the new data // Verify the record has the new data
assert_eq!( assert_eq!(
body[0]["result"].as_array().unwrap()[0]["name"], body[0]["result"].as_array().unwrap()[0]["name"],
"record_name", "record_name",
"body: {}", "body: {body}"
body
); );
// Verify the record has the original data too // Verify the record has the original data too
assert_eq!( assert_eq!(
body[0]["result"].as_array().unwrap()[0]["default"], body[0]["result"].as_array().unwrap()[0]["default"],
"content", "content",
"body: {}", "body: {body}"
body
); );
} }
@ -1611,17 +1582,16 @@ mod http_integration {
// Verify the record was not modified // Verify the record was not modified
let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?; let res = client.get(url).basic_auth(USER, Some(PASS)).send().await?;
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap()[0]["id"], "table:1", "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap()[0]["id"], "table:1", "body: {body}");
// Verify the record doesn't have the new data // Verify the record doesn't have the new data
assert!(body[0]["result"].as_array().unwrap()[0]["noauth"].is_null(), "body: {}", body); assert!(body[0]["result"].as_array().unwrap()[0]["noauth"].is_null(), "body: {body}");
// Verify the record has the original data too // Verify the record has the original data too
assert_eq!( assert_eq!(
body[0]["result"].as_array().unwrap()[0]["default"], body[0]["result"].as_array().unwrap()[0]["default"],
"content", "content",
"body: {}", "body: {body}"
body
); );
} }
@ -1651,33 +1621,30 @@ mod http_integration {
// Verify there are records // Verify there are records
let res = client.get(base_url).basic_auth(USER, Some(PASS)).send().await?; let res = client.get(base_url).basic_auth(USER, Some(PASS)).send().await?;
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap().len(), 2, "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap().len(), 2, "body: {body}");
// Try to delete the record // Try to delete the record
let res = client let res =
.delete(format!("{}/1", base_url)) client.delete(format!("{base_url}/1")).basic_auth(USER, Some(PASS)).send().await?;
.basic_auth(USER, Some(PASS))
.send()
.await?;
assert_eq!(res.status(), 200, "body: {}", res.text().await?); assert_eq!(res.status(), 200, "body: {}", res.text().await?);
// Verify only one record was deleted // Verify only one record was deleted
let res = client.get(base_url).basic_auth(USER, Some(PASS)).send().await?; let res = client.get(base_url).basic_auth(USER, Some(PASS)).send().await?;
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap().len(), 1, "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap().len(), 1, "body: {body}");
assert_eq!(body[0]["result"].as_array().unwrap()[0]["id"], "table:2", "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap()[0]["id"], "table:2", "body: {body}");
} }
// Delete one record without authentication // Delete one record without authentication
{ {
// Try to delete the record // Try to delete the record
let res = client.delete(format!("{}/2", base_url)).send().await?; let res = client.delete(format!("{base_url}/2")).send().await?;
assert_eq!(res.status(), 200, "body: {}", res.text().await?); assert_eq!(res.status(), 200, "body: {}", res.text().await?);
// Verify the record was not deleted // Verify the record was not deleted
let res = client.get(base_url).basic_auth(USER, Some(PASS)).send().await?; let res = client.get(base_url).basic_auth(USER, Some(PASS)).send().await?;
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap(); let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
assert_eq!(body[0]["result"].as_array().unwrap().len(), 1, "body: {}", body); assert_eq!(body[0]["result"].as_array().unwrap().len(), 1, "body: {body}");
} }
Ok(()) Ok(())