forked from davemachado/public-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger_test.go
32 lines (28 loc) · 813 Bytes
/
logger_test.go
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
package main
import (
"net/http"
"net/http/httptest"
"reflect"
"testing"
)
var (
myHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("bar"))
})
myHandlerWithError = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, http.StatusText(http.StatusBadGateway), http.StatusBadGateway)
})
)
func expect(t *testing.T, a interface{}, b interface{}) {
if a != b {
t.Errorf("Expected [%v] (type %v) - Got [%v] (type %v)", b, reflect.TypeOf(b), a, reflect.TypeOf(a))
}
}
func TestNoConfig(t *testing.T) {
res := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/should/be/stdout/", nil)
req.RemoteAddr = "111.222.333.444"
myHandler.ServeHTTP(res, req)
expect(t, res.Code, http.StatusOK)
expect(t, res.Body.String(), "bar")
}