mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
HTTP trigger http-stream tests (#1241)
This commit is contained in:
2
images/fn-test-utils/Gopkg.lock
generated
2
images/fn-test-utils/Gopkg.lock
generated
@@ -8,7 +8,7 @@
|
||||
".",
|
||||
"utils"
|
||||
]
|
||||
revision = "d1fa834929bb1579d770eded860a3a54e1f3502b"
|
||||
revision = "bd03f2c17b4d9e43525829d194174b35b5c47b54"
|
||||
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
|
||||
@@ -65,6 +65,11 @@ type AppRequest struct {
|
||||
PostErrGarbage string `json:"postErrGarbage,omitempty"`
|
||||
// test empty body
|
||||
IsEmptyBody bool `json:"isEmptyBody,omitempty"`
|
||||
// test headers that come into function
|
||||
ExpectHeaders map[string][]string `json:"expectHeaders,omitempty"`
|
||||
// send some headers out explicitly
|
||||
ReturnHeaders map[string][]string `json:"returnHeaders,omitempty"`
|
||||
|
||||
// TODO: simulate slow read/slow write
|
||||
// TODO: simulate partial IO write/read
|
||||
// TODO: simulate high cpu usage (async and sync)
|
||||
@@ -119,11 +124,6 @@ func AppHandler(ctx context.Context, in io.Reader, out io.Writer) {
|
||||
}
|
||||
|
||||
func finalizeRequest(out io.Writer, req *AppRequest, resp *AppResponse) {
|
||||
// custom response code
|
||||
if req.ResponseCode != 0 {
|
||||
fdk.WriteStatus(out, req.ResponseCode)
|
||||
}
|
||||
|
||||
// custom content type
|
||||
if req.ResponseContentType != "" {
|
||||
fdk.SetHeader(out, "Content-Type", req.ResponseContentType)
|
||||
@@ -137,6 +137,19 @@ func finalizeRequest(out io.Writer, req *AppRequest, resp *AppResponse) {
|
||||
fdk.SetHeader(out, "Content-Type", req.JasonContentType)
|
||||
}
|
||||
|
||||
if req.ReturnHeaders != nil {
|
||||
for k, vs := range req.ReturnHeaders {
|
||||
for _, v := range vs {
|
||||
fdk.AddHeader(out, k, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// custom response code
|
||||
if req.ResponseCode != 0 {
|
||||
fdk.WriteStatus(out, req.ResponseCode)
|
||||
}
|
||||
|
||||
if !req.IsEmptyBody {
|
||||
json.NewEncoder(out).Encode(resp)
|
||||
}
|
||||
@@ -155,6 +168,7 @@ func processRequest(ctx context.Context, in io.Reader) (*AppRequest, *AppRespons
|
||||
log.Printf("Received format %v", format)
|
||||
log.Printf("Received request %#v", request)
|
||||
log.Printf("Received headers %v", fnctx.Header)
|
||||
log.Printf("Received http headers %v", fnctx.HTTPHeader)
|
||||
log.Printf("Received config %v", fnctx.Config)
|
||||
}
|
||||
|
||||
@@ -219,6 +233,23 @@ func processRequest(ctx context.Context, in io.Reader) (*AppRequest, *AppRespons
|
||||
log.Fatalln("Crash requested")
|
||||
}
|
||||
|
||||
if request.ExpectHeaders != nil {
|
||||
for name, header := range request.ExpectHeaders {
|
||||
if strings.HasPrefix(name, "Fn-Http-H-") {
|
||||
// if it's an http header, make sure our other bucket works.
|
||||
// idk this seems like a weird good idea, maybe we should only test/expose one or the other...
|
||||
if h2 := fnctx.HTTPHeader.Get(strings.TrimPrefix(name, "Fn-Http-H-")); header[0] != h2 {
|
||||
log.Fatalf("Expected http header `%s` to be `%s` but was `%s`.",
|
||||
name, header[0], h2)
|
||||
}
|
||||
}
|
||||
if h2 := fnctx.Header.Get(name); header[0] != h2 {
|
||||
log.Fatalf("Expected header `%s` to be `%s` but was `%s`",
|
||||
name, header[0], h2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resp := AppResponse{
|
||||
Data: data,
|
||||
Request: request,
|
||||
|
||||
Reference in New Issue
Block a user