|
6 | 6 | package gatewayapi
|
7 | 7 |
|
8 | 8 | import (
|
| 9 | + "fmt" |
9 | 10 | "regexp"
|
10 | 11 | "testing"
|
11 | 12 |
|
12 | 13 | "github.com/stretchr/testify/assert"
|
13 | 14 | "github.com/stretchr/testify/require"
|
14 | 15 |
|
15 | 16 | egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
|
| 17 | + "github.com/envoyproxy/gateway/internal/ir" |
16 | 18 | )
|
17 | 19 |
|
18 | 20 | func Test_wildcard2regex(t *testing.T) {
|
@@ -490,3 +492,34 @@ func Test_APIKeyAuth(t *testing.T) {
|
490 | 492 | })
|
491 | 493 | }
|
492 | 494 | }
|
| 495 | + |
| 496 | +// TestSetDirectResponseForFailingFeatures tests the setDirectResponseForFailingFeatures function |
| 497 | +func TestSetDirectResponseForFailingFeatures(t *testing.T) { |
| 498 | + // Create a test route |
| 499 | + route := &ir.HTTPRoute{} |
| 500 | + |
| 501 | + // Create test security features |
| 502 | + basicAuth := &ir.BasicAuth{} |
| 503 | + |
| 504 | + // Create a test error |
| 505 | + err := fmt.Errorf("BasicAuth error") |
| 506 | + |
| 507 | + // Call the function |
| 508 | + setDirectResponseForFailingFeatures(route, err, basicAuth, nil, nil, nil, nil, nil) |
| 509 | + |
| 510 | + // Verify that the route has a direct response with status code 500 |
| 511 | + assert.NotNil(t, route.DirectResponse, "Route should have a direct response") |
| 512 | + assert.Equal(t, uint32(500), *route.DirectResponse.StatusCode, "Route should have a 500 status code") |
| 513 | + |
| 514 | + // Create a new route |
| 515 | + route = &ir.HTTPRoute{} |
| 516 | + |
| 517 | + // Create a test error for a different feature |
| 518 | + err = fmt.Errorf("JWT error") |
| 519 | + |
| 520 | + // Call the function with a different feature |
| 521 | + setDirectResponseForFailingFeatures(route, err, basicAuth, nil, nil, nil, nil, nil) |
| 522 | + |
| 523 | + // Verify that the route does not have a direct response |
| 524 | + assert.Nil(t, route.DirectResponse, "Route should not have a direct response") |
| 525 | +} |
0 commit comments