-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcorrelation_integration_test.go
54 lines (42 loc) · 1.37 KB
/
correlation_integration_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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package correlation
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
"github.com/urfave/negroni"
)
func TestIntegration(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("/foo", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "bar")
})
correlationMiddleware := New(Options{})
n := negroni.New()
n.Use(negroni.HandlerFunc(correlationMiddleware.HandlerFuncWithNext))
n.UseHandler(mux)
res := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "http://example.com/foo", nil)
n.ServeHTTP(res, req)
expectEq(t, res.Code, http.StatusOK)
expectEq(t, res.Body.String(), "bar")
expectNeq(t, res.Header().Get(correlationIDHeader), "")
expectNeq(t, req.Header.Get(correlationIDHeader), "")
}
func TestIntegrationForRequestOnly(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("/foo", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "bar")
})
correlationMiddleware := New(Options{})
n := negroni.New()
n.Use(negroni.HandlerFunc(correlationMiddleware.HandlerFuncWithNextForRequestOnly))
n.UseHandler(mux)
res := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "http://example.com/foo", nil)
n.ServeHTTP(res, req)
expectEq(t, res.Code, http.StatusOK)
expectEq(t, res.Body.String(), "bar")
expectEq(t, res.Header().Get(correlationIDHeader), "")
expectNeq(t, req.Header.Get(correlationIDHeader), "")
}