Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelvlach committed Apr 14, 2024
1 parent 7128f8f commit 140d1f2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
18 changes: 13 additions & 5 deletions agdb_server/tests/routes/misc_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ use std::process::Command;
async fn error() -> anyhow::Result<()> {
let server = TestServer::new().await?;
let client = reqwest::Client::new();
let status = client.get(server.url("/test_error")).send().await?.status();
let status = client
.get(server.full_url("/test_error"))
.send()
.await?
.status();
assert_eq!(status, StatusCode::INTERNAL_SERVER_ERROR);
Ok(())
}
Expand All @@ -20,7 +24,11 @@ async fn error() -> anyhow::Result<()> {
async fn missing() -> anyhow::Result<()> {
let server = TestServer::new().await?;
let client = reqwest::Client::new();
let status = client.get(server.url("/missing")).send().await?.status();
let status = client
.get(server.full_url("/missing"))
.send()
.await?
.status();
assert_eq!(status, StatusCode::NOT_FOUND);
Ok(())
}
Expand All @@ -46,7 +54,7 @@ async fn shutdown_bad_token() -> anyhow::Result<()> {
let server = TestServer::new().await?;
let client = reqwest::Client::new();
let status = client
.post(server.url("/admin/shutdown"))
.post(server.full_url("/admin/shutdown"))
.bearer_auth("bad")
.send()
.await?
Expand All @@ -60,7 +68,7 @@ async fn openapi() -> anyhow::Result<()> {
let server = TestServer::new().await?;
let client = reqwest::Client::new();
let status = client
.get(server.url("/openapi.json"))
.get(server.full_url("/openapi.json"))
.send()
.await?
.status();
Expand All @@ -69,7 +77,7 @@ async fn openapi() -> anyhow::Result<()> {
}

#[tokio::test]
async fn db_config_reuse() -> anyhow::Result<()> {
async fn config_reuse() -> anyhow::Result<()> {
let mut server = TestServerImpl::new().await?;
let mut client = AgdbApi::new(ReqwestClient::new(), &server.address);
client.user_login(ADMIN, ADMIN).await?;
Expand Down
11 changes: 10 additions & 1 deletion agdb_server/tests/test_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ impl TestServerImpl {
return Ok(());
}

let address = self.address.clone();
let mut address = self.address.clone();

if !address.starts_with("http") {
address = format!("http://{}", address);
}

let mut admin = HashMap::<&str, String>::new();
admin.insert("username", ADMIN.to_string());
admin.insert("password", ADMIN.to_string());
Expand Down Expand Up @@ -184,6 +189,10 @@ impl TestServer {
pub fn url(&self, uri: &str) -> String {
format!("{}{uri}", self.api.address())
}

pub fn full_url(&self, uri: &str) -> String {
format!("http://{}/api/v1{uri}", self.api.address())
}
}

impl Drop for TestServerImpl {
Expand Down

0 comments on commit 140d1f2

Please sign in to comment.