Skip to content

Commit

Permalink
Fix arangodb test config
Browse files Browse the repository at this point in the history
  • Loading branch information
bikeshedder committed Nov 3, 2021
1 parent 47d01be commit dfc293e
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions arangodb/tests/arangodb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,48 @@ use serde_1::Deserialize;
use deadpool_arangodb::{Pool, Runtime};


fn default_dbname() -> String {
"deadpool".to_string()
}


#[derive(Debug, Default, Deserialize)]
#[serde(crate = "serde_1")]
struct Config {
#[serde(default)]
arango: deadpool_arangodb::Config,
#[serde(default="default_dbname")]
dbname: String,
}

impl Config {
pub fn from_env() -> Self {
let mut cfg = Config::test_default();
let mut cfg = config::Config::new();
cfg.merge(config::Environment::new().separator("__"))
.unwrap();
cfg.try_into().unwrap()
}

pub fn test_default() -> Self {
Self {
arango: deadpool_arangodb::Config {
url: Some("http://localhost:8529".to_string()),
username: Some("root".to_string()),
password: Some("deadpool".to_string()),
use_jwt: true,
pool: None,
}
}
let mut cfg = cfg.try_into::<Self>().unwrap();
cfg.arango.url.get_or_insert("http://localhost:8529".to_string());
cfg
}
}

fn create_pool() -> Pool {
let cfg = Config::test_default();
cfg.arango.create_pool(Runtime::Tokio1).unwrap()
}

const DB_NAME: &str = "deadpool";

#[tokio::test]
async fn create_database() {
let pool = create_pool();
let cfg = Config::from_env();
let pool = cfg.arango.create_pool(Runtime::Tokio1).unwrap();
let conn = pool.get().await.unwrap();

let result = conn.create_database(DB_NAME).await;
let result = conn.create_database(&cfg.dbname).await;
if let Err(e) = result {
assert!(false, "Failed to create database: {:?}", e)
};
let result = conn.db(DB_NAME).await;
let result = conn.db(&cfg.dbname).await;
assert!(result.is_ok());

let result = conn.drop_database(DB_NAME).await;
let result = conn.drop_database(&cfg.dbname).await;
if let Err(e) = result {
assert!(false, "Failed to drop database: {:?}", e)
};
let result = conn.db(DB_NAME).await;
let result = conn.db(&cfg.dbname).await;
assert!(result.is_err());
}

0 comments on commit dfc293e

Please sign in to comment.