Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Schneider authored and Marcel Ludwig committed Jan 19, 2021
1 parent a78e717 commit 8b7432d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 65 deletions.
3 changes: 3 additions & 0 deletions internal/test/test_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ func createAnythingHandler(status int) func(rw http.ResponseWriter, req *http.Re
rw.Header().Set("Content-Length", strconv.Itoa(len(respContent)))
rw.Header().Set("Content-Type", "application/json")

rw.Header().Set("Remove-Me-1", "r1")
rw.Header().Set("Remove-Me-2", "r2")

rw.WriteHeader(status)
_, _ = rw.Write(respContent)
}
Expand Down
21 changes: 21 additions & 0 deletions server/http_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,27 @@ func TestHTTPServer_RequestHeaders(t *testing.T) {
res, err := client.Do(req)
helper.Must(err)

if r1 := res.Header.Get("Remove-Me-1"); r1 != "" {
t.Errorf("Unexpected header %s", r1)
}
if r2 := res.Header.Get("Remove-Me-2"); r2 != "" {
t.Errorf("Unexpected header %s", r2)
}

if s1 := res.Header.Get("Set-Me-1"); s1 != "s1" {
t.Errorf("Missing or invalid header Set-Me-1: %s", s1)
}
if s2 := res.Header.Get("Set-Me-2"); s2 != "s2" {
t.Errorf("Missing or invalid header Set-Me-2: %s", s2)
}

if a1 := res.Header.Get("Add-Me-1"); a1 != "a1" {
t.Errorf("Missing or invalid header Add-Me-1: %s", a1)
}
if a2 := res.Header.Get("Add-Me-2"); a2 != "a2" {
t.Errorf("Missing or invalid header Add-Me-2: %s", a2)
}

resBytes, err := ioutil.ReadAll(res.Body)
helper.Must(err)

Expand Down
80 changes: 15 additions & 65 deletions server/testdata/integration/endpoint_eval/12_couper.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -23,75 +23,17 @@ server "api" {
aeb_empty = ""
"${req.query.aeb[0]}" = "aeb"
}
}

remove_request_headers = [ "ae_del" ]
set_request_headers = {
ae_string = "str"
ae_multi = ["str1", "str2"]
ae_a_and_b = "A&B"
ae_noop = req.headers.noop
ae_null = null
ae_empty = ""
xxx = "zzz"
"${req.query.ae[0]}" = "ae"
}
add_request_headers = {
ae_string = "str"
ae_multi = ["str3", "str4"]
ae_a_and_b = "A&B"
ae_noop = req.headers.noop
ae_null = null
ae_empty = ""
xxx = "ccc"
"${req.query.ae[0]}" = "ae"
remove_response_headers = [ "Remove-Me-2" ]
set_response_headers = {
"Set-Me-2" = "s2"
}
add_response_headers = {
"Add-Me-2" = "a2"
}
}
}
}

# TODO: free-endpoints
# endpoint "/free/endpoint" {
# backend {
# origin = "https://w11w.de"
# hostname = "w11w.de"

# remove_request_headers = [ "feb_del" ]
# set_request_headers = {
# feb_string = "str"
# feb_multi = ["str1", "str2"]
# feb_a_and_b = "A&B"
# feb_noop = req.headers.noop
# feb_null = null
# feb_empty = ""
# }
# add_request_headers = {
# feb_string = "str"
# feb_multi = ["str3", "str4"]
# feb_a_and_b = "A&B"
# feb_noop = req.headers.noop
# feb_null = null
# feb_empty = ""
# }
# }

# remove_request_headers = [ "fe_del" ]
# set_request_headers = {
# fe_String = "str"
# fe_multi = ["str1", "str2"]
# fe_a_and_b = "A&B"
# fe_noop = req.headers.noop
# fe_null = null
# fe_empty = ""
# }
# add_request_headers = {
# fe_String = "str"
# fe_multi = ["str3", "str4"]
# fe_a_and_b = "A&B"
# fe_noop = req.headers.noop
# fe_null = null
# fe_empty = ""
# }
# }
}

definitions {
Expand Down Expand Up @@ -121,5 +63,13 @@ definitions {
xxx = "eee"
"${req.query.def[0]}" = "def"
}

remove_response_headers = [ "remove-me-1" ]
set_response_headers = {
"set-me-1" = "s1"
}
add_response_headers = {
"add-me-1" = "a1"
}
}
}

0 comments on commit 8b7432d

Please sign in to comment.