66 "net/http"
77 "net/http/httptest"
88 "os"
9+ "reflect"
910 "testing"
11+ "time"
1012
1113 "golang.org/x/net/context"
1214
@@ -105,17 +107,8 @@ func TestContext(t *testing.T) {
105107 }
106108
107109 varParams = append (varParams , param1 )
108-
109- // //store
110- // storeMap := store{
111- // "User": "Alice",
112- // "Information": []string{"Alice", "Bob", "40.712784", "-74.005941"},
113- // }
114-
115110 c .params = varParams
116111 c .netContext = context .Background ()
117- // c.m = new(sync.RWMutex)
118- // c.store = storeMap
119112 c .request = r
120113
121114 //Request
@@ -130,16 +123,18 @@ func TestContext(t *testing.T) {
130123 Equal (t , "507f191e810c19729de860ea" , bsonValue )
131124
132125 //Store
133- c .Set ("publicKey" , "U|ydN3SX)B(hI8SV1R;(" )
126+ ctx := c .Context ()
127+ ctx = context .WithValue (ctx , "publicKey" , "U|ydN3SX)B(hI8SV1R;(" )
128+ c .WithContext (ctx )
134129
135130 value , exists := c .Get ("publicKey" )
136131
137132 //Get
138133 Equal (t , true , exists )
139134 Equal (t , "U|ydN3SX)B(hI8SV1R;(" , value )
140135
141- c .Set ("User" , "Alice" )
142- value , exists = c .Get ("User" )
136+ c .WithValue ("User" , "Alice" )
137+ value , exists = c .Value ("User" ).( string )
143138 Equal (t , true , exists )
144139 Equal (t , "Alice" , value )
145140
@@ -168,13 +163,33 @@ func TestContext(t *testing.T) {
168163 NotEqual (t , c .response , nil )
169164
170165 //Set
171- Equal (t , c .netContext . Value ("test" ), nil )
166+ Equal (t , c .Value ("test" ), nil )
172167
173168 // Index
174169 Equal (t , c .index , - 1 )
175170
176171 // Handlers
177172 Equal (t , c .handlers , nil )
173+
174+ cancelFunc := c .WithCancel ()
175+ Equal (t , reflect .TypeOf (cancelFunc ).String (), "context.CancelFunc" )
176+
177+ dt := time .Now ().Add (time .Minute )
178+ cancelFunc = c .WithDeadline (dt )
179+ Equal (t , reflect .TypeOf (cancelFunc ).String (), "context.CancelFunc" )
180+
181+ cancelFunc = c .WithTimeout (time .Minute )
182+ Equal (t , reflect .TypeOf (cancelFunc ).String (), "context.CancelFunc" )
183+
184+ deadline , ok := c .Deadline ()
185+ Equal (t , ok , true )
186+ Equal (t , deadline , dt )
187+
188+ dc := c .Done ()
189+ Equal (t , reflect .TypeOf (dc ).String (), "<-chan struct {}" )
190+
191+ err := c .Err ()
192+ Equal (t , err , nil )
178193}
179194
180195func TestQueryParams (t * testing.T ) {
0 commit comments