Skip to content

Commit a673078

Browse files
committed
subscription_test: refactored tests
1 parent 6baca7e commit a673078

File tree

1 file changed

+45
-95
lines changed

1 file changed

+45
-95
lines changed

subscription_test.go

Lines changed: 45 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -9,53 +9,6 @@ import (
99
"github.com/graphql-go/graphql/testutil"
1010
)
1111

12-
func makeSubscribeToStringFunction(elements []string) func(p graphql.ResolveParams) (interface{}, error) {
13-
return func(p graphql.ResolveParams) (interface{}, error) {
14-
c := make(chan interface{})
15-
go func() {
16-
for _, r := range elements {
17-
select {
18-
case <-p.Context.Done():
19-
close(c)
20-
return
21-
case c <- r:
22-
}
23-
}
24-
close(c)
25-
}()
26-
return c, nil
27-
}
28-
}
29-
30-
func makeSubscribeToMapFunction(elements []map[string]interface{}) func(p graphql.ResolveParams) (interface{}, error) {
31-
return func(p graphql.ResolveParams) (interface{}, error) {
32-
c := make(chan interface{})
33-
go func() {
34-
for _, r := range elements {
35-
select {
36-
case <-p.Context.Done():
37-
close(c)
38-
return
39-
case c <- r:
40-
}
41-
}
42-
close(c)
43-
}()
44-
return c, nil
45-
}
46-
}
47-
48-
func makeSubscriptionSchema(t *testing.T, c graphql.ObjectConfig) graphql.Schema {
49-
schema, err := graphql.NewSchema(graphql.SchemaConfig{
50-
Query: dummyQuery,
51-
Subscription: graphql.NewObject(c),
52-
})
53-
if err != nil {
54-
t.Errorf("failed to create schema: %v", err)
55-
}
56-
return schema
57-
}
58-
5912
func TestSchemaSubscribe(t *testing.T) {
6013

6114
testutil.RunSubscribes(t, []*testutil.TestSubscription{
@@ -200,7 +153,6 @@ func TestSchemaSubscribe(t *testing.T) {
200153
},
201154
},
202155
},
203-
204156
{
205157
Name: "schema_without_subscribe_errors",
206158
Schema: makeSubscriptionSchema(t, graphql.ObjectConfig{
@@ -225,54 +177,52 @@ func TestSchemaSubscribe(t *testing.T) {
225177
})
226178
}
227179

228-
// func TestRootOperations_invalidSubscriptionSchema(t *testing.T) {
229-
// type args struct {
230-
// Schema string
231-
// }
232-
// type want struct {
233-
// Error string
234-
// }
235-
// testTable := map[string]struct {
236-
// Args args
237-
// Want want
238-
// }{
239-
// "Subscription as incorrect type": {
240-
// Args: args{
241-
// Schema: `
242-
// schema {
243-
// query: Query
244-
// subscription: String
245-
// }
246-
// type Query {
247-
// thing: String
248-
// }
249-
// `,
250-
// },
251-
// Want: want{Error: `root operation "subscription" must be an OBJECT`},
252-
// },
253-
// "Subscription declared by schema, but type not present": {
254-
// Args: args{
255-
// Schema: `
256-
// schema {
257-
// query: Query
258-
// subscription: Subscription
259-
// }
260-
// type Query {
261-
// hello: String!
262-
// }
263-
// `,
264-
// },
265-
// Want: want{Error: `graphql: type "Subscription" not found`},
266-
// },
267-
// }
180+
func makeSubscribeToStringFunction(elements []string) func(p graphql.ResolveParams) (interface{}, error) {
181+
return func(p graphql.ResolveParams) (interface{}, error) {
182+
c := make(chan interface{})
183+
go func() {
184+
for _, r := range elements {
185+
select {
186+
case <-p.Context.Done():
187+
close(c)
188+
return
189+
case c <- r:
190+
}
191+
}
192+
close(c)
193+
}()
194+
return c, nil
195+
}
196+
}
197+
198+
func makeSubscribeToMapFunction(elements []map[string]interface{}) func(p graphql.ResolveParams) (interface{}, error) {
199+
return func(p graphql.ResolveParams) (interface{}, error) {
200+
c := make(chan interface{})
201+
go func() {
202+
for _, r := range elements {
203+
select {
204+
case <-p.Context.Done():
205+
close(c)
206+
return
207+
case c <- r:
208+
}
209+
}
210+
close(c)
211+
}()
212+
return c, nil
213+
}
214+
}
268215

269-
// for name, tt := range testTable {
270-
// tt := tt
271-
// t.Run(name, func(t *testing.T) {
272-
// t.Log(tt.Args.Schema) // TODO do something
273-
// })
274-
// }
275-
// }
216+
func makeSubscriptionSchema(t *testing.T, c graphql.ObjectConfig) graphql.Schema {
217+
schema, err := graphql.NewSchema(graphql.SchemaConfig{
218+
Query: dummyQuery,
219+
Subscription: graphql.NewObject(c),
220+
})
221+
if err != nil {
222+
t.Errorf("failed to create schema: %v", err)
223+
}
224+
return schema
225+
}
276226

277227
var dummyQuery = graphql.NewObject(graphql.ObjectConfig{
278228
Name: "Query",

0 commit comments

Comments
 (0)