chore: testing fixes and cargo cleanup
This change makes sure all dependencies are now in the workspace-level Cargo.toml. Uses the `temp-env` crate to make the config tests less flaky.
This commit is contained in:
10
Cargo.lock
generated
10
Cargo.lock
generated
@@ -214,6 +214,7 @@ dependencies = [
|
||||
"serde_json",
|
||||
"sha2",
|
||||
"task-local-extensions",
|
||||
"temp-env",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tracing",
|
||||
@@ -2082,6 +2083,15 @@ dependencies = [
|
||||
"pin-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "temp-env"
|
||||
version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "96374855068f47402c3121c6eed88d29cb1de8f3ab27090e273e420bdabcf050"
|
||||
dependencies = [
|
||||
"parking_lot",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termtree"
|
||||
version = "0.5.1"
|
||||
|
||||
@@ -24,7 +24,7 @@ rust_decimal = { version = "1.33", features = ["serde-float"] }
|
||||
async-trait = "0.1"
|
||||
dotenvy = "0.15"
|
||||
clap = { version = "4.4", features = ["derive", "env"] }
|
||||
reqwest = { version = "0.11", default-features = false, features = ["json", "multipart", "rustls-tls"] }
|
||||
reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls"] }
|
||||
url = "2.5"
|
||||
wiremock = "0.5"
|
||||
tokio-test = "0.4"
|
||||
@@ -33,3 +33,10 @@ tokio-test = "0.4"
|
||||
hyper = { version = "0.14", features = ["full"] }
|
||||
bytes = "1.0"
|
||||
comfy-table = "7.1"
|
||||
http = "0.2"
|
||||
task-local-extensions = "0.1"
|
||||
aes-gcm = "0.10"
|
||||
pbkdf2 = "0.12"
|
||||
rand = "0.8"
|
||||
sha2 = "0.10"
|
||||
temp-env = "0.3"
|
||||
|
||||
@@ -29,17 +29,18 @@ gocardless-client = { path = "../gocardless-client" }
|
||||
reqwest-middleware = { workspace = true }
|
||||
hyper = { workspace = true }
|
||||
bytes = { workspace = true }
|
||||
http = "0.2"
|
||||
task-local-extensions = "0.1"
|
||||
http = { workspace = true }
|
||||
task-local-extensions = { workspace = true }
|
||||
|
||||
# Encryption dependencies
|
||||
aes-gcm = "0.10"
|
||||
pbkdf2 = "0.12"
|
||||
rand = "0.8"
|
||||
sha2 = "0.10"
|
||||
aes-gcm = { workspace = true }
|
||||
pbkdf2 = { workspace = true }
|
||||
rand = { workspace = true }
|
||||
sha2 = { workspace = true }
|
||||
|
||||
# CLI formatting dependencies
|
||||
comfy-table = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
mockall = { workspace = true }
|
||||
temp-env = { workspace = true }
|
||||
|
||||
@@ -108,112 +108,126 @@ impl LoggingConfig {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::env;
|
||||
use temp_env::with_vars;
|
||||
|
||||
#[test]
|
||||
fn test_gocardless_config_from_env() {
|
||||
env::set_var("GOCARDLESS_ID", "test-id");
|
||||
env::set_var("GOCARDLESS_KEY", "test-key");
|
||||
env::set_var("GOCARDLESS_URL", "https://test.example.com");
|
||||
|
||||
with_vars(
|
||||
[
|
||||
("GOCARDLESS_ID", Some("test-id")),
|
||||
("GOCARDLESS_KEY", Some("test-key")),
|
||||
("GOCARDLESS_URL", Some("https://test.example.com")),
|
||||
],
|
||||
|| {
|
||||
let config = GoCardlessConfig::from_env().unwrap();
|
||||
assert_eq!(config.secret_id, "test-id");
|
||||
assert_eq!(config.secret_key, "test-key");
|
||||
assert_eq!(config.url, "https://test.example.com");
|
||||
|
||||
env::remove_var("GOCARDLESS_ID");
|
||||
env::remove_var("GOCARDLESS_KEY");
|
||||
env::remove_var("GOCARDLESS_URL");
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_gocardless_config_default_url() {
|
||||
env::set_var("GOCARDLESS_ID", "test-id");
|
||||
env::set_var("GOCARDLESS_KEY", "test-key");
|
||||
env::remove_var("GOCARDLESS_URL");
|
||||
|
||||
with_vars(
|
||||
[
|
||||
("GOCARDLESS_ID", Some("test-id")),
|
||||
("GOCARDLESS_KEY", Some("test-key")),
|
||||
("GOCARDLESS_URL", None),
|
||||
],
|
||||
|| {
|
||||
let config = GoCardlessConfig::from_env().unwrap();
|
||||
assert_eq!(config.url, "https://bankaccountdata.gocardless.com");
|
||||
|
||||
env::remove_var("GOCARDLESS_ID");
|
||||
env::remove_var("GOCARDLESS_KEY");
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_gocardless_config_missing_id() {
|
||||
env::remove_var("GOCARDLESS_ID");
|
||||
env::set_var("GOCARDLESS_KEY", "test-key");
|
||||
|
||||
with_vars(
|
||||
[
|
||||
("GOCARDLESS_ID", None),
|
||||
("GOCARDLESS_KEY", Some("test-key")),
|
||||
],
|
||||
|| {
|
||||
let result = GoCardlessConfig::from_env();
|
||||
assert!(result.is_err());
|
||||
|
||||
env::remove_var("GOCARDLESS_KEY");
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_firefly_config_from_env() {
|
||||
env::set_var("FIREFLY_III_URL", "https://firefly.test.com");
|
||||
env::set_var("FIREFLY_III_API_KEY", "test-api-key");
|
||||
|
||||
with_vars(
|
||||
[
|
||||
("FIREFLY_III_URL", Some("https://firefly.test.com")),
|
||||
("FIREFLY_III_API_KEY", Some("test-api-key")),
|
||||
],
|
||||
|| {
|
||||
let config = FireflyConfig::from_env().unwrap();
|
||||
assert_eq!(config.url, "https://firefly.test.com");
|
||||
assert_eq!(config.api_key, "test-api-key");
|
||||
|
||||
env::remove_var("FIREFLY_III_URL");
|
||||
env::remove_var("FIREFLY_III_API_KEY");
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cache_config_from_env() {
|
||||
env::set_var("BANKS2FF_CACHE_KEY", "test-cache-key");
|
||||
env::set_var("BANKS2FF_CACHE_DIR", "/tmp/test-cache");
|
||||
|
||||
with_vars(
|
||||
[
|
||||
("BANKS2FF_CACHE_KEY", Some("test-cache-key")),
|
||||
("BANKS2FF_CACHE_DIR", Some("/tmp/test-cache")),
|
||||
],
|
||||
|| {
|
||||
let config = CacheConfig::from_env().unwrap();
|
||||
assert_eq!(config.key, "test-cache-key");
|
||||
assert_eq!(config.directory, "/tmp/test-cache");
|
||||
|
||||
env::remove_var("BANKS2FF_CACHE_KEY");
|
||||
env::remove_var("BANKS2FF_CACHE_DIR");
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cache_config_default_directory() {
|
||||
env::remove_var("BANKS2FF_CACHE_DIR");
|
||||
env::set_var("BANKS2FF_CACHE_KEY", "test-cache-key");
|
||||
|
||||
with_vars(
|
||||
[
|
||||
("BANKS2FF_CACHE_DIR", None),
|
||||
("BANKS2FF_CACHE_KEY", Some("test-cache-key")),
|
||||
],
|
||||
|| {
|
||||
let config = CacheConfig::from_env().unwrap();
|
||||
assert_eq!(config.directory, "data/cache");
|
||||
|
||||
env::remove_var("BANKS2FF_CACHE_KEY");
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_logging_config_from_env() {
|
||||
env::set_var("RUST_LOG", "debug");
|
||||
|
||||
with_vars([("RUST_LOG", Some("debug"))], || {
|
||||
let config = LoggingConfig::from_env().unwrap();
|
||||
assert_eq!(config.level, "debug");
|
||||
|
||||
env::remove_var("RUST_LOG");
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_logging_config_default() {
|
||||
env::remove_var("RUST_LOG");
|
||||
|
||||
with_vars([("RUST_LOG", None::<&str>)], || {
|
||||
let config = LoggingConfig::from_env().unwrap();
|
||||
assert_eq!(config.level, "warn");
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_full_config_from_env() {
|
||||
env::set_var("GOCARDLESS_ID", "test-id");
|
||||
env::set_var("GOCARDLESS_KEY", "test-key");
|
||||
env::set_var("FIREFLY_III_URL", "https://firefly.test.com");
|
||||
env::set_var("FIREFLY_III_API_KEY", "test-api-key");
|
||||
env::set_var("BANKS2FF_CACHE_KEY", "test-cache-key");
|
||||
env::set_var("RUST_LOG", "info");
|
||||
|
||||
with_vars(
|
||||
[
|
||||
("GOCARDLESS_ID", Some("test-id")),
|
||||
("GOCARDLESS_KEY", Some("test-key")),
|
||||
("FIREFLY_III_URL", Some("https://firefly.test.com")),
|
||||
("FIREFLY_III_API_KEY", Some("test-api-key")),
|
||||
("BANKS2FF_CACHE_KEY", Some("test-cache-key")),
|
||||
("RUST_LOG", Some("info")),
|
||||
],
|
||||
|| {
|
||||
let config = Config::from_env().unwrap();
|
||||
assert_eq!(config.gocardless.secret_id, "test-id");
|
||||
assert_eq!(config.gocardless.secret_key, "test-key");
|
||||
@@ -221,12 +235,7 @@ impl LoggingConfig {
|
||||
assert_eq!(config.firefly.api_key, "test-api-key");
|
||||
assert_eq!(config.cache.key, "test-cache-key");
|
||||
assert_eq!(config.logging.level, "info");
|
||||
|
||||
env::remove_var("GOCARDLESS_ID");
|
||||
env::remove_var("GOCARDLESS_KEY");
|
||||
env::remove_var("FIREFLY_III_URL");
|
||||
env::remove_var("FIREFLY_III_API_KEY");
|
||||
env::remove_var("BANKS2FF_CACHE_KEY");
|
||||
env::remove_var("RUST_LOG");
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user