(t *testing.T)
| 359 | } |
| 360 | |
| 361 | func TestExtractSecretsFromEnv(t *testing.T) { |
| 362 | // Test the underlying secret extraction logic |
| 363 | tests := []struct { |
| 364 | name string |
| 365 | envMap map[string]string |
| 366 | expectedCount int |
| 367 | expectedSecret string |
| 368 | }{ |
| 369 | { |
| 370 | name: "single secret", |
| 371 | envMap: map[string]string{ |
| 372 | "API_KEY": "${{ secrets.API_KEY }}", |
| 373 | }, |
| 374 | expectedCount: 1, |
| 375 | expectedSecret: "${{ secrets.API_KEY }}", |
| 376 | }, |
| 377 | { |
| 378 | name: "multiple secrets", |
| 379 | envMap: map[string]string{ |
| 380 | "API_KEY": "${{ secrets.API_KEY }}", |
| 381 | "DB_PASS": "${{ secrets.DB_PASSWORD }}", |
| 382 | }, |
| 383 | expectedCount: 2, |
| 384 | }, |
| 385 | { |
| 386 | name: "secret with fallback", |
| 387 | envMap: map[string]string{ |
| 388 | "API_KEY": "${{ secrets.API_KEY || 'default' }}", |
| 389 | }, |
| 390 | expectedCount: 1, |
| 391 | }, |
| 392 | { |
| 393 | name: "embedded secret", |
| 394 | envMap: map[string]string{ |
| 395 | "AUTH_HEADER": "Bearer ${{ secrets.TOKEN }}", |
| 396 | }, |
| 397 | expectedCount: 1, |
| 398 | expectedSecret: "${{ secrets.TOKEN }}", |
| 399 | }, |
| 400 | { |
| 401 | name: "no secrets", |
| 402 | envMap: map[string]string{ |
| 403 | "NODE_ENV": "production", |
| 404 | "API_URL": "https://api.example.com", |
| 405 | }, |
| 406 | expectedCount: 0, |
| 407 | }, |
| 408 | } |
| 409 | |
| 410 | for _, tt := range tests { |
| 411 | t.Run(tt.name, func(t *testing.T) { |
| 412 | secrets := ExtractSecretsFromMap(tt.envMap) |
| 413 | assert.Len(t, secrets, tt.expectedCount, "Secret count mismatch") |
| 414 | |
| 415 | if tt.expectedSecret != "" { |
| 416 | found := false |
| 417 | for _, secret := range secrets { |
| 418 | if secret == tt.expectedSecret { |
nothing calls this directly
no test coverage detected