Skip to content
This repository was archived by the owner on Oct 11, 2019. It is now read-only.

Commit 22c016f

Browse files
Alexander Gräfensteinelithrar
authored andcommitted
changed test scenario to not use context package
1 parent 6479fae commit 22c016f

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

server_test.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
package rpc
77

88
import (
9-
"context"
109
"net/http"
11-
"runtime"
1210
"strconv"
1311
"testing"
1412
)
@@ -193,28 +191,26 @@ func TestServeHTTP(t *testing.T) {
193191
}
194192

195193
func TestInterception(t *testing.T) {
196-
if runtime.Version() < "go1.7" {
197-
// this test case uses the context package which is not available in go < 1.7
198-
return
199-
}
200-
201194
const (
202195
A = 2
203196
B = 3
204197
)
205198
expected := A * B
206199

200+
r2, err := http.NewRequest("POST", "mocked/request", nil)
201+
if err != nil {
202+
t.Fatal(err)
203+
}
204+
207205
s := NewServer()
208206
s.RegisterService(new(Service1), "")
209207
s.RegisterCodec(MockCodec{A, B}, "mock")
210208
s.RegisterInterceptFunc(func(i *RequestInfo) *http.Request {
211-
ctx := context.WithValue(i.Request.Context(), "test", A)
212-
return i.Request.WithContext(ctx)
209+
return r2
213210
})
214211
s.RegisterAfterFunc(func(i *RequestInfo) {
215-
value := i.Request.Context().Value("test")
216-
if A != value {
217-
t.Errorf("Value from context was %d, should be %d.", value, A)
212+
if i.Request != r2 {
213+
t.Errorf("Request was %v, should be %v.", i.Request, r2)
218214
}
219215
})
220216

0 commit comments

Comments
 (0)