forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors_test.go
51 lines (38 loc) · 1.06 KB
/
errors_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
package http_test
import (
"context"
"fmt"
"net/http/httptest"
"testing"
"github.com/influxdata/influxdb"
"github.com/influxdata/influxdb/http"
)
func TestEncodeError(t *testing.T) {
ctx := context.TODO()
w := httptest.NewRecorder()
http.ErrorHandler(0).HandleHTTPError(ctx, nil, w)
if w.Code != 200 {
t.Errorf("expected status code 200, got: %d", w.Code)
}
}
func TestEncodeErrorWithError(t *testing.T) {
ctx := context.TODO()
err := fmt.Errorf("there's an error here, be aware")
w := httptest.NewRecorder()
http.ErrorHandler(0).HandleHTTPError(ctx, err, w)
if w.Code != 500 {
t.Errorf("expected status code 500, got: %d", w.Code)
}
errHeader := w.Header().Get("X-Platform-Error-Code")
if errHeader != influxdb.EInternal {
t.Errorf("expected X-Platform-Error-Code: %s, got: %s", influxdb.EInternal, errHeader)
}
expected := &influxdb.Error{
Code: influxdb.EInternal,
Err: err,
}
pe := http.CheckError(w.Result())
if pe.(*influxdb.Error).Err.Error() != expected.Err.Error() {
t.Errorf("errors encode err: got %s", w.Body.String())
}
}