Skip to content

Commit 7bbb8ea

Browse files
authored
Support .env files for testing (Azure#2487)
Requires changes to the TestResources scripts, which will need to be merged into Azure/azure-sdk-tools. Client libraries need to opt in. Resolves Azure#2038
1 parent c0a20b0 commit 7bbb8ea

File tree

5 files changed

+28
-1
lines changed

5 files changed

+28
-1
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eng/dict/crates.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ base64
2222
bytes
2323
cargo_metadata
2424
clap
25+
dotenvy
2526
dyn-clone
2627
fe2o3-amqp
2728
fe2o3-amqp-cbs

eng/scripts/verify-dependencies.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ use std::{
1717
process::Command,
1818
};
1919

20-
static EXEMPTIONS: &[(&str, &str)] = &[("azure_template", "serde")];
20+
static EXEMPTIONS: &[(&str, &str)] = &[
21+
("azure_core_test", "dotenvy"),
22+
("azure_template", "serde"),
23+
];
2124

2225
fn main() {
2326
let manifest_path = std::env::args()

sdk/core/azure_core_test/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ async-trait.workspace = true
2323
azure_core = { workspace = true, features = ["test"] }
2424
azure_core_test_macros.workspace = true
2525
azure_identity.workspace = true
26+
dotenvy = "0.15.7"
2627
futures.workspace = true
2728
rand.workspace = true
2829
rand_chacha.workspace = true

sdk/core/azure_core_test/src/recorded.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,21 @@ pub async fn start(
6868
ctx.test_recording_file(),
6969
ctx.test_recording_assets_file(mode),
7070
);
71+
72+
// Attempt to read any .env file up to the repo root.
73+
#[cfg(not(target_arch = "wasm32"))]
74+
if let Ok(path) = crate::find_ancestor_file(ctx.crate_dir, ".env") {
75+
tracing::debug!("loading environment variables from {}", path.display());
76+
77+
use azure_core::error::ResultExt as _;
78+
dotenvy::from_filename(&path).with_context(azure_core::error::ErrorKind::Io, || {
79+
format!(
80+
"failed to load environment variables from {}",
81+
path.display()
82+
)
83+
})?;
84+
};
85+
7186
recording.start().await?;
7287

7388
ctx.recording = Some(recording);

0 commit comments

Comments
 (0)