diff options
author | Wolfy-J <[email protected]> | 2018-06-11 22:21:39 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-06-11 22:21:39 +0300 |
commit | 1633a8ae539d423a88ec983b0bc531238d982a98 (patch) | |
tree | fe5bd8637d221e5209df7de081118709b1bfad6e | |
parent | ec9cc7d1b90148c757ffab76e43d88798c20e5e0 (diff) |
coverage
-rw-r--r-- | php-src/tests/http/header.php | 6 | ||||
-rw-r--r-- | service/http/server_test.go | 25 |
2 files changed, 21 insertions, 10 deletions
diff --git a/php-src/tests/http/header.php b/php-src/tests/http/header.php index 9bb15ccd..e5b295b6 100644 --- a/php-src/tests/http/header.php +++ b/php-src/tests/http/header.php @@ -1,9 +1,11 @@ <?php -use \Psr\Http\Message\ServerRequestInterface; -use \Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; function handleRequest(ServerRequestInterface $req, ResponseInterface $resp): ResponseInterface { + $resp->getBody()->write(strtoupper($req->getHeaderLine('input'))); + return $resp->withAddedHeader("Header", $req->getQueryParams()['hello']); }
\ No newline at end of file diff --git a/service/http/server_test.go b/service/http/server_test.go index 07c5bbdc..33c6d44e 100644 --- a/service/http/server_test.go +++ b/service/http/server_test.go @@ -7,8 +7,7 @@ import ( "github.com/stretchr/testify/assert" "net/http" "context" - "bytes" - "io" + "io/ioutil" ) // get request and return body @@ -19,10 +18,8 @@ func get(url string) (string, *http.Response, error) { } defer r.Body.Close() - buf := new(bytes.Buffer) - io.Copy(buf, r.Body) - - return buf.String(), r, nil + b, err := ioutil.ReadAll(r.Body) + return string(b), r, err } func TestServer_Echo(t *testing.T) { @@ -59,7 +56,7 @@ func TestServer_Echo(t *testing.T) { assert.Equal(t, "WORLD", body) } -func TestServer_EchoHeaders(t *testing.T) { +func TestServer_Headers(t *testing.T) { st := &Server{ cfg: &Config{ MaxRequest: 1024, @@ -87,8 +84,20 @@ func TestServer_EchoHeaders(t *testing.T) { go func() { hs.ListenAndServe() }() - _, r, err := get("http://localhost:8077/?hello=world") + req, err := http.NewRequest("GET", "http://localhost:8077?hello=world", nil) + assert.NoError(t, err) + + req.Header.Add("input", "sample") + + r, err := http.DefaultClient.Do(req) + assert.NoError(t, err) + defer r.Body.Close() + + b, err := ioutil.ReadAll(r.Body) + assert.NoError(t, err) + assert.NoError(t, err) assert.Equal(t, 200, r.StatusCode) assert.Equal(t, "world", r.Header.Get("Header")) + assert.Equal(t, "SAMPLE", string(b)) } |