aboutsummaryrefslogtreecommitdiff
path: root/src/datastructures.rs
diff options
context:
space:
mode:
authorKunoiSayami <[email protected]>2021-05-12 23:45:07 +0800
committerKunoiSayami <[email protected]>2021-05-12 23:45:07 +0800
commite027dbcff8f844beb6b90b8d934e97e2a8b9bd9a (patch)
tree88cf2eefeddd99ac04d7cb5712dbe4a49a0c1f4d /src/datastructures.rs
parent096186b2ca129d83b1041a2a9226d5a7fba0226b (diff)
refactor(core): Add a way to run unit test in cargo
Diffstat (limited to 'src/datastructures.rs')
-rw-r--r--src/datastructures.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/datastructures.rs b/src/datastructures.rs
index 7bdbab5..e4bc879 100644
--- a/src/datastructures.rs
+++ b/src/datastructures.rs
@@ -38,7 +38,7 @@ const DEFAULT_DATABASE_LOCATION: &str = "/etc/cgit/auth.db";
pub const CACHE_DIR: &str = "/var/cache/cgit";
pub type RandIntType = u32;
//pub const MINIMUM_SECRET_LENGTH: usize = 8;
-const COOKIE_LENGTH: usize = 32;
+pub const COOKIE_LENGTH: usize = 32;
pub fn get_current_timestamp() -> u64 {
let start = std::time::SystemTime::now();
@@ -76,6 +76,7 @@ pub struct Config {
//access_node: hashmap,
pub bypass_root: bool,
//secret: String,
+ pub(crate) test: bool,
}
impl Default for Config {
@@ -85,6 +86,7 @@ impl Default for Config {
database: DEFAULT_DATABASE_LOCATION.to_string(),
bypass_root: false,
//secret: Default::default(),
+ test: false,
}
}
}
@@ -124,6 +126,7 @@ impl Config {
cookie_ttl,
database: database.to_string(),
bypass_root,
+ test: false,
//secret: secret.to_string(),
}
}
@@ -143,12 +146,25 @@ impl Config {
}*/
pub fn get_copied_database_location(&self) -> PathBuf {
+ if self.test {
+ return PathBuf::from(self.database.as_str())
+ }
+
std::path::Path::new(CACHE_DIR).join(
std::path::Path::new(self.get_database_location())
.file_name()
.unwrap(),
)
}
+
+ pub(crate) fn generate_test_config() -> Self {
+ Self {
+ database: "test/tmp.db".to_string(),
+ bypass_root: false,
+ cookie_ttl: DEFAULT_COOKIE_TTL,
+ test: true,
+ }
+ }
}
#[derive(Debug, Clone, Default)]