diff options
| author | Shulhan <ms@kilabit.info> | 2024-02-21 01:29:25 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2024-02-21 01:34:56 +0700 |
| commit | 9ca138628023b926ddf07cbd2e93562b8e782cf6 (patch) | |
| tree | b2c4524d4ed5ebd7098ad69c2917ee49159e2d93 /http_server_test.go | |
| parent | 99999635f67931e1a6deb608f13b2dc2ecd9df73 (diff) | |
| download | gorankusu-9ca138628023b926ddf07cbd2e93562b8e782cf6.tar.xz | |
all: add global HTTP headers for Target
The Headers field on Target define the global headers that will be send
along with all HTTPTarget or WebSocketTarget.
The same header can also be defined on HTTPTarget that override the
value of Target.
Diffstat (limited to 'http_server_test.go')
| -rw-r--r-- | http_server_test.go | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/http_server_test.go b/http_server_test.go index 8b08c46..12e03c0 100644 --- a/http_server_test.go +++ b/http_server_test.go @@ -85,7 +85,6 @@ func TestGorankusuAPITargetRunHTTP_withRawBody_JSON(t *testing.T) { tag string exp string ) - for _, c = range listCase { var reqparams = httpRequestParams{ method: apiTargetRunHTTP.Method.String(), @@ -105,6 +104,62 @@ func TestGorankusuAPITargetRunHTTP_withRawBody_JSON(t *testing.T) { } } +func TestGorankusuAPITargetRunHTTP_withTargetHeaders(t *testing.T) { + type testCase struct { + tag string + } + + var ( + tdata *test.Data + err error + ) + tdata, err = test.LoadData(`testdata/apiTargetRunHTTP_withTargetHeaders_test.txt`) + if err != nil { + t.Fatal(err) + } + + var listCase = []testCase{{ + tag: `global`, + }, { + tag: `override`, + }} + + var ( + c testCase + runResp RunResponse + buf bytes.Buffer + tag string + exp string + ) + for _, c = range listCase { + var reqparams = httpRequestParams{ + method: apiTargetRunHTTP.Method.String(), + path: apiTargetRunHTTP.Path, + body: tdata.Input[c.tag+`:request_body`], + } + + _, runResp = dummyGorankusuServe(t, reqparams) + + tag = c.tag + `:RunResponse.DumpRequest` + exp = string(tdata.Output[tag]) + test.Assert(t, tag, exp, string(runResp.DumpRequest)) + + tag = c.tag + `:RunResponse.DumpResponse` + exp = string(tdata.Output[tag]) + test.Assert(t, tag, exp, string(runResp.DumpResponse)) + + tag = c.tag + `:RunResponse.ResponseBody` + exp = string(tdata.Output[tag]) + + buf.Reset() + err = json.Indent(&buf, runResp.ResponseBody, ``, ` `) + if err != nil { + t.Fatal(err) + } + test.Assert(t, tag, exp, buf.String()) + } +} + func dummyGorankusuServe(t *testing.T, reqparams httpRequestParams) (rawResp []byte, runResp RunResponse) { var body bytes.Buffer var recorder = httptest.NewRecorder() |
