-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1532f07
commit d24b5fd
Showing
12 changed files
with
167 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use std::path::Path; | ||
|
||
use crate::Db; | ||
use crate::TestServer; | ||
use crate::ADMIN_DB_REMOVE_URI; | ||
use crate::DB_LIST_URI; | ||
use crate::NO_TOKEN; | ||
use serde::Serialize; | ||
|
||
#[derive(Serialize)] | ||
struct DbName<'a> { | ||
name: &'a str, | ||
} | ||
|
||
#[tokio::test] | ||
async fn remove() -> anyhow::Result<()> { | ||
let server = TestServer::new().await?; | ||
let (_, token) = server.init_user().await?; | ||
let db = server.init_db("mapped", &token).await?; | ||
let (status, list) = server.get::<Vec<Db>>(DB_LIST_URI, &token).await?; | ||
assert_eq!(status, 200); | ||
assert!(list?.contains(&Db { | ||
name: db.clone(), | ||
db_type: "mapped".to_string(), | ||
})); | ||
let rem = DbName { name: &db }; | ||
assert_eq!( | ||
server | ||
.post(ADMIN_DB_REMOVE_URI, &rem, &server.admin_token) | ||
.await? | ||
.0, | ||
204 | ||
); | ||
let (status, list) = server.get::<Vec<Db>>(DB_LIST_URI, &token).await?; | ||
assert_eq!(status, 200); | ||
assert!(list?.is_empty()); | ||
assert!(Path::new(&server.dir).join(db).exists()); | ||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn db_not_found() -> anyhow::Result<()> { | ||
let server = TestServer::new().await?; | ||
let db = DbName { name: "some_db" }; | ||
assert_eq!( | ||
server | ||
.post(ADMIN_DB_REMOVE_URI, &db, &server.admin_token) | ||
.await? | ||
.0, | ||
466 | ||
); | ||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn no_admin_token() -> anyhow::Result<()> { | ||
let server = TestServer::new().await?; | ||
let db = DbName { name: "some_db" }; | ||
assert_eq!( | ||
server.post(ADMIN_DB_REMOVE_URI, &db, NO_TOKEN).await?.0, | ||
401 | ||
); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters