Skip to content

Commit

Permalink
Add test to check (openapi) block handling during backend refinement
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Ludwig committed Dec 15, 2020
1 parent 84cce77 commit 4329df5
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
18 changes: 18 additions & 0 deletions server/http_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,3 +764,21 @@ func TestHTTPServer_Endpoint_Evaluation_Inheritance(t *testing.T) {
cleanup(shutdown, t)
}
}

func TestHTTPServer_Endpoint_Evaluation_Inheritance_Backend_Block(t *testing.T) {
helper := test.New(t)
client := newClient()

shutdown, _ := newCouper("testdata/integration/endpoint_eval/08_couper.hcl", test.New(t))

req, err := http.NewRequest(http.MethodGet, "http://example.com:8080/", nil)
helper.Must(err)

res, err := client.Do(req)
helper.Must(err)

if res.StatusCode != http.StatusBadRequest {
t.Error("Expected a bad request without required query param")
}
cleanup(shutdown, t)
}
40 changes: 40 additions & 0 deletions server/testdata/integration/endpoint_eval/08_couper.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
server "protected" {
error_file = "./../server_error.html"

api {
error_file = "./../api_error.json"

backend "anything" { # overrides definitions: backend "anything"
path = "/set/by/api/unset/by/endpoint"
openapi {
file = "also-not-there.yml"
}
}

endpoint "/" {
path = "/set/by/endpoint/unset/by/backend"
backend "anything" {
path = "/anything"
origin = "http://${req.path_params.origin}"
hostname = req.path_params.hostname
set_response_headers = {
x-origin = req.path_params.origin
}
openapi {
file = "08_schema.yaml"
}
}
}
}
}

definitions {
# backend origin within a definition block gets replaced with the integration test "anything" server.
backend "anything" {
path = "/not-found-anything"
origin = "http://anyserver/"
openapi {
file = "not-there.yml"
}
}
}
16 changes: 16 additions & 0 deletions server/testdata/integration/endpoint_eval/08_schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
openapi: '3'
info:
title: 'Couper backend validation test'
version: 'v1.2.3'
paths:
/anything:
get:
parameters:
- in: query
name: myparam
schema:
type: string
required: true
responses:
200:
description: OK

0 comments on commit 4329df5

Please sign in to comment.