From 1b597190b1363e8d74cca3b166ad47bc264e001a Mon Sep 17 00:00:00 2001 From: jedarden Date: Thu, 2 Jul 2026 17:39:15 -0400 Subject: [PATCH] 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 --- notes/bf-4lid.md | 50 +++++++++++++++++++++++++++++++++++++++++ proxy/helpers_test.go | 52 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 notes/bf-4lid.md diff --git a/notes/bf-4lid.md b/notes/bf-4lid.md new file mode 100644 index 0000000..e51860c --- /dev/null +++ b/notes/bf-4lid.md @@ -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) diff --git a/proxy/helpers_test.go b/proxy/helpers_test.go index 052e565..d6601fe 100644 --- a/proxy/helpers_test.go +++ b/proxy/helpers_test.go @@ -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