...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package v2error
16
17 import (
18 "net/http"
19 "net/http/httptest"
20 "reflect"
21 "strings"
22 "testing"
23 )
24
25 func TestErrorWriteTo(t *testing.T) {
26 for k := range errors {
27 err := NewError(k, "", 1)
28 rr := httptest.NewRecorder()
29 err.WriteTo(rr)
30
31 if err.StatusCode() != rr.Code {
32 t.Errorf("HTTP status code %d, want %d", rr.Code, err.StatusCode())
33 }
34
35 gbody := strings.TrimSuffix(rr.Body.String(), "\n")
36 if err.toJsonString() != gbody {
37 t.Errorf("HTTP body %q, want %q", gbody, err.toJsonString())
38 }
39
40 wheader := http.Header(map[string][]string{
41 "Content-Type": {"application/json"},
42 "X-Etcd-Index": {"1"},
43 })
44
45 if !reflect.DeepEqual(wheader, rr.HeaderMap) {
46 t.Errorf("HTTP headers %v, want %v", rr.HeaderMap, wheader)
47 }
48 }
49
50 }
51
View as plain text