Skip to content

Commit d55d62e

Browse files
committed
fix config tests
Signed-off-by: Eren Atas <[email protected]>
1 parent 6f43120 commit d55d62e

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

crates/flagd/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,9 @@ impl Default for FlagdOptions {
342342
provider_id: std::env::var("FLAGD_PROVIDER_ID").ok(),
343343
};
344344

345-
if options.source_configuration.is_some() && options.resolver_type != ResolverType::Rpc {
345+
let resolver_env_set = std::env::var("FLAGD_RESOLVER").is_ok();
346+
if options.source_configuration.is_some() && !resolver_env_set {
347+
// Only override to File if FLAGD_RESOLVER wasn't explicitly set
346348
options.resolver_type = ResolverType::File;
347349
}
348350

crates/flagd/tests/gherkin_config_test.rs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,24 @@ impl ConfigWorld {
2424

2525
fn clear(&mut self) {
2626
// SAFETY: Removing environment variables is safe here because:
27-
// 1. We're only removing variables that were set during this specific test scenario
28-
// 2. The test is protected by #[serial_test::serial]
29-
// 3. This prevents test pollution between scenarios
30-
// 4. All variables being removed are tracked in world.env_vars
27+
// 1. The test is protected by #[serial_test::serial]
28+
// 2. This prevents test pollution between scenarios
29+
// 3. We clear env vars that were set in previous scenarios
30+
31+
// Clear env vars that were set in the previous scenario
3132
for key in self.env_vars.keys() {
3233
unsafe {
3334
std::env::remove_var(key);
3435
}
3536
}
37+
38+
// Also explicitly clear FLAGD_OFFLINE_FLAG_SOURCE_PATH because it can affect resolver type
39+
// via FlagdOptions::default() logic, even if not tracked in world.env_vars
40+
unsafe {
41+
std::env::remove_var("FLAGD_OFFLINE_FLAG_SOURCE_PATH");
42+
}
43+
3644
self.env_vars.clear();
37-
3845
self.options = FlagdOptions::default();
3946
self.provider = None;
4047
self.option_values.clear();
@@ -110,7 +117,27 @@ async fn initialize_config(world: &mut ConfigWorld) {
110117
let mut options = FlagdOptions::default();
111118
let mut resolver_explicitly_set = false;
112119

113-
// Handle resolver type first - explicit options override env vars
120+
// Apply env vars from world.env_vars to ensure they take precedence
121+
// This handles cases where env vars were set in test steps but timing issues
122+
// prevent FlagdOptions::default() from reading them correctly
123+
if let Some(resolver) = world.env_vars.get("FLAGD_RESOLVER") {
124+
options.resolver_type = match resolver.to_uppercase().as_str() {
125+
"RPC" => ResolverType::Rpc,
126+
"REST" => ResolverType::Rest,
127+
"IN-PROCESS" | "INPROCESS" => ResolverType::InProcess,
128+
"FILE" | "OFFLINE" => ResolverType::File,
129+
_ => ResolverType::Rpc,
130+
};
131+
resolver_explicitly_set = true;
132+
// Update port based on resolver type when set via env var
133+
options.port = match options.resolver_type {
134+
ResolverType::Rpc => 8013,
135+
ResolverType::InProcess => 8015,
136+
_ => options.port,
137+
};
138+
}
139+
140+
// Handle explicit options - these override env vars
114141
if let Some(resolver) = world.option_values.get("resolver") {
115142
options.resolver_type = match resolver.to_uppercase().as_str() {
116143
"RPC" => ResolverType::Rpc,

0 commit comments

Comments
 (0)