Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions blueprint/cli/src/bin/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,15 +496,19 @@ fn get_db_config(config: &DatabaseConfig) -> PgConnectOptions {

async fn get_db_client(config: &DatabaseConfig) -> PgConnection {
let db_config = get_db_config(config);
let connection: PgConnection = Connection::connect_with(&db_config).await.unwrap();
let connection: PgConnection = Connection::connect_with(&db_config)
.await
.expect("Should be able to connect to the database!");

connection
}

async fn get_root_db_client(config: &DatabaseConfig) -> PgConnection {
let db_config = get_db_config(config);
let root_db_config = db_config.clone().database("postgres");
let connection: PgConnection = Connection::connect_with(&root_db_config).await.unwrap();
let connection: PgConnection = Connection::connect_with(&root_db_config)
.await
.expect("Should be able to connect to the database!");

connection
}
Expand Down
11 changes: 8 additions & 3 deletions blueprint/cli/src/bin/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ fn get_liquid_template(path: &str) -> Result<Template, anyhow::Error> {
.context(format!("Failed to read blueprint {path}!"))?;
let template = liquid::ParserBuilder::with_stdlib()
.build()
.unwrap()
.context("Failed to build Liquid parser")?
.parse(template_source)
.context("Failed to parse blueprint as Liquid template")?;

Expand Down Expand Up @@ -508,10 +508,15 @@ fn validate_fields(fields: &[String]) -> Result<Vec<HashMap<String, String>>, an
return Err(anyhow!("Invalid field definition: {field}!"));
}

let field_name = String::from(captures.get(1).unwrap().as_str());
let field_name = String::from(
captures
.get(1)
.expect("Should be able to get the field name")
.as_str(),
);
let field_type = captures
.get(2)
.unwrap()
.expect("Should be able to get the field type")
.as_str()
.replace("Bool", "bool")
.replace("string", "String");
Expand Down
28 changes: 21 additions & 7 deletions blueprint/db/src/test_helpers/mod.rs.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,41 @@ pub async fn teardown_db(db_pool: DbPool) {
drop(db_pool);

let root_db_config = db_config.clone().database("postgres");
let mut connection: PgConnection = Connection::connect_with(&root_db_config).await.unwrap();
let mut connection: PgConnection = Connection::connect_with(&root_db_config)
.await
.expect("Should be able to connect to Postgres database!");

let test_db_name = db_config.get_database().unwrap();
let test_db_name = db_config
.get_database()
.expect("Should be able to get the database name!");

let query = format!("DROP DATABASE IF EXISTS {test_db_name}");
connection.execute(query.as_str()).await.unwrap();
connection
.execute(query.as_str())
.await
.unwrap_or_else(|_| panic!("Could not execute DROP DATABASE {test_db_name} query!"));
}

async fn prepare_db(config: &DatabaseConfig) -> DatabaseConfig {
let db_config = parse_db_config(&config.url);
let db_name = db_config.get_database().unwrap();
let db_name = db_config
.get_database()
.expect("Should be able to get the database name!");

let root_db_config = db_config.clone().database("postgres");
let mut connection: PgConnection = Connection::connect_with(&root_db_config).await.unwrap();
let mut connection: PgConnection = Connection::connect_with(&root_db_config)
.await
.expect("Should be able to connect to the Postgres database!");

let test_db_name = build_test_db_name(db_name);

let query = format!("CREATE DATABASE {test_db_name} TEMPLATE {db_name}");
connection.execute(query.as_str()).await.unwrap();
connection
.execute(query.as_str())
.await
.unwrap_or_else(|_| panic!("Could not execute CREATE DATABASE {test_db_name} query!"));

let regex = Regex::new(r"(.+)\/(.+$)").unwrap();
let regex = Regex::new(r"(.+)/(.+$)").expect("Should be able to compile regex");
let test_db_url = regex.replace(&config.url, |caps: &Captures| {
format!("{}/{}", &caps[1], test_db_name)
});
Expand Down
2 changes: 1 addition & 1 deletion blueprint/web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub async fn run() -> anyhow::Result<()> {
pub fn init_tracing() {
let filter = EnvFilter::try_from_default_env()
.or_else(|_| EnvFilter::try_new("info"))
.unwrap();
.expect("Should be able to parse RUST_LOG or construct default filter from info level");
tracing_subscriber::registry()
.with(fmt::layer())
.with(filter)
Expand Down
15 changes: 11 additions & 4 deletions blueprint/web/src/test_helpers/mod.rs.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ impl TestRequest {
#[allow(unused)]
#[must_use]
pub fn header(mut self, name: HeaderName, value: &str) -> Self {
self.headers.insert(name, value.parse().unwrap());
self.headers.insert(
name,
value.parse().expect("Should be abe to parse header value"),
);
self
}

Expand Down Expand Up @@ -112,9 +115,11 @@ impl TestRequest {

request_builder = request_builder.method(&self.method);

let request = request_builder.body(self.body);
let request = request_builder
.body(self.body)
.expect("Should be able to build request");

self.router.oneshot(request.unwrap()).await.unwrap()
self.router.oneshot(request).await.unwrap()
}
}

Expand Down Expand Up @@ -222,7 +227,9 @@ pub struct DbTestContext {
#[allow(unused)]
pub async fn setup() -> DbTestContext {
let init_config: OnceCell<Config> = OnceCell::new();
let config = init_config.get_or_init(|| load_config(&Environment::Test).unwrap());
let config = init_config.get_or_init(|| {
load_config(&Environment::Test).expect("Should be able to load Test environment config")
});

let test_db_pool = setup_db(&config.database).await;

Expand Down
6 changes: 4 additions & 2 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,10 @@ mod tests {
}

fn read_buffer(buffer: std::io::BufWriter<Vec<u8>>) -> String {
let bytes = buffer.into_inner().unwrap();
let bytes = buffer
.into_inner()
.expect("Should be able to flush the buffer!");

String::from_utf8(bytes).unwrap()
String::from_utf8(bytes).expect("Should be able to convert the buffer to a string!")
}
}
Loading