-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Arko Dasgupta <arko@tetrate.io>
- Loading branch information
Showing
3 changed files
with
145 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
apiVersion: gateway.networking.k8s.io/v1 | ||
kind: HTTPRoute | ||
metadata: | ||
name: direct-response | ||
namespace: gateway-conformance-infra | ||
spec: | ||
parentRefs: | ||
- name: same-namespace | ||
rules: | ||
- matches: | ||
- path: | ||
type: PathPrefix | ||
value: /inline | ||
filters: | ||
- type: ExtensionRef | ||
extensionRef: | ||
group: gateway.envoyproxy.io | ||
kind: HTTPRouteFilter | ||
name: direct-response-inline | ||
- matches: | ||
- path: | ||
type: PathPrefix | ||
value: /value-ref | ||
filters: | ||
- type: ExtensionRef | ||
extensionRef: | ||
group: gateway.envoyproxy.io | ||
kind: HTTPRouteFilter | ||
name: direct-response-value-ref | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: response-value-ref | ||
namespace: gateway-conformance-infra | ||
data: | ||
response.body: '{"error": "Internal Server Error"}' | ||
--- | ||
apiVersion: gateway.envoyproxy.io/v1alpha1 | ||
kind: HTTPRouteFilter | ||
metadata: | ||
name: direct-response-inline | ||
namespace: gateway-conformance-infra | ||
spec: | ||
directResponse: | ||
contentType: text/plain | ||
body: | ||
type: Inline | ||
inline: "Oops! Your request is not found." | ||
--- | ||
apiVersion: gateway.envoyproxy.io/v1alpha1 | ||
kind: HTTPRouteFilter | ||
metadata: | ||
name: direct-response-value-ref | ||
namespace: gateway-conformance-infra | ||
spec: | ||
directResponse: | ||
contentType: application/json | ||
body: | ||
type: ValueRef | ||
valueRef: | ||
group: "" | ||
kind: ConfigMap | ||
name: value-ref-response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright Envoy Gateway Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// The full text of the Apache license is available in the LICENSE file at | ||
// the root of the repo. | ||
|
||
//go:build e2e | ||
|
||
package tests | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"net/url" | ||
"testing" | ||
|
||
"k8s.io/apimachinery/pkg/types" | ||
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" | ||
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2" | ||
httputils "sigs.k8s.io/gateway-api/conformance/utils/http" | ||
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes" | ||
"sigs.k8s.io/gateway-api/conformance/utils/suite" | ||
|
||
"github.com/envoyproxy/gateway/internal/gatewayapi" | ||
"github.com/envoyproxy/gateway/internal/gatewayapi/resource" | ||
) | ||
|
||
func init() { | ||
ConformanceTests = append(ConformanceTests, DirectResponseTest) | ||
} | ||
|
||
var DirectResponseTest = suite.ConformanceTest{ | ||
ShortName: "DirectResponse", | ||
Description: "Direct", | ||
Manifests: []string{"testdata/direct-response.yaml"}, | ||
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { | ||
t.Run("direct response", func(t *testing.T) { | ||
ns := "gateway-conformance-infra" | ||
routeNN := types.NamespacedName{Name: "direct-response", Namespace: ns} | ||
gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns} | ||
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN) | ||
|
||
kubernetes.HTTPRouteMustHaveResolvedRefsConditionsTrue(t, suite.Client, suite.TimeoutConfig, routeNN, gwNN) | ||
verifyCustomResponse(t, gwAddr, "/status/404", "text/plain", "Oops! Your request is not found.") | ||
verifyCustomResponse(t, gwAddr, "/status/500", "application/json", `{"error": "Internal Server Error"}`) | ||
}) | ||
}, | ||
} | ||
|
||
func verifyCustomResponse(t *testing.T, gwAddr, path, expectedContentType, expectedBody string) { | ||
reqURL := url.URL{ | ||
Scheme: "http", | ||
Host: httputils.CalculateHost(t, gwAddr, "http"), | ||
Path: path, | ||
} | ||
|
||
rsp, err := http.Get(reqURL.String()) | ||
if err != nil { | ||
t.Fatalf("failed to get response: %v", err) | ||
} | ||
|
||
// Verify that the response body is overridden | ||
defer rsp.Body.Close() | ||
body, err := io.ReadAll(rsp.Body) | ||
if err != nil { | ||
t.Fatalf("failed to read response body: %v", err) | ||
} | ||
if string(body) != expectedBody { | ||
t.Errorf("expected response body to be %s but got %s", expectedBody, string(body)) | ||
} | ||
|
||
// Verify that the content type is overridden | ||
contentType := rsp.Header.Get("Content-Type") | ||
if contentType != expectedContentType { | ||
t.Errorf("expected content type to be %s but got %s", expectedContentType, contentType) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters