Skip to content

Commit e0638a4

Browse files
committed
Add test to cover the Pretty = False codepath in the ServeHTTP function.
1 parent 36a88d7 commit e0638a4

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

handler_test.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ func TestContextPropagated(t *testing.T) {
8383
}
8484
}
8585

86-
func TestHandler_BasicQuery(t *testing.T) {
87-
86+
func TestHandler_BasicQuery_Pretty(t *testing.T) {
8887
expected := &graphql.Result{
8988
Data: map[string]interface{}{
9089
"rebels": map[string]interface{}{
@@ -108,6 +107,32 @@ func TestHandler_BasicQuery(t *testing.T) {
108107
t.Fatalf("wrong result, graphql result diff: %v", testutil.Diff(expected, result))
109108
}
110109
}
110+
111+
func TestHandler_BasicQuery_Ugly(t *testing.T) {
112+
expected := &graphql.Result{
113+
Data: map[string]interface{}{
114+
"rebels": map[string]interface{}{
115+
"id": "RmFjdGlvbjox",
116+
"name": "Alliance to Restore the Republic",
117+
},
118+
},
119+
}
120+
queryString := `query=query RebelsShipsQuery { rebels { id, name } }`
121+
req, _ := http.NewRequest("GET", fmt.Sprintf("/graphql?%v", queryString), nil)
122+
123+
h := handler.New(&handler.Config{
124+
Schema: &starwars.Schema,
125+
Pretty: false,
126+
})
127+
result, resp := executeTest(t, h, req)
128+
if resp.Code != http.StatusOK {
129+
t.Fatalf("unexpected server response %v", resp.Code)
130+
}
131+
if !reflect.DeepEqual(result, expected) {
132+
t.Fatalf("wrong result, graphql result diff: %v", testutil.Diff(expected, result))
133+
}
134+
}
135+
111136
func TestHandler_Params_NilParams(t *testing.T) {
112137
defer func() {
113138
if r := recover(); r != nil {

0 commit comments

Comments
 (0)