Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Schneider committed Mar 11, 2021
1 parent 8127639 commit 6aa787b
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
54 changes: 53 additions & 1 deletion server/http_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,6 @@ func TestHTTPServer_QueryParams(t *testing.T) {
Path: "/",
}},
} {
tc := tc
t.Run("_"+tc.query, func(subT *testing.T) {
helper := test.New(subT)

Expand Down Expand Up @@ -679,6 +678,59 @@ func TestHTTPServer_QueryParams(t *testing.T) {
}
}

func TestHTTPServer_PathPrefix(t *testing.T) {
client := newClient()

type expectation struct {
Path string
}

type testCase struct {
path string
exp expectation
}

for _, tc := range []testCase{
{"/", expectation{
Path: "/xxx/xxx/",
}},
{"/yyy", expectation{
Path: "/yyy",
}},
{"/zzz", expectation{
Path: "/zzz/zzz",
}},
} {
t.Run("_"+tc.path, func(subT *testing.T) {
helper := test.New(subT)

shutdown, _ := newCouper("testdata/integration/api/06_couper.hcl", helper)
defer shutdown()

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

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

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

_ = res.Body.Close()

var jsonResult expectation
err = json.Unmarshal(resBytes, &jsonResult)
if err != nil {
t.Errorf("unmarshal json: %v: got:\n%s", err, string(resBytes))
}

if !reflect.DeepEqual(jsonResult, tc.exp) {
t.Errorf("\nwant: \n%#v\ngot: \n%#v\npayload:\n%s", tc.exp, jsonResult, string(resBytes))
}
})
}
}

func TestHTTPServer_RequestHeaders(t *testing.T) {
client := newClient()

Expand Down
34 changes: 34 additions & 0 deletions server/testdata/integration/api/06_couper.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
server "multi-api" {
api {
endpoint "/" {
proxy {
backend {
origin = env.COUPER_TEST_BACKEND_ADDR
path_prefix = "/xxx/xxx/"
}
}
}
}

api {
endpoint "/yyy" {
proxy {
backend {
origin = env.COUPER_TEST_BACKEND_ADDR
path_prefix = "/"
}
}
}
}

api {
endpoint "/zzz" {
proxy {
backend {
origin = env.COUPER_TEST_BACKEND_ADDR
path_prefix = "/zzz"
}
}
}
}
}

0 comments on commit 6aa787b

Please sign in to comment.