Addressing more comments

tests do assertion on request data and headers
 doc fixed
This commit is contained in:
Denis Makogon
2017-10-07 02:24:07 +03:00
parent 181ccf54b4
commit e8f317abd4
2 changed files with 21 additions and 3 deletions

View File

@@ -8,6 +8,7 @@ import (
"io/ioutil"
"io"
"encoding/json"
"reflect"
)
type RequestData struct {
@@ -33,7 +34,8 @@ func TestJSONProtocolDumpJSONRequestWithData(t *testing.T) {
Host: "localhost:8080",
}
var buf bytes.Buffer
json.NewEncoder(&buf).Encode(RequestData{A: "a"})
rDataBefore := RequestData{A: "a"}
json.NewEncoder(&buf).Encode(rDataBefore)
req.Body = ioutil.NopCloser(&buf)
r, w := io.Pipe()
@@ -56,6 +58,15 @@ func TestJSONProtocolDumpJSONRequestWithData(t *testing.T) {
if err != nil {
t.Error(err.Error())
}
rDataAfter := new(RequestData)
err = json.Unmarshal([]byte(incomingReq.Body), &rDataAfter)
if err != nil {
t.Error(err.Error())
}
if rDataBefore.A != rDataAfter.A {
t.Errorf("Request data assertion mismatch: expected: %s, got %s",
rDataBefore.A, rDataAfter.A)
}
}
func TestJSONProtocolDumpJSONRequestWithoutData(t *testing.T) {
@@ -99,4 +110,9 @@ func TestJSONProtocolDumpJSONRequestWithoutData(t *testing.T) {
if err != nil {
t.Error(err.Error())
}
if ok := reflect.DeepEqual(req.Header, incomingReq.Headers); !ok {
t.Errorf("Request headers assertion mismatch: expected: %s, got %s",
req.Header, incomingReq.Headers)
}
}

View File

@@ -88,7 +88,9 @@ Internally function receives data in following format:
```json
{
"body": "{\"some\": \"input\"}",
"body": {
"some": "data"
},
"headers": {
"yo": ["dawg"]
}
@@ -102,7 +104,7 @@ Function's output format should have following format:
"status_code": 200,
"body": "...",
"headeres": {
"A": "b"
"A": ["b"]
}
}
```