(t *testing.T)
| 304 | } |
| 305 | |
| 306 | func TestGetEngineSecretNameAndValue(t *testing.T) { |
| 307 | // Save current env and restore after test |
| 308 | oldCopilotToken := os.Getenv("COPILOT_GITHUB_TOKEN") |
| 309 | oldAnthropicKey := os.Getenv("ANTHROPIC_API_KEY") |
| 310 | oldOpenAIKey := os.Getenv("OPENAI_API_KEY") |
| 311 | oldCodexKey := os.Getenv("CODEX_API_KEY") |
| 312 | defer func() { |
| 313 | if oldCopilotToken != "" { |
| 314 | os.Setenv("COPILOT_GITHUB_TOKEN", oldCopilotToken) |
| 315 | } else { |
| 316 | os.Unsetenv("COPILOT_GITHUB_TOKEN") |
| 317 | } |
| 318 | if oldAnthropicKey != "" { |
| 319 | os.Setenv("ANTHROPIC_API_KEY", oldAnthropicKey) |
| 320 | } else { |
| 321 | os.Unsetenv("ANTHROPIC_API_KEY") |
| 322 | } |
| 323 | if oldOpenAIKey != "" { |
| 324 | os.Setenv("OPENAI_API_KEY", oldOpenAIKey) |
| 325 | } else { |
| 326 | os.Unsetenv("OPENAI_API_KEY") |
| 327 | } |
| 328 | if oldCodexKey != "" { |
| 329 | os.Setenv("CODEX_API_KEY", oldCodexKey) |
| 330 | } else { |
| 331 | os.Unsetenv("CODEX_API_KEY") |
| 332 | } |
| 333 | }() |
| 334 | |
| 335 | t.Run("secret exists in repository", func(t *testing.T) { |
| 336 | existingSecrets := map[string]struct { |
| 337 | }{ |
| 338 | "COPILOT_GITHUB_TOKEN": {}, |
| 339 | } |
| 340 | |
| 341 | name, value, existsInRepo, err := GetEngineSecretNameAndValue("copilot", existingSecrets) |
| 342 | |
| 343 | require.NoError(t, err, "Should not error when secret exists in repo") |
| 344 | assert.Equal(t, "COPILOT_GITHUB_TOKEN", name) |
| 345 | assert.Empty(t, value, "Value should be empty when secret exists in repo") |
| 346 | assert.True(t, existsInRepo, "Should indicate secret exists in repo") |
| 347 | }) |
| 348 | |
| 349 | t.Run("secret found in environment", func(t *testing.T) { |
| 350 | os.Setenv("ANTHROPIC_API_KEY", "test-api-key-12345") |
| 351 | defer os.Unsetenv("ANTHROPIC_API_KEY") |
| 352 | |
| 353 | existingSecrets := map[string]struct { |
| 354 | }{} |
| 355 | |
| 356 | name, value, existsInRepo, err := GetEngineSecretNameAndValue("claude", existingSecrets) |
| 357 | |
| 358 | require.NoError(t, err, "Should not error when secret in environment") |
| 359 | assert.Equal(t, "ANTHROPIC_API_KEY", name) |
| 360 | assert.Equal(t, "test-api-key-12345", value) |
| 361 | assert.False(t, existsInRepo, "Should indicate secret does not exist in repo") |
| 362 | }) |
| 363 |
nothing calls this directly
no test coverage detected