forked from Shashankft9/function-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandle_test.go
More file actions
38 lines (33 loc) · 863 Bytes
/
handle_test.go
File metadata and controls
38 lines (33 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package function
import (
"context"
"net/http"
"net/http/httptest"
"testing"
)
// TestHandle ensures that Handle executes without error, returns 2000 and sets
// and sets a content-type.
func TestHandle(t *testing.T) {
var (
w = httptest.NewRecorder()
req = httptest.NewRequest("GET", "http://example.com/test", nil)
res *http.Response
err error
)
// Invoke the Handler via a standard Go http.Handler
func(w http.ResponseWriter, req *http.Request) {
Handle(context.Background(), w, req)
}(w, req)
res = w.Result()
defer res.Body.Close()
// Assert postconditions
if err != nil {
t.Fatalf("unepected error in Handle: %v", err)
}
if res.StatusCode != 200 {
t.Fatalf("unexpected response code: %v", res.StatusCode)
}
if res.Header.Get("Content-Type") == "" {
t.Fatal("Handler did not set a content type for the response")
}
}