Skip to content

Commit c0e4351

Browse files
author
Jean-Pierre de Villiers
committed
fix(test): prevent panic when .env is absent
The `dotenv!` macro panics if no file named `.env` is present in the workspace root. Use `dotenv::var` function instead.
1 parent 3d94671 commit c0e4351

File tree

4 files changed

+5
-34
lines changed

4 files changed

+5
-34
lines changed

.github/workflows/rust-workspace-test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ jobs:
5252
-
5353
name: cargo test
5454
uses: MarcoPolo/cargo@a527bf4d534717ff4424a84446c5d710f8833139
55+
env:
56+
ALGORAND_MNEMONIC: ${{ secrets.TEST_ALGORAND_MNEMONIC }}
5557
with:
5658
working-directory: rust-workspace
5759
command: test

rust-workspace/Cargo.lock

Lines changed: 1 addition & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust-workspace/crates/ntc-asset-manager/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ url = { version = "2.2", features = ["serde"] }
1717
zeroize = { version = "1.5", features = ["zeroize_derive"] }
1818

1919
[dev-dependencies]
20-
dotenv_codegen = "0.15"
20+
dotenv = { version = "0.15" }
2121
tokio = { version = "1.18", default-features = false, features = ["macros", "rt"] }
2222
mockall = "0.11"

rust-workspace/crates/ntc-asset-manager/tests/algo_explorer.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use dotenv_codegen::dotenv;
21
use ntc_asset_manager::{
32
algorand::Address,
43
algorand::{Account, Algod, AlgonautAlgod},
@@ -10,13 +9,12 @@ use std::str::FromStr;
109

1110
static ALGO_ENDPOINT: &str = "https://node.testnet.algoexplorerapi.io/";
1211
static ALGO_API_TOKEN: [char; 64] = ['a'; 64];
13-
static ALGORAND_MNEMONIC: &str = dotenv!("ALGORAND_MNEMONIC");
1412

1513
#[tokio::test]
1614
async fn create_new_drt() {
1715
let api_token: String = ALGO_API_TOKEN.iter().collect();
1816
let algod = Algod(AlgonautAlgod::new(ALGO_ENDPOINT, &api_token).unwrap());
19-
let secret = Secret::from_str(ALGORAND_MNEMONIC).unwrap();
17+
let secret = Secret::from_str(&dotenv::var("ALGORAND_MNEMONIC").unwrap()).unwrap();
2018
let account = Account::from_secret(secret).unwrap();
2119

2220
let note = AsaNote {

0 commit comments

Comments
 (0)