style: simplify string formatting (#4260)
Co-authored-by: Tobie Morgan Hitchcock <tobie@surrealdb.com>
This commit is contained in:
parent
c73435a881
commit
b37929b6ab
12 changed files with 360 additions and 407 deletions
|
@ -565,19 +565,16 @@ mod tests {
|
|||
|
||||
let res = res.unwrap().remove(0).output();
|
||||
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()
|
||||
} 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()
|
||||
};
|
||||
|
||||
assert!(
|
||||
res.contains(&contains),
|
||||
"Unexpected result for test case {}: expected to contain = `{}`, got `{}`",
|
||||
idx,
|
||||
contains,
|
||||
res
|
||||
"Unexpected result for test case {idx}: expected to contain = `{contains}`, got `{res}`"
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -231,7 +231,7 @@ impl Drop for HttpCallMetricTracker {
|
|||
}
|
||||
ResultState::Result(s, v, size) => {
|
||||
self.status_code = Some(s);
|
||||
self.version = format!("{:?}", v);
|
||||
self.version = format!("{v:?}");
|
||||
self.response_size = size;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -135,7 +135,7 @@ mod tests {
|
|||
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(
|
||||
vec![
|
||||
("SURREAL_TRACING_TRACER", Some("otlp")),
|
||||
|
@ -176,7 +176,7 @@ mod tests {
|
|||
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(
|
||||
vec![
|
||||
("SURREAL_TRACING_TRACER", Some("otlp")),
|
||||
|
|
|
@ -26,7 +26,7 @@ where
|
|||
Some(otlp::new(filter))
|
||||
}
|
||||
tracer => {
|
||||
panic!("unsupported tracer {}", tracer);
|
||||
panic!("unsupported tracer {tracer}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -468,8 +468,7 @@ mod cli_integration {
|
|||
.clone()
|
||||
.unwrap_err()
|
||||
.contains("Namespace is needed for authentication but it was not provided"),
|
||||
"auth level namespace requires providing a namespace: {:?}",
|
||||
output
|
||||
"auth level namespace requires providing a namespace: {output:?}"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -484,8 +483,7 @@ mod cli_integration {
|
|||
.clone()
|
||||
.unwrap_err()
|
||||
.contains("Database is needed for authentication but it was not provided"),
|
||||
"auth level database requires providing a namespace and database: {:?}",
|
||||
output
|
||||
"auth level database requires providing a namespace and database: {output:?}"
|
||||
);
|
||||
}
|
||||
server.finish().unwrap();
|
||||
|
@ -832,7 +830,7 @@ mod cli_integration {
|
|||
let args = format!("{sql_args} {creds}");
|
||||
let input = "";
|
||||
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");
|
||||
|
@ -840,7 +838,7 @@ mod cli_integration {
|
|||
let args = format!("sql --conn ws://{addr} --multi --pretty {creds}");
|
||||
let input = "";
|
||||
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");
|
||||
|
@ -852,8 +850,7 @@ mod cli_integration {
|
|||
let output = common::run(&args).output();
|
||||
assert!(
|
||||
output.clone().unwrap_err().contains("Forbidden"),
|
||||
"anonymous user shouldn't be able to export: {:?}",
|
||||
output
|
||||
"anonymous user shouldn't be able to export: {output:?}"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -868,8 +865,7 @@ mod cli_integration {
|
|||
let output = common::run(&args).output();
|
||||
assert!(
|
||||
output.clone().unwrap_err().contains("Forbidden"),
|
||||
"anonymous user shouldn't be able to import: {:?}",
|
||||
output
|
||||
"anonymous user shouldn't be able to import: {output:?}"
|
||||
);
|
||||
}
|
||||
server.finish().unwrap();
|
||||
|
@ -1028,7 +1024,7 @@ mod cli_integration {
|
|||
|
||||
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());
|
||||
}
|
||||
|
@ -1104,10 +1100,7 @@ mod cli_integration {
|
|||
tokio::time::timeout(time::Duration::from_secs(10), async {
|
||||
loop {
|
||||
if let Ok(Some(exit)) = server.status() {
|
||||
panic!(
|
||||
"Server unexpectedly exited after receiving first SIGINT: {:?}",
|
||||
exit
|
||||
);
|
||||
panic!("Server unexpectedly exited after receiving first SIGINT: {exit:?}");
|
||||
}
|
||||
tokio::time::sleep(time::Duration::from_millis(100)).await;
|
||||
}
|
||||
|
@ -1190,7 +1183,7 @@ mod cli_integration {
|
|||
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();
|
||||
assert!(
|
||||
output.contains("Function 'http::get' is not allowed"),
|
||||
|
@ -1222,7 +1215,7 @@ mod cli_integration {
|
|||
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();
|
||||
assert!(output.contains("['surrealdb-"), "unexpected output: {output:?}");
|
||||
|
||||
|
@ -1271,7 +1264,7 @@ mod cli_integration {
|
|||
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();
|
||||
assert!(
|
||||
output.contains(
|
||||
|
@ -1298,7 +1291,7 @@ mod cli_integration {
|
|||
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();
|
||||
assert!(output.contains("['surrealdb-"), "unexpected output: {output:?}");
|
||||
server.finish().unwrap();
|
||||
|
@ -1412,7 +1405,7 @@ mod cli_integration {
|
|||
panic!("Should not be ok!");
|
||||
}
|
||||
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!");
|
||||
}
|
||||
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();
|
||||
|
|
|
@ -54,7 +54,7 @@ impl DockerContainer {
|
|||
if !output.stderr.is_empty() {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,11 +10,11 @@ impl Expected {
|
|||
match self {
|
||||
Expected::Any => {}
|
||||
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);
|
||||
}
|
||||
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[1], expected2);
|
||||
}
|
||||
|
@ -23,6 +23,6 @@ impl Expected {
|
|||
|
||||
pub fn check_json(q: &str, result: &JsonValue, expected: &str) {
|
||||
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}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ impl Child {
|
|||
let a = self
|
||||
.inner
|
||||
.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()));
|
||||
a.map(|_ok| self)
|
||||
}
|
||||
|
@ -85,10 +85,10 @@ impl Drop for Child {
|
|||
let _ = inner.kill();
|
||||
let stdout =
|
||||
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 =
|
||||
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.stderr_path);
|
||||
|
|
|
@ -83,7 +83,7 @@ impl Socket {
|
|||
|
||||
/// Connect to a WebSocket server using a specific format
|
||||
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();
|
||||
if let Some(v) = format.map(|v| v.to_string()) {
|
||||
req.headers_mut().insert("Sec-WebSocket-Protocol", v.parse().unwrap());
|
||||
|
@ -340,14 +340,13 @@ impl Socket {
|
|||
.get("result")
|
||||
.ok_or(TestError::AssertionError {
|
||||
message: format!(
|
||||
"expected a result from the received object, got this instead: {:?}",
|
||||
obj
|
||||
"expected a result from the received object, got this instead: {obj:?}"
|
||||
),
|
||||
})?
|
||||
.to_owned()),
|
||||
_ => {
|
||||
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
|
||||
.get("result")
|
||||
.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()
|
||||
.ok_or(TestError::AssertionError {
|
||||
|
@ -373,7 +372,7 @@ impl Socket {
|
|||
.to_owned()),
|
||||
_ => {
|
||||
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
|
||||
.get("result")
|
||||
.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()
|
||||
.ok_or(TestError::AssertionError {
|
||||
|
@ -417,7 +416,7 @@ impl Socket {
|
|||
.to_owned()),
|
||||
_ => {
|
||||
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")
|
||||
.ok_or(TestError::AssertionError {
|
||||
message: format!(
|
||||
"expected a result from the received object, got this instead: {:?}",
|
||||
obj
|
||||
"expected a result from the received object, got this instead: {obj:?}"
|
||||
),
|
||||
})?
|
||||
.to_owned()),
|
||||
_ => {
|
||||
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")
|
||||
.ok_or(TestError::AssertionError {
|
||||
message: format!(
|
||||
"expected a result from the received object, got this instead: {:?}",
|
||||
obj
|
||||
"expected a result from the received object, got this instead: {obj:?}"
|
||||
),
|
||||
})?
|
||||
.to_owned()),
|
||||
_ => {
|
||||
error!("{:?}", msg.as_object().unwrap().keys().collect::<Vec<_>>());
|
||||
Err(format!("unexpected response: {:?}", msg).into())
|
||||
Err(format!("unexpected response: {msg:?}").into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,11 +14,11 @@ async fn ping() -> Result<(), Box<dyn std::error::Error>> {
|
|||
let socket = Socket::connect(&addr, SERVER, FORMAT).await?;
|
||||
// Send INFO command
|
||||
let res = socket.send_request("ping", json!([])).await;
|
||||
assert!(res.is_ok(), "result: {:?}", res);
|
||||
assert!(res.is_ok(), "result: {res:?}");
|
||||
let res = res.unwrap();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
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
|
||||
server.finish().unwrap();
|
||||
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?;
|
||||
// Send INFO command
|
||||
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();
|
||||
assert_eq!(res["user"], "user", "result: {:?}", res);
|
||||
assert_eq!(res["user"], "user", "result: {res:?}");
|
||||
// Test passed
|
||||
server.finish().unwrap();
|
||||
Ok(())
|
||||
|
@ -105,16 +105,16 @@ async fn signup() -> Result<(), Box<dyn std::error::Error>> {
|
|||
}]),
|
||||
)
|
||||
.await;
|
||||
assert!(res.is_ok(), "result: {:?}", res);
|
||||
assert!(res.is_ok(), "result: {res:?}");
|
||||
let res = res.unwrap();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
let res = res.as_object().unwrap();
|
||||
// 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
|
||||
assert!(res["result"].is_string(), "result: {:?}", res);
|
||||
assert!(res["result"].is_string(), "result: {res:?}");
|
||||
let res = res["result"].as_str().unwrap();
|
||||
assert!(res.starts_with("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9"), "result: {}", res);
|
||||
assert!(res.starts_with("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9"), "result: {res}");
|
||||
// Test passed
|
||||
server.finish().unwrap();
|
||||
Ok(())
|
||||
|
@ -156,16 +156,16 @@ async fn signin() -> Result<(), Box<dyn std::error::Error>> {
|
|||
),
|
||||
)
|
||||
.await;
|
||||
assert!(res.is_ok(), "result: {:?}", res);
|
||||
assert!(res.is_ok(), "result: {res:?}");
|
||||
let res = res.unwrap();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
let res = res.as_object().unwrap();
|
||||
// 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
|
||||
assert!(res["result"].is_string(), "result: {:?}", res);
|
||||
assert!(res["result"].is_string(), "result: {res:?}");
|
||||
let res = res["result"].as_str().unwrap();
|
||||
assert!(res.starts_with("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9"), "result: {}", res);
|
||||
assert!(res.starts_with("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9"), "result: {res}");
|
||||
// Send SIGNIN command
|
||||
let res = socket
|
||||
.send_request(
|
||||
|
@ -180,16 +180,16 @@ async fn signin() -> Result<(), Box<dyn std::error::Error>> {
|
|||
}]),
|
||||
)
|
||||
.await;
|
||||
assert!(res.is_ok(), "result: {:?}", res);
|
||||
assert!(res.is_ok(), "result: {res:?}");
|
||||
let res = res.unwrap();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
let res = res.as_object().unwrap();
|
||||
// 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
|
||||
assert!(res["result"].is_string(), "result: {:?}", res);
|
||||
assert!(res["result"].is_string(), "result: {res:?}");
|
||||
let res = res["result"].as_str().unwrap();
|
||||
assert!(res.starts_with("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9"), "result: {}", res);
|
||||
assert!(res.starts_with("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9"), "result: {res}");
|
||||
// Test passed
|
||||
server.finish().unwrap();
|
||||
Ok(())
|
||||
|
@ -207,7 +207,7 @@ async fn invalidate() -> Result<(), Box<dyn std::error::Error>> {
|
|||
socket.send_message_use(Some(NS), Some(DB)).await?;
|
||||
// Verify we have an authenticated session
|
||||
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
|
||||
socket.send_request("invalidate", json!([])).await?;
|
||||
// Verify we have an invalidated session
|
||||
|
@ -215,7 +215,7 @@ async fn invalidate() -> Result<(), Box<dyn std::error::Error>> {
|
|||
assert_eq!(
|
||||
res["error"]["message"],
|
||||
"There was a problem with the database: IAM error: Not enough permissions to perform this action",
|
||||
"result: {:?}", res
|
||||
"result: {res:?}"
|
||||
);
|
||||
// Test passed
|
||||
server.finish().unwrap();
|
||||
|
@ -238,7 +238,7 @@ async fn authenticate() -> Result<(), Box<dyn std::error::Error>> {
|
|||
socket.send_request("authenticate", json!([token,])).await?;
|
||||
// Verify we have an authenticated session
|
||||
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
|
||||
server.finish().unwrap();
|
||||
Ok(())
|
||||
|
@ -260,7 +260,7 @@ async fn letset() -> Result<(), Box<dyn std::error::Error>> {
|
|||
socket.send_request("set", json!(["set_var", "set_value",])).await?;
|
||||
// Verify the variables are set
|
||||
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();
|
||||
Ok(())
|
||||
}
|
||||
|
@ -279,12 +279,12 @@ async fn unset() -> Result<(), Box<dyn std::error::Error>> {
|
|||
socket.send_request("let", json!(["let_var", "let_value",])).await?;
|
||||
// Verify the variable is set
|
||||
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
|
||||
socket.send_request("unset", json!(["let_var",])).await?;
|
||||
// Verify the variable is unset
|
||||
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
|
||||
server.finish().unwrap();
|
||||
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?;
|
||||
// Send SELECT command
|
||||
let res = socket.send_request("select", json!(["tester",])).await?;
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res["result"].is_array(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
assert!(res["result"].is_array(), "result: {res:?}");
|
||||
let res = res["result"].as_array().unwrap();
|
||||
assert_eq!(res.len(), 1, "result: {:?}", res);
|
||||
assert_eq!(res[0]["name"], "foo", "result: {:?}", res);
|
||||
assert_eq!(res[0]["value"], "bar", "result: {:?}", res);
|
||||
assert_eq!(res.len(), 1, "result: {res:?}");
|
||||
assert_eq!(res[0]["name"], "foo", "result: {res:?}");
|
||||
assert_eq!(res[0]["value"], "bar", "result: {res:?}");
|
||||
// Test passed
|
||||
server.finish().unwrap();
|
||||
Ok(())
|
||||
|
@ -338,19 +338,19 @@ async fn insert() -> Result<(), Box<dyn std::error::Error>> {
|
|||
]),
|
||||
)
|
||||
.await?;
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res["result"].is_array(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
assert!(res["result"].is_array(), "result: {res:?}");
|
||||
let res = res["result"].as_array().unwrap();
|
||||
assert_eq!(res.len(), 1, "result: {:?}", res);
|
||||
assert_eq!(res[0]["name"], "foo", "result: {:?}", res);
|
||||
assert_eq!(res[0]["value"], "bar", "result: {:?}", res);
|
||||
assert_eq!(res.len(), 1, "result: {res:?}");
|
||||
assert_eq!(res[0]["name"], "foo", "result: {res:?}");
|
||||
assert_eq!(res[0]["value"], "bar", "result: {res:?}");
|
||||
// Verify the data was inserted and can be queried
|
||||
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();
|
||||
assert_eq!(res.len(), 1, "result: {:?}", res);
|
||||
assert_eq!(res[0]["name"], "foo", "result: {:?}", res);
|
||||
assert_eq!(res[0]["value"], "bar", "result: {:?}", res);
|
||||
assert_eq!(res.len(), 1, "result: {res:?}");
|
||||
assert_eq!(res[0]["name"], "foo", "result: {res:?}");
|
||||
assert_eq!(res[0]["value"], "bar", "result: {res:?}");
|
||||
// Test passed
|
||||
server.finish().unwrap();
|
||||
Ok(())
|
||||
|
@ -378,17 +378,17 @@ async fn create() -> Result<(), Box<dyn std::error::Error>> {
|
|||
]),
|
||||
)
|
||||
.await?;
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res["result"].is_array(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
assert!(res["result"].is_array(), "result: {res:?}");
|
||||
let res = res["result"].as_array().unwrap();
|
||||
assert_eq!(res.len(), 1, "result: {:?}", res);
|
||||
assert_eq!(res[0]["value"], "bar", "result: {:?}", res);
|
||||
assert_eq!(res.len(), 1, "result: {res:?}");
|
||||
assert_eq!(res[0]["value"], "bar", "result: {res:?}");
|
||||
// Verify the data was created
|
||||
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();
|
||||
assert_eq!(res.len(), 1, "result: {:?}", res);
|
||||
assert_eq!(res[0]["value"], "bar", "result: {:?}", res);
|
||||
assert_eq!(res.len(), 1, "result: {res:?}");
|
||||
assert_eq!(res[0]["value"], "bar", "result: {res:?}");
|
||||
// Test passed
|
||||
server.finish().unwrap();
|
||||
Ok(())
|
||||
|
@ -418,18 +418,18 @@ async fn update() -> Result<(), Box<dyn std::error::Error>> {
|
|||
]),
|
||||
)
|
||||
.await?;
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res["result"].is_array(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
assert!(res["result"].is_array(), "result: {res:?}");
|
||||
let res = res["result"].as_array().unwrap();
|
||||
assert_eq!(res.len(), 1, "result: {:?}", res);
|
||||
assert_eq!(res[0]["value"], "bar", "result: {:?}", res);
|
||||
assert_eq!(res.len(), 1, "result: {res:?}");
|
||||
assert_eq!(res[0]["value"], "bar", "result: {res:?}");
|
||||
// Verify the data was updated
|
||||
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();
|
||||
assert_eq!(res.len(), 1, "result: {:?}", res);
|
||||
assert_eq!(res[0]["name"], json!(null), "result: {:?}", res);
|
||||
assert_eq!(res[0]["value"], "bar", "result: {:?}", res);
|
||||
assert_eq!(res.len(), 1, "result: {res:?}");
|
||||
assert_eq!(res[0]["name"], json!(null), "result: {res:?}");
|
||||
assert_eq!(res[0]["value"], "bar", "result: {res:?}");
|
||||
// Test passed
|
||||
server.finish().unwrap();
|
||||
Ok(())
|
||||
|
@ -459,19 +459,19 @@ async fn merge() -> Result<(), Box<dyn std::error::Error>> {
|
|||
]),
|
||||
)
|
||||
.await?;
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res["result"].is_array(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
assert!(res["result"].is_array(), "result: {res:?}");
|
||||
let res = res["result"].as_array().unwrap();
|
||||
assert_eq!(res.len(), 1, "result: {:?}", res);
|
||||
assert_eq!(res[0]["name"], "foo", "result: {:?}", res);
|
||||
assert_eq!(res[0]["value"], "bar", "result: {:?}", res);
|
||||
assert_eq!(res.len(), 1, "result: {res:?}");
|
||||
assert_eq!(res[0]["name"], "foo", "result: {res:?}");
|
||||
assert_eq!(res[0]["value"], "bar", "result: {res:?}");
|
||||
// Verify the data was merged
|
||||
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();
|
||||
assert_eq!(res.len(), 1, "result: {:?}", res);
|
||||
assert_eq!(res[0]["name"], "foo", "result: {:?}", res);
|
||||
assert_eq!(res[0]["value"], "bar", "result: {:?}", res);
|
||||
assert_eq!(res.len(), 1, "result: {res:?}");
|
||||
assert_eq!(res[0]["name"], "foo", "result: {res:?}");
|
||||
assert_eq!(res[0]["value"], "bar", "result: {res:?}");
|
||||
// Test passed
|
||||
server.finish().unwrap();
|
||||
Ok(())
|
||||
|
@ -509,16 +509,16 @@ async fn patch() -> Result<(), Box<dyn std::error::Error>> {
|
|||
]),
|
||||
)
|
||||
.await?;
|
||||
assert!(res["result"].is_object(), "result: {:?}", res);
|
||||
assert!(res["result"].is_object(), "result: {res:?}");
|
||||
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
|
||||
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();
|
||||
assert_eq!(res.len(), 1, "result: {:?}", res);
|
||||
assert_eq!(res[0]["name"], json!(null), "result: {:?}", res);
|
||||
assert_eq!(res[0]["value"], "bar", "result: {:?}", res);
|
||||
assert_eq!(res.len(), 1, "result: {res:?}");
|
||||
assert_eq!(res[0]["name"], json!(null), "result: {res:?}");
|
||||
assert_eq!(res[0]["value"], "bar", "result: {res:?}");
|
||||
// Test passed
|
||||
server.finish().unwrap();
|
||||
Ok(())
|
||||
|
@ -538,24 +538,24 @@ async fn delete() -> Result<(), Box<dyn std::error::Error>> {
|
|||
socket.send_message_query("CREATE tester:id").await?;
|
||||
// Send DELETE command
|
||||
let res = socket.send_request("delete", json!(["tester"])).await?;
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res["result"].is_array(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
assert!(res["result"].is_array(), "result: {res:?}");
|
||||
let res = res["result"].as_array().unwrap();
|
||||
assert_eq!(res.len(), 1, "result: {:?}", res);
|
||||
assert_eq!(res[0]["id"], "tester:id", "result: {:?}", res);
|
||||
assert_eq!(res.len(), 1, "result: {res:?}");
|
||||
assert_eq!(res[0]["id"], "tester:id", "result: {res:?}");
|
||||
// Create a test record
|
||||
socket.send_message_query("CREATE tester:id").await?;
|
||||
// Send DELETE command
|
||||
let res = socket.send_request("delete", json!(["tester:id"])).await?;
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res["result"].is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
assert!(res["result"].is_object(), "result: {res:?}");
|
||||
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
|
||||
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();
|
||||
assert_eq!(res.len(), 0, "result: {:?}", res);
|
||||
assert_eq!(res.len(), 0, "result: {res:?}");
|
||||
// Test passed
|
||||
server.finish().unwrap();
|
||||
Ok(())
|
||||
|
@ -574,15 +574,15 @@ async fn query() -> Result<(), Box<dyn std::error::Error>> {
|
|||
// Send QUERY command
|
||||
let res =
|
||||
socket.send_request("query", json!(["CREATE tester; SELECT * FROM tester;",])).await?;
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res["result"].is_array(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
assert!(res["result"].is_array(), "result: {res:?}");
|
||||
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
|
||||
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();
|
||||
assert_eq!(res.len(), 1, "result: {:?}", res);
|
||||
assert_eq!(res.len(), 1, "result: {res:?}");
|
||||
// Test passed
|
||||
server.finish().unwrap();
|
||||
Ok(())
|
||||
|
@ -596,9 +596,9 @@ async fn version() -> Result<(), Box<dyn std::error::Error>> {
|
|||
let socket = Socket::connect(&addr, SERVER, FORMAT).await?;
|
||||
// Send version command
|
||||
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();
|
||||
assert!(res.starts_with("surrealdb-"), "result: {}", res);
|
||||
assert!(res.starts_with("surrealdb-"), "result: {res}");
|
||||
// Test passed
|
||||
server.finish().unwrap();
|
||||
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
|
||||
server.finish().unwrap();
|
||||
Ok(())
|
||||
|
@ -655,23 +655,23 @@ async fn live() -> Result<(), Box<dyn std::error::Error>> {
|
|||
socket.send_message_use(Some(NS), Some(DB)).await?;
|
||||
// Send LIVE command
|
||||
let res = socket.send_request("live", json!(["tester"])).await?;
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res["result"].is_string(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
assert!(res["result"].is_string(), "result: {res:?}");
|
||||
let live1 = res["result"].as_str().unwrap();
|
||||
// Send QUERY command
|
||||
let res = socket.send_request("query", json!(["LIVE SELECT * FROM tester"])).await?;
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res["result"].is_array(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
assert!(res["result"].is_array(), "result: {res:?}");
|
||||
let res = res["result"].as_array().unwrap();
|
||||
assert_eq!(res.len(), 1, "result: {:?}", res);
|
||||
assert!(res[0]["result"].is_string(), "result: {:?}", res);
|
||||
assert_eq!(res.len(), 1, "result: {res:?}");
|
||||
assert!(res[0]["result"].is_string(), "result: {res:?}");
|
||||
let live2 = res[0]["result"].as_str().unwrap();
|
||||
// Create a new test record
|
||||
let res = socket.send_request("query", json!(["CREATE tester:id SET name = 'foo'"])).await?;
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res["result"].is_array(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
assert!(res["result"].is_array(), "result: {res:?}");
|
||||
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
|
||||
let msgs: Result<_, Box<dyn std::error::Error>> =
|
||||
tokio::time::timeout(Duration::from_secs(1), async {
|
||||
|
@ -679,32 +679,32 @@ async fn live() -> Result<(), Box<dyn std::error::Error>> {
|
|||
})
|
||||
.await?;
|
||||
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
|
||||
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();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
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();
|
||||
assert!(res["action"].is_string(), "result: {:?}", res);
|
||||
assert_eq!(res["action"], "CREATE", "result: {:?}", res);
|
||||
assert!(res["result"].is_object(), "result: {:?}", res);
|
||||
assert!(res["action"].is_string(), "result: {res:?}");
|
||||
assert_eq!(res["action"], "CREATE", "result: {res:?}");
|
||||
assert!(res["result"].is_object(), "result: {res:?}");
|
||||
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
|
||||
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();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
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();
|
||||
assert_eq!(res["action"], "CREATE", "result: {:?}", res);
|
||||
assert!(res["result"].is_object(), "result: {:?}", res);
|
||||
assert_eq!(res["action"], "CREATE", "result: {res:?}");
|
||||
assert!(res["result"].is_object(), "result: {res:?}");
|
||||
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
|
||||
server.finish().unwrap();
|
||||
Ok(())
|
||||
|
@ -722,92 +722,92 @@ async fn kill() -> Result<(), Box<dyn std::error::Error>> {
|
|||
socket.send_message_use(Some(NS), Some(DB)).await?;
|
||||
// Send LIVE command
|
||||
let res = socket.send_request("live", json!(["tester"])).await?;
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res["result"].is_string(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
assert!(res["result"].is_string(), "result: {res:?}");
|
||||
let live1 = res["result"].as_str().unwrap();
|
||||
// Send QUERY command
|
||||
let res = socket.send_request("query", json!(["LIVE SELECT * FROM tester"])).await?;
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res["result"].is_array(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
assert!(res["result"].is_array(), "result: {res:?}");
|
||||
let res = res["result"].as_array().unwrap();
|
||||
assert_eq!(res.len(), 1, "result: {:?}", res);
|
||||
assert!(res[0]["result"].is_string(), "result: {:?}", res);
|
||||
assert_eq!(res.len(), 1, "result: {res:?}");
|
||||
assert!(res[0]["result"].is_string(), "result: {res:?}");
|
||||
let live2 = res[0]["result"].as_str().unwrap();
|
||||
// Create a new test record
|
||||
let res = socket.send_request("query", json!(["CREATE tester:one SET name = 'one'"])).await?;
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res["result"].is_array(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
assert!(res["result"].is_array(), "result: {res:?}");
|
||||
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
|
||||
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
|
||||
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();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
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();
|
||||
assert!(res["action"].is_string(), "result: {:?}", res);
|
||||
assert_eq!(res["action"], "CREATE", "result: {:?}", res);
|
||||
assert!(res["result"].is_object(), "result: {:?}", res);
|
||||
assert!(res["action"].is_string(), "result: {res:?}");
|
||||
assert_eq!(res["action"], "CREATE", "result: {res:?}");
|
||||
assert!(res["result"].is_object(), "result: {res:?}");
|
||||
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
|
||||
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();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
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();
|
||||
assert_eq!(res["action"], "CREATE", "result: {:?}", res);
|
||||
assert!(res["result"].is_object(), "result: {:?}", res);
|
||||
assert_eq!(res["action"], "CREATE", "result: {res:?}");
|
||||
assert!(res["result"].is_object(), "result: {res:?}");
|
||||
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
|
||||
let res = socket.send_request("kill", json!([live1])).await?;
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res["result"].is_null(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
assert!(res["result"].is_null(), "result: {res:?}");
|
||||
// Create a new test record
|
||||
let res = socket.send_request("query", json!(["CREATE tester:two SET name = 'two'"])).await?;
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res["result"].is_array(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
assert!(res["result"].is_array(), "result: {res:?}");
|
||||
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
|
||||
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
|
||||
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();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
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();
|
||||
assert_eq!(res["action"], "CREATE", "result: {:?}", res);
|
||||
assert!(res["result"].is_object(), "result: {:?}", res);
|
||||
assert_eq!(res["action"], "CREATE", "result: {res:?}");
|
||||
assert!(res["result"].is_object(), "result: {res:?}");
|
||||
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
|
||||
let res = socket.send_request("query", json!([format!("KILL u'{live2}'")])).await?;
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res["result"].is_array(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
assert!(res["result"].is_array(), "result: {res:?}");
|
||||
let res = res["result"].as_array().unwrap();
|
||||
assert_eq!(res.len(), 1, "result: {:?}", res);
|
||||
assert!(res[0]["result"].is_null(), "result: {:?}", res);
|
||||
assert_eq!(res.len(), 1, "result: {res:?}");
|
||||
assert!(res[0]["result"].is_null(), "result: {res:?}");
|
||||
// Create a new test record
|
||||
let res = socket.send_request("query", json!(["CREATE tester:tre SET name = 'two'"])).await?;
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res["result"].is_array(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
assert!(res["result"].is_array(), "result: {res:?}");
|
||||
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
|
||||
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
|
||||
server.finish().unwrap();
|
||||
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?;
|
||||
// Send LIVE command
|
||||
let res = socket1.send_request("live", json!(["tester"])).await?;
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res["result"].is_string(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
assert!(res["result"].is_string(), "result: {res:?}");
|
||||
let liveid = res["result"].as_str().unwrap();
|
||||
// Connect to WebSocket
|
||||
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?;
|
||||
// Create a new test record
|
||||
let res = socket2.send_request("query", json!(["CREATE tester:id SET name = 'foo'"])).await?;
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res["result"].is_array(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
assert!(res["result"].is_array(), "result: {res:?}");
|
||||
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
|
||||
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
|
||||
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();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
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();
|
||||
assert!(res["action"].is_string(), "result: {:?}", res);
|
||||
assert_eq!(res["action"], "CREATE", "result: {:?}", res);
|
||||
assert!(res["result"].is_object(), "result: {:?}", res);
|
||||
assert!(res["action"].is_string(), "result: {res:?}");
|
||||
assert_eq!(res["action"], "CREATE", "result: {res:?}");
|
||||
assert!(res["result"].is_object(), "result: {res:?}");
|
||||
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
|
||||
server.finish().unwrap();
|
||||
Ok(())
|
||||
|
@ -897,31 +897,31 @@ async fn variable_auth_live_query() -> Result<(), Box<dyn std::error::Error>> {
|
|||
}]),
|
||||
)
|
||||
.await;
|
||||
assert!(res.is_ok(), "result: {:?}", res);
|
||||
assert!(res.is_ok(), "result: {res:?}");
|
||||
let res = res.unwrap();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
let res = res.as_object().unwrap();
|
||||
// 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
|
||||
socket_expiring_auth.send_message_signin(USER, PASS, None, None, None).await?;
|
||||
// Send LIVE command
|
||||
let res = socket_expiring_auth.send_request("live", json!(["tester"])).await?;
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res["result"].is_string(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
assert!(res["result"].is_string(), "result: {res:?}");
|
||||
// Wait 2 seconds for auth to expire
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
// Create a new test record
|
||||
let res = socket_permanent
|
||||
.send_request("query", json!(["CREATE tester:id SET name = 'foo'"]))
|
||||
.await?;
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res["result"].is_array(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
assert!(res["result"].is_array(), "result: {res:?}");
|
||||
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
|
||||
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
|
||||
server.finish().unwrap();
|
||||
Ok(())
|
||||
|
@ -982,28 +982,28 @@ async fn session_expiration() {
|
|||
),
|
||||
)
|
||||
.await;
|
||||
assert!(res.is_ok(), "result: {:?}", res);
|
||||
assert!(res.is_ok(), "result: {res:?}");
|
||||
let res = res.unwrap();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
let res = res.as_object().unwrap();
|
||||
// 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
|
||||
assert!(res["result"].is_string(), "result: {:?}", res);
|
||||
assert!(res["result"].is_string(), "result: {res:?}");
|
||||
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
|
||||
socket.send_request("authenticate", json!([res,])).await.unwrap();
|
||||
// Check if the session is now authenticated
|
||||
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
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
|
||||
// Check that the session has expired and queries fail
|
||||
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();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
let res = res.as_object().unwrap();
|
||||
assert_eq!(
|
||||
res["error"],
|
||||
|
@ -1024,15 +1024,15 @@ async fn session_expiration() {
|
|||
),
|
||||
)
|
||||
.await;
|
||||
assert!(res.is_ok(), "result: {:?}", res);
|
||||
assert!(res.is_ok(), "result: {res:?}");
|
||||
let res = res.unwrap();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
let res = res.as_object().unwrap();
|
||||
// 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
|
||||
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
|
||||
server.finish().unwrap();
|
||||
}
|
||||
|
@ -1093,28 +1093,28 @@ async fn session_expiration_operations() {
|
|||
),
|
||||
)
|
||||
.await;
|
||||
assert!(res.is_ok(), "result: {:?}", res);
|
||||
assert!(res.is_ok(), "result: {res:?}");
|
||||
let res = res.unwrap();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
let res = res.as_object().unwrap();
|
||||
// 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
|
||||
assert!(res["result"].is_string(), "result: {:?}", res);
|
||||
assert!(res["result"].is_string(), "result: {res:?}");
|
||||
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
|
||||
socket.send_request("authenticate", json!([res,])).await.unwrap();
|
||||
// Check if the session is now authenticated
|
||||
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
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
|
||||
// Check if the session is now expired
|
||||
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();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
let res = res.as_object().unwrap();
|
||||
assert_eq!(
|
||||
res["error"],
|
||||
|
@ -1187,9 +1187,9 @@ async fn session_expiration_operations() {
|
|||
// Futures are executed sequentially as some operations rely on the previous state
|
||||
for operation in operations_ko {
|
||||
let res = operation.await;
|
||||
assert!(res.is_ok(), "result: {:?}", res);
|
||||
assert!(res.is_ok(), "result: {res:?}");
|
||||
let res = res.unwrap();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
let res = res.as_object().unwrap();
|
||||
assert_eq!(
|
||||
res["error"],
|
||||
|
@ -1207,12 +1207,12 @@ async fn session_expiration_operations() {
|
|||
// Futures are executed sequentially as some operations rely on the previous state
|
||||
for operation in operations_ok {
|
||||
let res = operation.await;
|
||||
assert!(res.is_ok(), "result: {:?}", res);
|
||||
assert!(res.is_ok(), "result: {res:?}");
|
||||
let res = res.unwrap();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
let res = res.as_object().unwrap();
|
||||
// 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
|
||||
|
@ -1229,19 +1229,19 @@ async fn session_expiration_operations() {
|
|||
}]),
|
||||
)
|
||||
.await;
|
||||
assert!(res.is_ok(), "result: {:?}", res);
|
||||
assert!(res.is_ok(), "result: {res:?}");
|
||||
let res = res.unwrap();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
let res = res.as_object().unwrap();
|
||||
// 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
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
|
||||
// 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;
|
||||
assert!(res.is_ok(), "result: {:?}", res);
|
||||
assert!(res.is_ok(), "result: {res:?}");
|
||||
let res = res.unwrap();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
let res = res.as_object().unwrap();
|
||||
assert_eq!(
|
||||
res["error"],
|
||||
|
@ -1261,19 +1261,19 @@ async fn session_expiration_operations() {
|
|||
),
|
||||
)
|
||||
.await;
|
||||
assert!(res.is_ok(), "result: {:?}", res);
|
||||
assert!(res.is_ok(), "result: {res:?}");
|
||||
let res = res.unwrap();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
let res = res.as_object().unwrap();
|
||||
// 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
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
|
||||
// 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;
|
||||
assert!(res.is_ok(), "result: {:?}", res);
|
||||
assert!(res.is_ok(), "result: {res:?}");
|
||||
let res = res.unwrap();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
let res = res.as_object().unwrap();
|
||||
assert_eq!(
|
||||
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
|
||||
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();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
let res = res.as_object().unwrap();
|
||||
// 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
|
||||
server.finish().unwrap();
|
||||
|
@ -1350,34 +1350,33 @@ async fn session_reauthentication() {
|
|||
),
|
||||
)
|
||||
.await;
|
||||
assert!(res.is_ok(), "result: {:?}", res);
|
||||
assert!(res.is_ok(), "result: {res:?}");
|
||||
let res = res.unwrap();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
let res = res.as_object().unwrap();
|
||||
// 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
|
||||
assert!(res["result"].is_string(), "result: {:?}", res);
|
||||
assert!(res["result"].is_string(), "result: {res:?}");
|
||||
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
|
||||
socket.send_request("authenticate", json!([res,])).await.unwrap();
|
||||
// Check that we do not have root access
|
||||
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!(
|
||||
res[0]["result"], "IAM error: Not enough permissions to perform this action",
|
||||
"result: {:?}",
|
||||
res
|
||||
"result: {res:?}"
|
||||
);
|
||||
// Check if the session is authenticated
|
||||
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
|
||||
socket.send_request("authenticate", json!([root_token,])).await.unwrap();
|
||||
// Check that we have root access again
|
||||
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
|
||||
server.finish().unwrap();
|
||||
}
|
||||
|
@ -1439,25 +1438,25 @@ async fn session_reauthentication_expired() {
|
|||
),
|
||||
)
|
||||
.await;
|
||||
assert!(res.is_ok(), "result: {:?}", res);
|
||||
assert!(res.is_ok(), "result: {res:?}");
|
||||
let res = res.unwrap();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
let res = res.as_object().unwrap();
|
||||
// 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
|
||||
assert!(res["result"].is_string(), "result: {:?}", res);
|
||||
assert!(res["result"].is_string(), "result: {res:?}");
|
||||
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
|
||||
socket.send_request("authenticate", json!([res,])).await.unwrap();
|
||||
// Wait two seconds for token to expire
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
|
||||
// Verify that the session has expired
|
||||
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();
|
||||
assert!(res.is_object(), "result: {:?}", res);
|
||||
assert!(res.is_object(), "result: {res:?}");
|
||||
let res = res.as_object().unwrap();
|
||||
assert_eq!(
|
||||
res["error"],
|
||||
|
@ -1467,7 +1466,7 @@ async fn session_reauthentication_expired() {
|
|||
socket.send_request("authenticate", json!([root_token,])).await.unwrap();
|
||||
// Check that we have root access and the session is not expired
|
||||
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
|
||||
server.finish().unwrap();
|
||||
}
|
||||
|
|
|
@ -328,7 +328,7 @@ mod database_upgrade {
|
|||
}
|
||||
|
||||
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_db(DB).await.unwrap();
|
||||
db
|
||||
|
|
|
@ -35,7 +35,7 @@ mod http_integration {
|
|||
let res = client.post(url).body("CREATE foo").send().await?;
|
||||
assert_eq!(res.status(), 200);
|
||||
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
|
||||
|
@ -51,7 +51,7 @@ mod http_integration {
|
|||
client.post(url).basic_auth(USER, Some(PASS)).body("CREATE foo").send().await?;
|
||||
assert_eq!(res.status(), 200);
|
||||
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
|
||||
|
@ -71,7 +71,7 @@ mod http_integration {
|
|||
client.post(url).basic_auth(USER, Some(PASS)).body("INFO FOR ROOT").send().await?;
|
||||
assert_eq!(res.status(), 200);
|
||||
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
|
||||
|
@ -80,7 +80,7 @@ mod http_integration {
|
|||
client.post(url).basic_auth(USER, Some(PASS)).body("INFO FOR NS").send().await?;
|
||||
assert_eq!(res.status(), 200);
|
||||
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
|
||||
|
@ -89,7 +89,7 @@ mod http_integration {
|
|||
client.post(url).basic_auth(USER, Some(PASS)).body("INFO FOR DB").send().await?;
|
||||
assert_eq!(res.status(), 200);
|
||||
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
|
||||
|
@ -103,11 +103,10 @@ mod http_integration {
|
|||
.await?;
|
||||
assert_eq!(res.status(), 200);
|
||||
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!(
|
||||
body[0]["result"], "IAM error: Not enough permissions to perform this action",
|
||||
"body: {}",
|
||||
body
|
||||
"body: {body}"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -122,7 +121,7 @@ mod http_integration {
|
|||
.await?;
|
||||
assert_eq!(res.status(), 200);
|
||||
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
|
||||
|
@ -136,7 +135,7 @@ mod http_integration {
|
|||
.await?;
|
||||
assert_eq!(res.status(), 200);
|
||||
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
|
||||
|
@ -151,11 +150,10 @@ mod http_integration {
|
|||
.await?;
|
||||
assert_eq!(res.status(), 200);
|
||||
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!(
|
||||
body[0]["result"], "IAM error: Not enough permissions to perform this action",
|
||||
"body: {}",
|
||||
body
|
||||
"body: {body}"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -171,11 +169,10 @@ mod http_integration {
|
|||
.await?;
|
||||
assert_eq!(res.status(), 200);
|
||||
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!(
|
||||
body[0]["result"], "IAM error: Not enough permissions to perform this action",
|
||||
"body: {}",
|
||||
body
|
||||
"body: {body}"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -191,7 +188,7 @@ mod http_integration {
|
|||
.await?;
|
||||
assert_eq!(res.status(), 200);
|
||||
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
|
||||
|
@ -236,7 +233,7 @@ mod http_integration {
|
|||
.send()
|
||||
.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
|
||||
|
@ -266,7 +263,7 @@ mod http_integration {
|
|||
let res = client.post(url).bearer_auth(&token).body("CREATE foo").send().await?;
|
||||
assert_eq!(res.status(), 200, "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
|
||||
let res = client
|
||||
|
@ -279,8 +276,8 @@ mod http_integration {
|
|||
.await?;
|
||||
assert_eq!(res.status(), 200, "body: {}", res.text().await?);
|
||||
let body = res.text().await?;
|
||||
assert!(body.contains(&format!(r#""result":["{ns}"]"#)), "body: {}", body);
|
||||
assert!(body.contains(&format!(r#""result":["{db}"]"#)), "body: {}", body);
|
||||
assert!(body.contains(&format!(r#""result":["{ns}"]"#)), "body: {body}");
|
||||
assert!(body.contains(&format!(r#""result":["{db}"]"#)), "body: {body}");
|
||||
}
|
||||
|
||||
// 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?;
|
||||
assert_eq!(res.status(), 200, "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(())
|
||||
|
@ -347,7 +344,7 @@ mod http_integration {
|
|||
let url = &format!("http://{addr}/health");
|
||||
|
||||
let res = Client::default().get(url).send().await?;
|
||||
assert_eq!(res.status(), 200, "response: {:#?}", res);
|
||||
assert_eq!(res.status(), 200, "response: {res:#?}");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -445,7 +442,7 @@ mod http_integration {
|
|||
.await?;
|
||||
assert_eq!(res.status(), 200, "body: {}", res.text().await?);
|
||||
let body = res.text().await?;
|
||||
assert!(body.contains("foo:bvklxkhtxumyrfzqoc5i"), "body: {}", body);
|
||||
assert!(body.contains("foo:bvklxkhtxumyrfzqoc5i"), "body: {body}");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -531,7 +528,7 @@ mod http_integration {
|
|||
assert_eq!(res.status(), 200, "body: {}", res.text().await?);
|
||||
|
||||
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
|
||||
|
@ -599,7 +596,7 @@ mod http_integration {
|
|||
assert_eq!(res.status(), 200, "body: {}", res.text().await?);
|
||||
|
||||
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
|
||||
|
@ -684,7 +681,7 @@ mod http_integration {
|
|||
assert_eq!(res.status(), 200, "body: {}", res.text().await?);
|
||||
|
||||
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
|
||||
|
@ -766,8 +763,7 @@ mod http_integration {
|
|||
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
|
||||
assert!(
|
||||
body["token"].as_str().unwrap().starts_with("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9"),
|
||||
"body: {}",
|
||||
body
|
||||
"body: {body}"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -802,7 +798,7 @@ mod http_integration {
|
|||
assert_eq!(res.status(), 200);
|
||||
|
||||
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
|
||||
|
@ -812,7 +808,7 @@ mod http_integration {
|
|||
assert_eq!(res.status(), 200);
|
||||
|
||||
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
|
||||
|
@ -941,14 +937,14 @@ mod http_integration {
|
|||
let res = client.get(url).send().await?;
|
||||
assert_eq!(res.status(), 200, "body: {}", res.text().await?);
|
||||
let body = res.text().await?;
|
||||
assert_eq!(body, r#"Save"#, "body: {}", body);
|
||||
assert_eq!(body, r#"Save"#, "body: {body}");
|
||||
}
|
||||
// POST
|
||||
{
|
||||
let res = client.post(url).body("").send().await?;
|
||||
assert_eq!(res.status(), 200, "body: {}", res.text().await?);
|
||||
let body = res.text().await?;
|
||||
assert_eq!(body, r#"Load"#, "body: {}", body);
|
||||
assert_eq!(body, r#"Load"#, "body: {body}");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -960,9 +956,9 @@ mod http_integration {
|
|||
let url = &format!("http://{addr}/version");
|
||||
|
||||
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?;
|
||||
assert!(body.starts_with("surrealdb-"), "body: {}", body);
|
||||
assert!(body.starts_with("surrealdb-"), "body: {body}");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -988,8 +984,7 @@ mod http_integration {
|
|||
assert_eq!(
|
||||
body[0]["result"].as_array().unwrap().len(),
|
||||
num_records,
|
||||
"error seeding the table: {}",
|
||||
body
|
||||
"error seeding the table: {body}"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
|
@ -1021,57 +1016,46 @@ mod http_integration {
|
|||
assert_eq!(res.status(), 200, "body: {}", res.text().await?);
|
||||
|
||||
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
|
||||
{
|
||||
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?);
|
||||
|
||||
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
|
||||
{
|
||||
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?);
|
||||
|
||||
let body: serde_json::Value = serde_json::from_str(&res.text().await?).unwrap();
|
||||
assert_eq!(
|
||||
body[0]["result"].as_array().unwrap().len(),
|
||||
num_records - 10,
|
||||
"body: {}",
|
||||
body
|
||||
);
|
||||
assert_eq!(
|
||||
body[0]["result"].as_array().unwrap()[0]["id"],
|
||||
"table:11",
|
||||
"body: {}",
|
||||
body
|
||||
"body: {body}"
|
||||
);
|
||||
assert_eq!(body[0]["result"].as_array().unwrap()[0]["id"], "table:11", "body: {body}");
|
||||
}
|
||||
|
||||
// GET records with a start and limit
|
||||
{
|
||||
let res = client
|
||||
.get(format!("{}?start=10&limit=10", url))
|
||||
.get(format!("{url}?start=10&limit=10"))
|
||||
.basic_auth(USER, Some(PASS))
|
||||
.send()
|
||||
.await?;
|
||||
assert_eq!(res.status(), 200, "body: {}", res.text().await?);
|
||||
|
||||
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()[0]["id"],
|
||||
"table:11",
|
||||
"body: {}",
|
||||
body
|
||||
);
|
||||
assert_eq!(body[0]["result"].as_array().unwrap().len(), 10, "body: {body}");
|
||||
assert_eq!(body[0]["result"].as_array().unwrap()[0]["id"], "table:11", "body: {body}");
|
||||
}
|
||||
|
||||
// GET without authentication returns no records
|
||||
|
@ -1080,7 +1064,7 @@ mod http_integration {
|
|||
assert_eq!(res.status(), 200, "body: {}", res.text().await?);
|
||||
|
||||
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(())
|
||||
|
@ -1108,7 +1092,7 @@ mod http_integration {
|
|||
// Verify there are no records
|
||||
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();
|
||||
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
|
||||
let res = client
|
||||
|
@ -1121,12 +1105,11 @@ mod http_integration {
|
|||
|
||||
// Verify the record was created
|
||||
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]["name"],
|
||||
"record_name",
|
||||
"body: {}",
|
||||
body
|
||||
"body: {body}"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1142,7 +1125,7 @@ mod http_integration {
|
|||
// Verify the table is empty
|
||||
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();
|
||||
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(())
|
||||
|
@ -1181,15 +1164,15 @@ mod http_integration {
|
|||
// Verify the records were updated
|
||||
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();
|
||||
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
|
||||
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
|
||||
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
|
||||
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();
|
||||
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
|
||||
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
|
||||
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
|
||||
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();
|
||||
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
|
||||
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
|
||||
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
|
||||
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();
|
||||
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
|
||||
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
|
||||
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
|
||||
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();
|
||||
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
|
||||
let res = client.delete(url).basic_auth(USER, Some(PASS)).send().await?;
|
||||
|
@ -1319,7 +1302,7 @@ mod http_integration {
|
|||
// Verify the records were deleted
|
||||
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();
|
||||
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
|
||||
|
@ -1333,7 +1316,7 @@ mod http_integration {
|
|||
// Verify the records were not deleted
|
||||
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();
|
||||
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(())
|
||||
|
@ -1364,7 +1347,7 @@ mod http_integration {
|
|||
assert_eq!(res.status(), 200, "body: {}", res.text().await?);
|
||||
|
||||
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
|
||||
|
@ -1373,7 +1356,7 @@ mod http_integration {
|
|||
assert_eq!(res.status(), 200, "body: {}", res.text().await?);
|
||||
|
||||
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(())
|
||||
|
@ -1409,12 +1392,11 @@ mod http_integration {
|
|||
|
||||
// Verify the record was created with the given ID
|
||||
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:new_id",
|
||||
"body: {}",
|
||||
body
|
||||
"body: {body}"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1436,25 +1418,22 @@ mod http_integration {
|
|||
|
||||
// Verify the record was created with the given ID
|
||||
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: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!(
|
||||
body[0]["result"].as_array().unwrap()[0]["elems"].as_array().unwrap().len(),
|
||||
3,
|
||||
"body: {}",
|
||||
body
|
||||
"body: {body}"
|
||||
);
|
||||
assert_eq!(
|
||||
body[0]["result"].as_array().unwrap()[0]["other"].as_object().unwrap()["test"],
|
||||
true,
|
||||
"body: {}",
|
||||
body
|
||||
"body: {body}"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1469,7 +1448,7 @@ mod http_integration {
|
|||
// Verify the table is empty
|
||||
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();
|
||||
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(())
|
||||
|
@ -1507,22 +1486,17 @@ mod http_integration {
|
|||
// Verify the record was updated
|
||||
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();
|
||||
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
|
||||
assert_eq!(
|
||||
body[0]["result"].as_array().unwrap()[0]["name"],
|
||||
"record_name",
|
||||
"body: {}",
|
||||
body
|
||||
"body: {body}"
|
||||
);
|
||||
|
||||
// Verify the record doesn't have the original data
|
||||
assert!(
|
||||
body[0]["result"].as_array().unwrap()[0]["default"].is_null(),
|
||||
"body: {}",
|
||||
body
|
||||
);
|
||||
assert!(body[0]["result"].as_array().unwrap()[0]["default"].is_null(), "body: {body}");
|
||||
}
|
||||
|
||||
// Update one record without authentication
|
||||
|
@ -1534,17 +1508,16 @@ mod http_integration {
|
|||
// Verify the record was not updated
|
||||
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();
|
||||
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
|
||||
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
|
||||
assert_eq!(
|
||||
body[0]["result"].as_array().unwrap()[0]["name"],
|
||||
"record_name",
|
||||
"body: {}",
|
||||
body
|
||||
"body: {body}"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1583,22 +1556,20 @@ mod http_integration {
|
|||
// Verify the records were modified
|
||||
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();
|
||||
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
|
||||
assert_eq!(
|
||||
body[0]["result"].as_array().unwrap()[0]["name"],
|
||||
"record_name",
|
||||
"body: {}",
|
||||
body
|
||||
"body: {body}"
|
||||
);
|
||||
|
||||
// Verify the record has the original data too
|
||||
assert_eq!(
|
||||
body[0]["result"].as_array().unwrap()[0]["default"],
|
||||
"content",
|
||||
"body: {}",
|
||||
body
|
||||
"body: {body}"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1611,17 +1582,16 @@ mod http_integration {
|
|||
// Verify the record was not modified
|
||||
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();
|
||||
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
|
||||
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
|
||||
assert_eq!(
|
||||
body[0]["result"].as_array().unwrap()[0]["default"],
|
||||
"content",
|
||||
"body: {}",
|
||||
body
|
||||
"body: {body}"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1651,33 +1621,30 @@ mod http_integration {
|
|||
// Verify there are records
|
||||
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();
|
||||
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
|
||||
let res = client
|
||||
.delete(format!("{}/1", base_url))
|
||||
.basic_auth(USER, Some(PASS))
|
||||
.send()
|
||||
.await?;
|
||||
let res =
|
||||
client.delete(format!("{base_url}/1")).basic_auth(USER, Some(PASS)).send().await?;
|
||||
assert_eq!(res.status(), 200, "body: {}", res.text().await?);
|
||||
|
||||
// Verify only one record was deleted
|
||||
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();
|
||||
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().len(), 1, "body: {body}");
|
||||
assert_eq!(body[0]["result"].as_array().unwrap()[0]["id"], "table:2", "body: {body}");
|
||||
}
|
||||
|
||||
// Delete one record without authentication
|
||||
{
|
||||
// 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?);
|
||||
|
||||
// Verify the record was not deleted
|
||||
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();
|
||||
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(())
|
||||
|
|
Loading…
Reference in a new issue