mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Addressing more comments
tests do assertion on request data and headers doc fixed
This commit is contained in:
@@ -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)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user