test(bf-4lid): add comprehensive test environment config helper tests

- Add GetTestMaxRetries_WithOverride test to verify MAX_RETRIES env var handling
- Add ConfigureTestEnv test to verify all required environment variables are set
- Test coverage includes: valid/invalid env values, all 7 required vars
- All acceptance criteria for bead bf-4lid are now verified
This commit is contained in:
jedarden 2026-07-02 17:39:15 -04:00
parent 2d508816e8
commit 1b597190b1
2 changed files with 102 additions and 0 deletions

50
notes/bf-4lid.md Normal file
View file

@ -0,0 +1,50 @@
# Test Environment Configuration Helper Verification
## Summary
Verified and completed test coverage for test environment configuration helper functions in `proxy/helpers_test.go`.
## Changes Made
### Added Test Cases to `TestHelperFunctions`
1. **`GetTestMaxRetries_WithOverride`** - Tests that `GetTestMaxRetries()` correctly respects the `MAX_RETRIES` environment variable:
- Valid values: 0, 1, 5, 100 are properly parsed and returned
- Invalid values: "abc" (text), "-1" (negative) fall back to `DefaultTestMaxRetries` (1)
2. **`ConfigureTestEnv`** - Tests that `ConfigureTestEnv()` sets all required environment variables:
- `MAX_RETRIES` = "1" (DefaultTestMaxRetries)
- `ZAI_PROXY_TEST_MODE` = "true"
- `DEPLOYMENT_VARIANT` = "test"
- `TOKEN_COUNTING_ENABLED` = "false"
- `RATE_LIMIT_INITIAL` = "1000"
- `RATE_LIMIT_MIN` = "1000"
- `RATE_LIMIT_MAX` = "1000"
## Test Results
All tests pass successfully:
```
=== RUN TestHelperFunctions/GetTestMaxRetries_WithOverride
--- PASS: TestHelperFunctions/GetTestMaxRetries_WithOverride/zero (0.00s)
--- PASS: TestHelperFunctions/GetTestMaxRetries_WithOverride/one (0.00s)
--- PASS: TestHelperFunctions/GetTestMaxRetries_WithOverride/five (0.00s)
--- PASS: TestHelperFunctions/GetTestMaxRetries_WithOverride/large (0.00s)
--- PASS: TestHelperFunctions/GetTestMaxRetries_WithOverride/invalid_text (0.00s)
--- PASS: TestHelperFunctions/GetTestMaxRetries_WithOverride/negative (0.00s)
=== RUN TestHelperFunctions/ConfigureTestEnv
--- PASS: TestHelperFunctions/ConfigureTestEnv/RATE_LIMIT_MAX (0.00s)
--- PASS: TestHelperFunctions/ConfigureTestEnv/MAX_RETRIES (0.00s)
--- PASS: TestHelperFunctions/ConfigureTestEnv/ZAI_PROXY_TEST_MODE (0.00s)
--- PASS: TestHelperFunctions/ConfigureTestEnv/DEPLOYMENT_VARIANT (0.00s)
--- PASS: TestHelperFunctions/ConfigureTestEnv/TOKEN_COUNTING_ENABLED (0.00s)
--- PASS: TestHelperFunctions/ConfigureTestEnv/RATE_LIMIT_INITIAL (0.00s)
--- PASS: TestHelperFunctions/ConfigureTestEnv/RATE_LIMIT_MIN (0.00s)
```
## Acceptance Criteria Verification
1. ✅ `IsTestMode()` correctly detects test mode during test execution (already covered)
2. ✅ `GetTestMaxRetries()` returns `DefaultTestMaxRetries` (1) by default (already covered)
3. ✅ `GetTestMaxRetries()` respects `MAX_RETRIES` environment variable override (newly added)
4. ✅ `ConfigureTestEnv()` sets all required environment variables (newly added)

View file

@ -605,6 +605,58 @@ func TestHelperFunctions(t *testing.T) {
}
})
t.Run("GetTestMaxRetries_WithOverride", func(t *testing.T) {
// Test that GetTestMaxRetries respects MAX_RETRIES environment variable
testCases := []struct {
name string
envValue string
expected int
shouldDefault bool
}{
{"zero", "0", 0, false},
{"one", "1", 1, false},
{"five", "5", 5, false},
{"large", "100", 100, false},
{"invalid_text", "abc", 1, true}, // Should default to DefaultTestMaxRetries
{"negative", "-1", 1, true}, // Should default to DefaultTestMaxRetries
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Setenv(TestMaxRetriesEnv, tc.envValue)
result := GetTestMaxRetries()
if result != tc.expected {
t.Errorf("Expected %d, got %d", tc.expected, result)
}
})
}
})
t.Run("ConfigureTestEnv", func(t *testing.T) {
// Test that ConfigureTestEnv sets all required environment variables
ConfigureTestEnv(t)
// Verify all required environment variables are set
expectedVars := map[string]string{
TestMaxRetriesEnv: strconv.Itoa(DefaultTestMaxRetries),
TestModeEnv: "true",
"DEPLOYMENT_VARIANT": "test",
"TOKEN_COUNTING_ENABLED": "false",
"RATE_LIMIT_INITIAL": "1000",
"RATE_LIMIT_MIN": "1000",
"RATE_LIMIT_MAX": "1000",
}
for key, expectedValue := range expectedVars {
t.Run(key, func(t *testing.T) {
actualValue := os.Getenv(key)
if actualValue != expectedValue {
t.Errorf("Environment variable %s: expected %q, got %q", key, expectedValue, actualValue)
}
})
}
})
t.Run("CalculateBackoffDelay", func(t *testing.T) {
testCases := []struct {
attempt int