Repository navigation
Expand file tree
/
Copy patherrors_test.go
More file actions
57 lines (53 loc) · 1.66 KB
/
Copy patherrors_test.go
File metadata and controls
57 lines (53 loc) · 1.66 KB
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
55
56
57
package graphqlsse
import (
"errors"
"net/http"
"net/http/httptest"
"reflect"
"testing"
)
func TestWriteHTTPError(t *testing.T) {
rec := httptest.NewRecorder()
writeHTTPError(rec, http.StatusBadRequest, errors.New("bad"))
if rec.Code != http.StatusBadRequest {
t.Fatalf("status = %d, want %d", rec.Code, http.StatusBadRequest)
}
if got, want := rec.Body.String(), "bad\n"; got != want {
t.Fatalf("body = %q, want %q", got, want)
}
}
func TestWriteStreamError(t *testing.T) {
rec := httptest.NewRecorder()
w, err := newFrameWriter(rec, 0)
if err != nil {
t.Fatal(err)
}
if err := writeStreamError(w, errors.New("boom")); err != nil {
t.Fatal(err)
}
want := "event: next\ndata: {\"errors\":[{\"message\":\"boom\"}]}\n\n"
if got := rec.Body.String(); got != want {
t.Fatalf("body = %q, want %q", got, want)
}
}
func TestSplitHeader(t *testing.T) {
tests := []struct {
name string
in string
want []string
}{
{name: "single", in: "text/event-stream", want: []string{"text/event-stream"}},
{name: "quality", in: "text/event-stream;q=0.9", want: []string{"text/event-stream"}},
{name: "spaces", in: "text/event-stream, application/json", want: []string{"text/event-stream", "application/json"}},
{name: "tabs", in: "\ttext/event-stream\t,\tapplication/json\t", want: []string{"text/event-stream", "application/json"}},
{name: "empty", in: "", want: []string{""}},
{name: "space before semicolon", in: "0 ;0", want: []string{"0"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := splitHeader(tt.in); !reflect.DeepEqual(got, tt.want) {
t.Fatalf("splitHeader(%q) = %v, want %v", tt.in, got, tt.want)
}
})
}
}