Skip to content

Commit

Permalink
Extend tests to test overwrites of path attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Schneider committed Dec 9, 2020
1 parent 5987d80 commit 7bf957c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
5 changes: 2 additions & 3 deletions config/runtime/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func newInlineBackend(
if diags.HasErrors() {
return nil, diags
}
// TODO: affects path / endpoint inheritance below?

parentAttr, _ := inlineDef.Body().JustAttributes()
content := &hcl.BodyContent{
Attributes: parentAttr,
Expand Down Expand Up @@ -464,8 +464,7 @@ func newInlineBackend(
// to handle possible overrides like 'path' for endpoints. Only if the most recent definition
// has no own attribute defined, use the parents one.
if len(bodies) > 0 && reflect.TypeOf(inlineDef) == reflect.TypeOf(&config.Endpoint{}) {
// TODO: working code with prepending inlineDef attr Body above ?
inheritableAttributes := []string{"path"} //, "add_query_params", "remove_query_params", "set_query_params"}
inheritableAttributes := []string{"path"}
inheritAttributes := make(hcl.Attributes)

recentBody := bodies[len(bodies)-1]
Expand Down
21 changes: 16 additions & 5 deletions server/http_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,20 +542,21 @@ func TestHTTPServer_Gzip(t *testing.T) {
func TestHTTPServer_QueryParams(t *testing.T) {
client := newClient()

confPath := path.Join("testdata/integration/endpoint_eval/04_couper.hcl")
shutdown, _ := newCouper(confPath, test.New(t))
const confPath = "testdata/integration/endpoint_eval/"

type expectation struct {
Query url.Values
Path string
}

type testCase struct {
file string
query string
exp expectation
}

for _, tc := range []testCase{
{"a=b%20c&aeb_del=1&ae_del=1&CaseIns=1&caseIns=1&def_del=1", expectation{
{"04_couper.hcl", "a=b%20c&aeb_del=1&ae_del=1&CaseIns=1&caseIns=1&def_del=1", expectation{
Query: url.Values{
"a": []string{"b c"},
"ae_a_and_b": []string{"A&B", "A&B"},
Expand Down Expand Up @@ -583,8 +584,18 @@ func TestHTTPServer_QueryParams(t *testing.T) {
"foo": []string{""},
"xxx": []string{"ddd", "zzz", "aaa", "bbb", "eee", "ccc"},
},
Path: "/",
}},
{"05_couper.hcl", "", expectation{
Query: url.Values{
"ae": []string{"ae"},
"def": []string{"def"},
},
Path: "/yyy",
}},
} {
shutdown, _ := newCouper(path.Join(confPath, tc.file), test.New(t))

t.Run("_"+tc.query, func(subT *testing.T) {
helper := test.New(subT)

Expand Down Expand Up @@ -613,9 +624,9 @@ func TestHTTPServer_QueryParams(t *testing.T) {
t.Errorf("\nwant: \n%#v\ngot: \n%#v\npayload:\n%s", tc.exp, jsonResult, string(resBytes))
}
})
}

cleanup(shutdown, t)
cleanup(shutdown, t)
}
}

func TestHTTPServer_Endpoint_Evaluation(t *testing.T) {
Expand Down
24 changes: 24 additions & 0 deletions server/testdata/integration/endpoint_eval/05_couper.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
server "api" {
api {
endpoint "/" {
path = "/yyy"
backend = "anything"

set_query_params = {
ae = "ae"
}
}
}
}

definitions {
# backend origin within a definition block gets replaced with the integration test "anything" server.
backend "anything" {
path = "/xxx"
origin = "http://anyserver/"

set_query_params = {
def = "def"
}
}
}

0 comments on commit 7bf957c

Please sign in to comment.