diff --git a/api/agent/protocol/json_test.go b/api/agent/protocol/json_test.go index f485ad94a..19391b429 100644 --- a/api/agent/protocol/json_test.go +++ b/api/agent/protocol/json_test.go @@ -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) + + } } diff --git a/docs/function-format.md b/docs/function-format.md index db4ede1b1..3f7d13ab0 100644 --- a/docs/function-format.md +++ b/docs/function-format.md @@ -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"] } } ```