summaryrefslogtreecommitdiff
path: root/test/go
diff options
context:
space:
mode:
authortaozle <zhangliyang26@gmail.com>2017-07-23 15:21:44 +0200
committerJens Geyer <jensg@apache.org>2017-07-25 00:17:30 +0200
commit5c302e02c40be558a21f3a82b53e527f7bec2ff2 (patch)
tree9c09e89736305138383d79ceda91e28f8fc6d491 /test/go
parentc0d384a38c2b43ee47cef86b1cd054e3f84dc909 (diff)
downloadthrift-5c302e02c40be558a21f3a82b53e527f7bec2ff2.tar.gz
THRIFT-4260 Go context generation issue. Context is parameter in Interface not in implementation
Client: Go Patch: taozle <zhangliyang26@gmail.com> This closes #1312
Diffstat (limited to 'test/go')
-rw-r--r--test/go/Makefile.am7
-rw-r--r--test/go/src/bin/testclient/go17.go26
-rw-r--r--test/go/src/bin/testclient/main.go54
-rw-r--r--test/go/src/bin/testclient/pre_go17.go26
-rw-r--r--test/go/src/common/clientserver_test.go48
-rw-r--r--test/go/src/common/go17.go26
-rw-r--r--test/go/src/common/pre_go17.go26
7 files changed, 160 insertions, 53 deletions
diff --git a/test/go/Makefile.am b/test/go/Makefile.am
index 428535984..ce711f664 100644
--- a/test/go/Makefile.am
+++ b/test/go/Makefile.am
@@ -18,9 +18,12 @@
#
BUILT_SOURCES = gopath
+if GOVERSION_LT_17
+COMPILER_EXTRAFLAG=",legacy_context"
+endif
THRIFT = $(top_builddir)/compiler/cpp/thrift
-THRIFTCMD = $(THRIFT) -out src/gen --gen go:thrift_import=thrift,legacy_context
+THRIFTCMD = $(THRIFT) -out src/gen --gen go:thrift_import=thrift$(COMPILER_EXTRAFLAG)
THRIFTTEST = $(top_srcdir)/test/ThriftTest.thrift
precross: bin/testclient bin/testserver
@@ -52,7 +55,7 @@ clean-local:
check_PROGRAMS: bin/testclient bin/testserver bin/stress
-check: gopath
+check: gopath genmock
GOPATH=`pwd` $(GO) test -v common/...
genmock: gopath
diff --git a/test/go/src/bin/testclient/go17.go b/test/go/src/bin/testclient/go17.go
new file mode 100644
index 000000000..a6003a917
--- /dev/null
+++ b/test/go/src/bin/testclient/go17.go
@@ -0,0 +1,26 @@
+// +build go1.7
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package main
+
+import "context"
+
+var defaultCtx = context.Background()
diff --git a/test/go/src/bin/testclient/main.go b/test/go/src/bin/testclient/main.go
index 228120b04..b34c53927 100644
--- a/test/go/src/bin/testclient/main.go
+++ b/test/go/src/bin/testclient/main.go
@@ -63,11 +63,11 @@ var xcept = &thrifttest.Xception{ErrorCode: 1001, Message: "Xception"}
func callEverything(client *thrifttest.ThriftTestClient) {
var err error
- if err = client.TestVoid(); err != nil {
+ if err = client.TestVoid(defaultCtx); err != nil {
t.Fatalf("Unexpected error in TestVoid() call: ", err)
}
- thing, err := client.TestString("thing")
+ thing, err := client.TestString(defaultCtx, "thing")
if err != nil {
t.Fatalf("Unexpected error in TestString() call: ", err)
}
@@ -75,14 +75,14 @@ func callEverything(client *thrifttest.ThriftTestClient) {
t.Fatalf("Unexpected TestString() result, expected 'thing' got '%s' ", thing)
}
- bl, err := client.TestBool(true)
+ bl, err := client.TestBool(defaultCtx, true)
if err != nil {
t.Fatalf("Unexpected error in TestBool() call: ", err)
}
if !bl {
t.Fatalf("Unexpected TestBool() result expected true, got %f ", bl)
}
- bl, err = client.TestBool(false)
+ bl, err = client.TestBool(defaultCtx, false)
if err != nil {
t.Fatalf("Unexpected error in TestBool() call: ", err)
}
@@ -90,7 +90,7 @@ func callEverything(client *thrifttest.ThriftTestClient) {
t.Fatalf("Unexpected TestBool() result expected false, got %f ", bl)
}
- b, err := client.TestByte(42)
+ b, err := client.TestByte(defaultCtx, 42)
if err != nil {
t.Fatalf("Unexpected error in TestByte() call: ", err)
}
@@ -98,7 +98,7 @@ func callEverything(client *thrifttest.ThriftTestClient) {
t.Fatalf("Unexpected TestByte() result expected 42, got %d ", b)
}
- i32, err := client.TestI32(4242)
+ i32, err := client.TestI32(defaultCtx, 4242)
if err != nil {
t.Fatalf("Unexpected error in TestI32() call: ", err)
}
@@ -106,7 +106,7 @@ func callEverything(client *thrifttest.ThriftTestClient) {
t.Fatalf("Unexpected TestI32() result expected 4242, got %d ", i32)
}
- i64, err := client.TestI64(424242)
+ i64, err := client.TestI64(defaultCtx, 424242)
if err != nil {
t.Fatalf("Unexpected error in TestI64() call: ", err)
}
@@ -114,7 +114,7 @@ func callEverything(client *thrifttest.ThriftTestClient) {
t.Fatalf("Unexpected TestI64() result expected 424242, got %d ", i64)
}
- d, err := client.TestDouble(42.42)
+ d, err := client.TestDouble(defaultCtx, 42.42)
if err != nil {
t.Fatalf("Unexpected error in TestDouble() call: ", err)
}
@@ -126,19 +126,19 @@ func callEverything(client *thrifttest.ThriftTestClient) {
for i := 0; i < 256; i++ {
binout[i] = byte(i)
}
- bin, err := client.TestBinary(binout)
+ bin, err := client.TestBinary(defaultCtx, binout)
for i := 0; i < 256; i++ {
if (binout[i] != bin[i]) {
t.Fatalf("Unexpected TestBinary() result expected %d, got %d ", binout[i], bin[i])
}
}
-
+
xs := thrifttest.NewXtruct()
xs.StringThing = "thing"
xs.ByteThing = 42
xs.I32Thing = 4242
xs.I64Thing = 424242
- xsret, err := client.TestStruct(xs)
+ xsret, err := client.TestStruct(defaultCtx, xs)
if err != nil {
t.Fatalf("Unexpected error in TestStruct() call: ", err)
}
@@ -148,7 +148,7 @@ func callEverything(client *thrifttest.ThriftTestClient) {
x2 := thrifttest.NewXtruct2()
x2.StructThing = xs
- x2ret, err := client.TestNest(x2)
+ x2ret, err := client.TestNest(defaultCtx, x2)
if err != nil {
t.Fatalf("Unexpected error in TestNest() call: ", err)
}
@@ -157,7 +157,7 @@ func callEverything(client *thrifttest.ThriftTestClient) {
}
m := map[int32]int32{1: 2, 3: 4, 5: 42}
- mret, err := client.TestMap(m)
+ mret, err := client.TestMap(defaultCtx, m)
if err != nil {
t.Fatalf("Unexpected error in TestMap() call: ", err)
}
@@ -166,7 +166,7 @@ func callEverything(client *thrifttest.ThriftTestClient) {
}
sm := map[string]string{"a": "2", "b": "blah", "some": "thing"}
- smret, err := client.TestStringMap(sm)
+ smret, err := client.TestStringMap(defaultCtx, sm)
if err != nil {
t.Fatalf("Unexpected error in TestStringMap() call: ", err)
}
@@ -175,7 +175,7 @@ func callEverything(client *thrifttest.ThriftTestClient) {
}
s := []int32{1, 2, 42}
- sret, err := client.TestSet(s)
+ sret, err := client.TestSet(defaultCtx, s)
if err != nil {
t.Fatalf("Unexpected error in TestSet() call: ", err)
}
@@ -191,7 +191,7 @@ func callEverything(client *thrifttest.ThriftTestClient) {
}
l := []int32{1, 2, 42}
- lret, err := client.TestList(l)
+ lret, err := client.TestList(defaultCtx, l)
if err != nil {
t.Fatalf("Unexpected error in TestList() call: ", err)
}
@@ -199,7 +199,7 @@ func callEverything(client *thrifttest.ThriftTestClient) {
t.Fatalf("Unexpected TestList() result expected %#v, got %#v ", l, lret)
}
- eret, err := client.TestEnum(thrifttest.Numberz_TWO)
+ eret, err := client.TestEnum(defaultCtx, thrifttest.Numberz_TWO)
if err != nil {
t.Fatalf("Unexpected error in TestEnum() call: ", err)
}
@@ -207,7 +207,7 @@ func callEverything(client *thrifttest.ThriftTestClient) {
t.Fatalf("Unexpected TestEnum() result expected %#v, got %#v ", thrifttest.Numberz_TWO, eret)
}
- tret, err := client.TestTypedef(thrifttest.UserId(42))
+ tret, err := client.TestTypedef(defaultCtx, thrifttest.UserId(42))
if err != nil {
t.Fatalf("Unexpected error in TestTypedef() call: ", err)
}
@@ -215,7 +215,7 @@ func callEverything(client *thrifttest.ThriftTestClient) {
t.Fatalf("Unexpected TestTypedef() result expected %#v, got %#v ", thrifttest.UserId(42), tret)
}
- mapmap, err := client.TestMapMap(42)
+ mapmap, err := client.TestMapMap(defaultCtx, 42)
if err != nil {
t.Fatalf("Unexpected error in TestMapMap() call: ", err)
}
@@ -242,7 +242,7 @@ func callEverything(client *thrifttest.ThriftTestClient) {
truck1,
truck2,
}
- insanity, err := client.TestInsanity(crazy)
+ insanity, err := client.TestInsanity(defaultCtx, crazy)
if err != nil {
t.Fatalf("Unexpected error in TestInsanity() call: ", err)
}
@@ -261,7 +261,7 @@ func callEverything(client *thrifttest.ThriftTestClient) {
insanity[2][6])
}
- xxsret, err := client.TestMulti(42, 4242, 424242, map[int16]string{1: "blah", 2: "thing"}, thrifttest.Numberz_EIGHT, thrifttest.UserId(24))
+ xxsret, err := client.TestMulti(defaultCtx, 42, 4242, 424242, map[int16]string{1: "blah", 2: "thing"}, thrifttest.Numberz_EIGHT, thrifttest.UserId(24))
if err != nil {
t.Fatalf("Unexpected error in TestMulti() call: ", err)
}
@@ -269,7 +269,7 @@ func callEverything(client *thrifttest.ThriftTestClient) {
t.Fatalf("Unexpected TestMulti() result expected %#v, got %#v ", xxs, xxsret)
}
- err = client.TestException("Xception")
+ err = client.TestException(defaultCtx, "Xception")
if err == nil {
t.Fatalf("Expecting exception in TestException() call")
}
@@ -277,13 +277,13 @@ func callEverything(client *thrifttest.ThriftTestClient) {
t.Fatalf("Unexpected TestException() result expected %#v, got %#v ", xcept, err)
}
- err = client.TestException("TException")
+ err = client.TestException(defaultCtx, "TException")
_, ok := err.(thrift.TApplicationException)
if err == nil || !ok {
t.Fatalf("Unexpected TestException() result expected ApplicationError, got %#v ", err)
}
- ign, err := client.TestMultiException("Xception", "ignoreme")
+ ign, err := client.TestMultiException(defaultCtx, "Xception", "ignoreme")
if ign != nil || err == nil {
t.Fatalf("Expecting exception in TestMultiException() call")
}
@@ -291,7 +291,7 @@ func callEverything(client *thrifttest.ThriftTestClient) {
t.Fatalf("Unexpected TestMultiException() %#v ", err)
}
- ign, err = client.TestMultiException("Xception2", "ignoreme")
+ ign, err = client.TestMultiException(defaultCtx, "Xception2", "ignoreme")
if ign != nil || err == nil {
t.Fatalf("Expecting exception in TestMultiException() call")
}
@@ -301,13 +301,13 @@ func callEverything(client *thrifttest.ThriftTestClient) {
t.Fatalf("Unexpected TestMultiException() %#v ", err)
}
- err = client.TestOneway(2)
+ err = client.TestOneway(defaultCtx, 2)
if err != nil {
t.Fatalf("Unexpected error in TestOneway() call: ", err)
}
//Make sure the connection still alive
- if err = client.TestVoid(); err != nil {
+ if err = client.TestVoid(defaultCtx); err != nil {
t.Fatalf("Unexpected error in TestVoid() call: ", err)
}
}
diff --git a/test/go/src/bin/testclient/pre_go17.go b/test/go/src/bin/testclient/pre_go17.go
new file mode 100644
index 000000000..10a6fb8d9
--- /dev/null
+++ b/test/go/src/bin/testclient/pre_go17.go
@@ -0,0 +1,26 @@
+// +build !go1.7
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package main
+
+import "golang.org/x/net/context"
+
+var defaultCtx = context.Background()
diff --git a/test/go/src/common/clientserver_test.go b/test/go/src/common/clientserver_test.go
index acc3dbaf8..ecd021f3b 100644
--- a/test/go/src/common/clientserver_test.go
+++ b/test/go/src/common/clientserver_test.go
@@ -120,11 +120,11 @@ func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, h
handler.EXPECT().TestVoid(gomock.Any()),
)
var err error
- if err = client.TestVoid(); err != nil {
+ if err = client.TestVoid(defaultCtx); err != nil {
t.Errorf("Unexpected error in TestVoid() call: ", err)
}
- thing, err := client.TestString("thing")
+ thing, err := client.TestString(defaultCtx, "thing")
if err != nil {
t.Errorf("Unexpected error in TestString() call: ", err)
}
@@ -132,14 +132,14 @@ func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, h
t.Errorf("Unexpected TestString() result, expected 'thing' got '%s' ", thing)
}
- bl, err := client.TestBool(true)
+ bl, err := client.TestBool(defaultCtx, true)
if err != nil {
t.Errorf("Unexpected error in TestBool() call: ", err)
}
if !bl {
t.Errorf("Unexpected TestBool() result expected true, got %f ", bl)
}
- bl, err = client.TestBool(false)
+ bl, err = client.TestBool(defaultCtx, false)
if err != nil {
t.Errorf("Unexpected error in TestBool() call: ", err)
}
@@ -147,7 +147,7 @@ func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, h
t.Errorf("Unexpected TestBool() result expected false, got %f ", bl)
}
- b, err := client.TestByte(42)
+ b, err := client.TestByte(defaultCtx, 42)
if err != nil {
t.Errorf("Unexpected error in TestByte() call: ", err)
}
@@ -155,7 +155,7 @@ func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, h
t.Errorf("Unexpected TestByte() result expected 42, got %d ", b)
}
- i32, err := client.TestI32(4242)
+ i32, err := client.TestI32(defaultCtx, 4242)
if err != nil {
t.Errorf("Unexpected error in TestI32() call: ", err)
}
@@ -163,7 +163,7 @@ func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, h
t.Errorf("Unexpected TestI32() result expected 4242, got %d ", i32)
}
- i64, err := client.TestI64(424242)
+ i64, err := client.TestI64(defaultCtx, 424242)
if err != nil {
t.Errorf("Unexpected error in TestI64() call: ", err)
}
@@ -171,7 +171,7 @@ func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, h
t.Errorf("Unexpected TestI64() result expected 424242, got %d ", i64)
}
- d, err := client.TestDouble(42.42)
+ d, err := client.TestDouble(defaultCtx, 42.42)
if err != nil {
t.Errorf("Unexpected error in TestDouble() call: ", err)
}
@@ -186,7 +186,7 @@ func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, h
xs.ByteThing = 42
xs.I32Thing = 4242
xs.I64Thing = 424242
- xsret, err := client.TestStruct(xs)
+ xsret, err := client.TestStruct(defaultCtx, xs)
if err != nil {
t.Errorf("Unexpected error in TestStruct() call: ", err)
}
@@ -196,7 +196,7 @@ func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, h
x2 := thrifttest.NewXtruct2()
x2.StructThing = xs
- x2ret, err := client.TestNest(x2)
+ x2ret, err := client.TestNest(defaultCtx, x2)
if err != nil {
t.Errorf("Unexpected error in TestNest() call: ", err)
}
@@ -205,7 +205,7 @@ func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, h
}
m := map[int32]int32{1: 2, 3: 4, 5: 42}
- mret, err := client.TestMap(m)
+ mret, err := client.TestMap(defaultCtx, m)
if err != nil {
t.Errorf("Unexpected error in TestMap() call: ", err)
}
@@ -214,7 +214,7 @@ func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, h
}
sm := map[string]string{"a": "2", "b": "blah", "some": "thing"}
- smret, err := client.TestStringMap(sm)
+ smret, err := client.TestStringMap(defaultCtx, sm)
if err != nil {
t.Errorf("Unexpected error in TestStringMap() call: ", err)
}
@@ -223,7 +223,7 @@ func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, h
}
s := []int32{1, 2, 42}
- sret, err := client.TestSet(s)
+ sret, err := client.TestSet(defaultCtx, s)
if err != nil {
t.Errorf("Unexpected error in TestSet() call: ", err)
}
@@ -239,7 +239,7 @@ func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, h
}
l := []int32{1, 2, 42}
- lret, err := client.TestList(l)
+ lret, err := client.TestList(defaultCtx, l)
if err != nil {
t.Errorf("Unexpected error in TestList() call: ", err)
}
@@ -247,7 +247,7 @@ func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, h
t.Errorf("Unexpected TestList() result expected %#v, got %#v ", l, lret)
}
- eret, err := client.TestEnum(thrifttest.Numberz_TWO)
+ eret, err := client.TestEnum(defaultCtx, thrifttest.Numberz_TWO)
if err != nil {
t.Errorf("Unexpected error in TestEnum() call: ", err)
}
@@ -255,7 +255,7 @@ func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, h
t.Errorf("Unexpected TestEnum() result expected %#v, got %#v ", thrifttest.Numberz_TWO, eret)
}
- tret, err := client.TestTypedef(thrifttest.UserId(42))
+ tret, err := client.TestTypedef(defaultCtx, thrifttest.UserId(42))
if err != nil {
t.Errorf("Unexpected error in TestTypedef() call: ", err)
}
@@ -263,7 +263,7 @@ func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, h
t.Errorf("Unexpected TestTypedef() result expected %#v, got %#v ", thrifttest.UserId(42), tret)
}
- mapmap, err := client.TestMapMap(42)
+ mapmap, err := client.TestMapMap(defaultCtx, 42)
if err != nil {
t.Errorf("Unexpected error in TestMapmap() call: ", err)
}
@@ -271,7 +271,7 @@ func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, h
t.Errorf("Unexpected TestMapmap() result expected %#v, got %#v ", rmapmap, mapmap)
}
- xxsret, err := client.TestMulti(42, 4242, 424242, map[int16]string{1: "blah", 2: "thing"}, thrifttest.Numberz_EIGHT, thrifttest.UserId(24))
+ xxsret, err := client.TestMulti(defaultCtx, 42, 4242, 424242, map[int16]string{1: "blah", 2: "thing"}, thrifttest.Numberz_EIGHT, thrifttest.UserId(24))
if err != nil {
t.Errorf("Unexpected error in TestMulti() call: ", err)
}
@@ -279,7 +279,7 @@ func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, h
t.Errorf("Unexpected TestMulti() result expected %#v, got %#v ", xxs, xxsret)
}
- err = client.TestException("some")
+ err = client.TestException(defaultCtx, "some")
if err == nil {
t.Errorf("Expecting exception in TestException() call")
}
@@ -288,13 +288,13 @@ func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, h
}
// TODO: connection is being closed on this
- err = client.TestException("TException")
+ err = client.TestException(defaultCtx, "TException")
tex, ok := err.(thrift.TApplicationException)
if err == nil || !ok || tex.TypeId() != thrift.INTERNAL_ERROR {
t.Errorf("Unexpected TestException() result expected ApplicationError, got %#v ", err)
}
- ign, err := client.TestMultiException("Xception", "ignoreme")
+ ign, err := client.TestMultiException(defaultCtx, "Xception", "ignoreme")
if ign != nil || err == nil {
t.Errorf("Expecting exception in TestMultiException() call")
}
@@ -302,7 +302,7 @@ func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, h
t.Errorf("Unexpected TestMultiException() %#v ", err)
}
- ign, err = client.TestMultiException("Xception2", "ignoreme")
+ ign, err = client.TestMultiException(defaultCtx, "Xception2", "ignoreme")
if ign != nil || err == nil {
t.Errorf("Expecting exception in TestMultiException() call")
}
@@ -312,13 +312,13 @@ func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, h
t.Errorf("Unexpected TestMultiException() %#v ", err)
}
- err = client.TestOneway(2)
+ err = client.TestOneway(defaultCtx, 2)
if err != nil {
t.Errorf("Unexpected error in TestOneway() call: ", err)
}
//Make sure the connection still alive
- if err = client.TestVoid(); err != nil {
+ if err = client.TestVoid(defaultCtx); err != nil {
t.Errorf("Unexpected error in TestVoid() call: ", err)
}
}
diff --git a/test/go/src/common/go17.go b/test/go/src/common/go17.go
new file mode 100644
index 000000000..9aca4075c
--- /dev/null
+++ b/test/go/src/common/go17.go
@@ -0,0 +1,26 @@
+// +build go1.7
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package common
+
+import "context"
+
+var defaultCtx = context.Background()
diff --git a/test/go/src/common/pre_go17.go b/test/go/src/common/pre_go17.go
new file mode 100644
index 000000000..6c14579d2
--- /dev/null
+++ b/test/go/src/common/pre_go17.go
@@ -0,0 +1,26 @@
+// +build !go1.7
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package common
+
+import "golang.org/x/net/context"
+
+var defaultCtx = context.Background()