commit f16daaab5f6272dc59e9bf9631ef141c1c24aa04
parent ee054fe3cc3b8be912cd32cd5f9f76aea2651e33
Author: Jackson G. Kaindume <kaindume@kwatafana.org>
Date: Thu, 22 Sep 2022 21:11:08 +0200
[phora] fix cfg!() attributes
Diffstat:
1 file changed, 21 insertions(+), 9 deletions(-)
diff --git a/phora/src/lib.rs b/phora/src/lib.rs
@@ -34,7 +34,7 @@ impl<D: DB> Cyrtophora<D> {
// TODO: email verification
// store account in database
- if cfg!(sqlite) {
+ if cfg!(feature = "sqlite") {
if let Some(db) = &self.database {
db.account_store(&account)?;
}
@@ -44,7 +44,7 @@ impl<D: DB> Cyrtophora<D> {
/// Get account public data, using the username as ID
pub fn account_get(&self, username: &str) -> Result<PublicAccount, database::error::Error> {
- if cfg!(sqlite) {
+ if cfg!(feature = "sqlite") {
if let Some(db) = &self.database {
let public_account = db.account_get_pub(username)?;
Ok(public_account)
@@ -61,17 +61,29 @@ impl<D: DB> Cyrtophora<D> {
mod test {
use super::*;
- const TEST_DB_PATH: &str = "test-data/ACCOUNTS.db";
+ const TEST_DB_PATH: &str = "test-data/CYRTOPHORA.db";
#[test]
#[cfg(feature = "sqlite")]
- fn test_new_sqlite() {
- let cyrtophora =
- Cyrtophora::<database::sqlite::SqliteDB>::new_sqlite(TEST_DB_PATH).unwrap();
+ fn test_create_and_get_account_sqlite() {
+ remove_test_db();
+ let mut cyrt = Cyrtophora::<database::sqlite::SqliteDB>::new_sqlite(TEST_DB_PATH).unwrap();
+ let account_input = crate::data::AccountCreationInput {
+ username: "testuser".to_string(),
+ password: "1234567890".to_string(),
+ retyped_password: "1234567890".to_string(),
+ email: None,
+ };
- match cyrtophora.database {
- Some(_conn) => assert!(true),
- _ => assert!(false),
+ cyrt.account_create(account_input).unwrap();
+ let public_account = cyrt.account_get("testuser").unwrap();
+ assert_eq!(&public_account.username, "testuser");
+ }
+
+ fn remove_test_db() {
+ let test_db_path = std::path::Path::new(TEST_DB_PATH);
+ if std::path::Path::exists(test_db_path) {
+ std::fs::remove_file(test_db_path).unwrap();
}
}
}