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",
|
"serde_json",
|
||||||
"sha2",
|
"sha2",
|
||||||
"task-local-extensions",
|
"task-local-extensions",
|
||||||
|
"temp-env",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
@@ -2082,6 +2083,15 @@ dependencies = [
|
|||||||
"pin-utils",
|
"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]]
|
[[package]]
|
||||||
name = "termtree"
|
name = "termtree"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ rust_decimal = { version = "1.33", features = ["serde-float"] }
|
|||||||
async-trait = "0.1"
|
async-trait = "0.1"
|
||||||
dotenvy = "0.15"
|
dotenvy = "0.15"
|
||||||
clap = { version = "4.4", features = ["derive", "env"] }
|
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"
|
url = "2.5"
|
||||||
wiremock = "0.5"
|
wiremock = "0.5"
|
||||||
tokio-test = "0.4"
|
tokio-test = "0.4"
|
||||||
@@ -33,3 +33,10 @@ tokio-test = "0.4"
|
|||||||
hyper = { version = "0.14", features = ["full"] }
|
hyper = { version = "0.14", features = ["full"] }
|
||||||
bytes = "1.0"
|
bytes = "1.0"
|
||||||
comfy-table = "7.1"
|
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 }
|
reqwest-middleware = { workspace = true }
|
||||||
hyper = { workspace = true }
|
hyper = { workspace = true }
|
||||||
bytes = { workspace = true }
|
bytes = { workspace = true }
|
||||||
http = "0.2"
|
http = { workspace = true }
|
||||||
task-local-extensions = "0.1"
|
task-local-extensions = { workspace = true }
|
||||||
|
|
||||||
# Encryption dependencies
|
# Encryption dependencies
|
||||||
aes-gcm = "0.10"
|
aes-gcm = { workspace = true }
|
||||||
pbkdf2 = "0.12"
|
pbkdf2 = { workspace = true }
|
||||||
rand = "0.8"
|
rand = { workspace = true }
|
||||||
sha2 = "0.10"
|
sha2 = { workspace = true }
|
||||||
|
|
||||||
# CLI formatting dependencies
|
# CLI formatting dependencies
|
||||||
comfy-table = { workspace = true }
|
comfy-table = { workspace = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
mockall = { workspace = true }
|
mockall = { workspace = true }
|
||||||
|
temp-env = { workspace = true }
|
||||||
|
|||||||
@@ -108,112 +108,126 @@ impl LoggingConfig {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use std::env;
|
use temp_env::with_vars;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_gocardless_config_from_env() {
|
fn test_gocardless_config_from_env() {
|
||||||
env::set_var("GOCARDLESS_ID", "test-id");
|
with_vars(
|
||||||
env::set_var("GOCARDLESS_KEY", "test-key");
|
[
|
||||||
env::set_var("GOCARDLESS_URL", "https://test.example.com");
|
("GOCARDLESS_ID", Some("test-id")),
|
||||||
|
("GOCARDLESS_KEY", Some("test-key")),
|
||||||
|
("GOCARDLESS_URL", Some("https://test.example.com")),
|
||||||
|
],
|
||||||
|
|| {
|
||||||
let config = GoCardlessConfig::from_env().unwrap();
|
let config = GoCardlessConfig::from_env().unwrap();
|
||||||
assert_eq!(config.secret_id, "test-id");
|
assert_eq!(config.secret_id, "test-id");
|
||||||
assert_eq!(config.secret_key, "test-key");
|
assert_eq!(config.secret_key, "test-key");
|
||||||
assert_eq!(config.url, "https://test.example.com");
|
assert_eq!(config.url, "https://test.example.com");
|
||||||
|
},
|
||||||
env::remove_var("GOCARDLESS_ID");
|
);
|
||||||
env::remove_var("GOCARDLESS_KEY");
|
|
||||||
env::remove_var("GOCARDLESS_URL");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_gocardless_config_default_url() {
|
fn test_gocardless_config_default_url() {
|
||||||
env::set_var("GOCARDLESS_ID", "test-id");
|
with_vars(
|
||||||
env::set_var("GOCARDLESS_KEY", "test-key");
|
[
|
||||||
env::remove_var("GOCARDLESS_URL");
|
("GOCARDLESS_ID", Some("test-id")),
|
||||||
|
("GOCARDLESS_KEY", Some("test-key")),
|
||||||
|
("GOCARDLESS_URL", None),
|
||||||
|
],
|
||||||
|
|| {
|
||||||
let config = GoCardlessConfig::from_env().unwrap();
|
let config = GoCardlessConfig::from_env().unwrap();
|
||||||
assert_eq!(config.url, "https://bankaccountdata.gocardless.com");
|
assert_eq!(config.url, "https://bankaccountdata.gocardless.com");
|
||||||
|
},
|
||||||
env::remove_var("GOCARDLESS_ID");
|
);
|
||||||
env::remove_var("GOCARDLESS_KEY");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_gocardless_config_missing_id() {
|
fn test_gocardless_config_missing_id() {
|
||||||
env::remove_var("GOCARDLESS_ID");
|
with_vars(
|
||||||
env::set_var("GOCARDLESS_KEY", "test-key");
|
[
|
||||||
|
("GOCARDLESS_ID", None),
|
||||||
|
("GOCARDLESS_KEY", Some("test-key")),
|
||||||
|
],
|
||||||
|
|| {
|
||||||
let result = GoCardlessConfig::from_env();
|
let result = GoCardlessConfig::from_env();
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
|
},
|
||||||
env::remove_var("GOCARDLESS_KEY");
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_firefly_config_from_env() {
|
fn test_firefly_config_from_env() {
|
||||||
env::set_var("FIREFLY_III_URL", "https://firefly.test.com");
|
with_vars(
|
||||||
env::set_var("FIREFLY_III_API_KEY", "test-api-key");
|
[
|
||||||
|
("FIREFLY_III_URL", Some("https://firefly.test.com")),
|
||||||
|
("FIREFLY_III_API_KEY", Some("test-api-key")),
|
||||||
|
],
|
||||||
|
|| {
|
||||||
let config = FireflyConfig::from_env().unwrap();
|
let config = FireflyConfig::from_env().unwrap();
|
||||||
assert_eq!(config.url, "https://firefly.test.com");
|
assert_eq!(config.url, "https://firefly.test.com");
|
||||||
assert_eq!(config.api_key, "test-api-key");
|
assert_eq!(config.api_key, "test-api-key");
|
||||||
|
},
|
||||||
env::remove_var("FIREFLY_III_URL");
|
);
|
||||||
env::remove_var("FIREFLY_III_API_KEY");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cache_config_from_env() {
|
fn test_cache_config_from_env() {
|
||||||
env::set_var("BANKS2FF_CACHE_KEY", "test-cache-key");
|
with_vars(
|
||||||
env::set_var("BANKS2FF_CACHE_DIR", "/tmp/test-cache");
|
[
|
||||||
|
("BANKS2FF_CACHE_KEY", Some("test-cache-key")),
|
||||||
|
("BANKS2FF_CACHE_DIR", Some("/tmp/test-cache")),
|
||||||
|
],
|
||||||
|
|| {
|
||||||
let config = CacheConfig::from_env().unwrap();
|
let config = CacheConfig::from_env().unwrap();
|
||||||
assert_eq!(config.key, "test-cache-key");
|
assert_eq!(config.key, "test-cache-key");
|
||||||
assert_eq!(config.directory, "/tmp/test-cache");
|
assert_eq!(config.directory, "/tmp/test-cache");
|
||||||
|
},
|
||||||
env::remove_var("BANKS2FF_CACHE_KEY");
|
);
|
||||||
env::remove_var("BANKS2FF_CACHE_DIR");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cache_config_default_directory() {
|
fn test_cache_config_default_directory() {
|
||||||
env::remove_var("BANKS2FF_CACHE_DIR");
|
with_vars(
|
||||||
env::set_var("BANKS2FF_CACHE_KEY", "test-cache-key");
|
[
|
||||||
|
("BANKS2FF_CACHE_DIR", None),
|
||||||
|
("BANKS2FF_CACHE_KEY", Some("test-cache-key")),
|
||||||
|
],
|
||||||
|
|| {
|
||||||
let config = CacheConfig::from_env().unwrap();
|
let config = CacheConfig::from_env().unwrap();
|
||||||
assert_eq!(config.directory, "data/cache");
|
assert_eq!(config.directory, "data/cache");
|
||||||
|
},
|
||||||
env::remove_var("BANKS2FF_CACHE_KEY");
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_logging_config_from_env() {
|
fn test_logging_config_from_env() {
|
||||||
env::set_var("RUST_LOG", "debug");
|
with_vars([("RUST_LOG", Some("debug"))], || {
|
||||||
|
|
||||||
let config = LoggingConfig::from_env().unwrap();
|
let config = LoggingConfig::from_env().unwrap();
|
||||||
assert_eq!(config.level, "debug");
|
assert_eq!(config.level, "debug");
|
||||||
|
});
|
||||||
env::remove_var("RUST_LOG");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_logging_config_default() {
|
fn test_logging_config_default() {
|
||||||
env::remove_var("RUST_LOG");
|
with_vars([("RUST_LOG", None::<&str>)], || {
|
||||||
|
|
||||||
let config = LoggingConfig::from_env().unwrap();
|
let config = LoggingConfig::from_env().unwrap();
|
||||||
assert_eq!(config.level, "warn");
|
assert_eq!(config.level, "warn");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_full_config_from_env() {
|
fn test_full_config_from_env() {
|
||||||
env::set_var("GOCARDLESS_ID", "test-id");
|
with_vars(
|
||||||
env::set_var("GOCARDLESS_KEY", "test-key");
|
[
|
||||||
env::set_var("FIREFLY_III_URL", "https://firefly.test.com");
|
("GOCARDLESS_ID", Some("test-id")),
|
||||||
env::set_var("FIREFLY_III_API_KEY", "test-api-key");
|
("GOCARDLESS_KEY", Some("test-key")),
|
||||||
env::set_var("BANKS2FF_CACHE_KEY", "test-cache-key");
|
("FIREFLY_III_URL", Some("https://firefly.test.com")),
|
||||||
env::set_var("RUST_LOG", "info");
|
("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();
|
let config = Config::from_env().unwrap();
|
||||||
assert_eq!(config.gocardless.secret_id, "test-id");
|
assert_eq!(config.gocardless.secret_id, "test-id");
|
||||||
assert_eq!(config.gocardless.secret_key, "test-key");
|
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.firefly.api_key, "test-api-key");
|
||||||
assert_eq!(config.cache.key, "test-cache-key");
|
assert_eq!(config.cache.key, "test-cache-key");
|
||||||
assert_eq!(config.logging.level, "info");
|
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