This repository was archived by the owner on Oct 11, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +8
-12
lines changed Expand file tree Collapse file tree 1 file changed +8
-12
lines changed Original file line number Diff line number Diff line change 66package rpc
77
88import (
9- "context"
109"net/http"
11- "runtime"
1210"strconv"
1311"testing"
1412)
@@ -193,28 +191,26 @@ func TestServeHTTP(t *testing.T) {
193191}
194192
195193func 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-
201194const (
202195A = 2
203196B = 3
204197)
205198expected := A * B
206199
200+ r2 , err := http .NewRequest ("POST" , "mocked/request" , nil )
201+ if err != nil {
202+ t .Fatal (err )
203+ }
204+
207205s := NewServer ()
208206s .RegisterService (new (Service1 ), "" )
209207s .RegisterCodec (MockCodec {A , B }, "mock" )
210208s .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})
214211s .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
You can’t perform that action at this time.
0 commit comments