Skip to content

Commit

Permalink
Support context injection in testing
Browse files Browse the repository at this point in the history
  • Loading branch information
OscarYuen authored and neelance committed Dec 29, 2017
1 parent beff084 commit 5d3b13f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gqltesting/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

// Test is a GraphQL test case to be used with RunTest(s).
type Test struct {
Context context.Context
Schema *graphql.Schema
Query string
OperationName string
Expand All @@ -35,7 +36,10 @@ func RunTests(t *testing.T, tests []*Test) {

// RunTest runs a single GraphQL test case.
func RunTest(t *testing.T, test *Test) {
result := test.Schema.Exec(context.Background(), test.Query, test.OperationName, test.Variables)
if test.Context == nil {
test.Context = context.Background()
}
result := test.Schema.Exec(test.Context, test.Query, test.OperationName, test.Variables)
if len(result.Errors) != 0 {
t.Fatal(result.Errors[0])
}
Expand Down

0 comments on commit 5d3b13f

Please sign in to comment.