From 5d3b13f2e2215f7d53c88b20fd2c37f0a37b5ffd Mon Sep 17 00:00:00 2001 From: Oscar Yuen Date: Fri, 29 Dec 2017 21:23:21 +0800 Subject: [PATCH] Support context injection in testing --- gqltesting/testing.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gqltesting/testing.go b/gqltesting/testing.go index 71882cbfe24..56f90e4cd3e 100644 --- a/gqltesting/testing.go +++ b/gqltesting/testing.go @@ -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 @@ -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]) }