context_test.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. // Copyright 2014 Manu Martinez-Almeida. All rights reserved.
  2. // Use of this source code is governed by a MIT style
  3. // license that can be found in the LICENSE file.
  4. package gin
  5. import (
  6. "bytes"
  7. "errors"
  8. "html/template"
  9. "mime/multipart"
  10. "net/http"
  11. "net/http/httptest"
  12. "testing"
  13. "time"
  14. "github.com/manucorporat/sse"
  15. "github.com/stretchr/testify/assert"
  16. )
  17. // Unit tests TODO
  18. // func (c *Context) File(filepath string) {
  19. // func (c *Context) Negotiate(code int, config Negotiate) {
  20. // BAD case: func (c *Context) Render(code int, render render.Render, obj ...interface{}) {
  21. // test that information is not leaked when reusing Contexts (using the Pool)
  22. func createTestContext() (c *Context, w *httptest.ResponseRecorder, r *Engine) {
  23. w = httptest.NewRecorder()
  24. r = New()
  25. c = r.allocateContext()
  26. c.reset()
  27. c.writermem.reset(w)
  28. return
  29. }
  30. func createMultipartRequest() *http.Request {
  31. boundary := "--testboundary"
  32. body := new(bytes.Buffer)
  33. mw := multipart.NewWriter(body)
  34. defer mw.Close()
  35. must(mw.SetBoundary(boundary))
  36. must(mw.WriteField("foo", "bar"))
  37. must(mw.WriteField("bar", "foo"))
  38. req, err := http.NewRequest("POST", "/", body)
  39. must(err)
  40. req.Header.Set("Content-Type", MIMEMultipartPOSTForm+"; boundary="+boundary)
  41. return req
  42. }
  43. func must(err error) {
  44. if err != nil {
  45. panic(err.Error())
  46. }
  47. }
  48. func TestContextReset(t *testing.T) {
  49. router := New()
  50. c := router.allocateContext()
  51. assert.Equal(t, c.engine, router)
  52. c.index = 2
  53. c.Writer = &responseWriter{ResponseWriter: httptest.NewRecorder()}
  54. c.Params = Params{Param{}}
  55. c.Error(errors.New("test"))
  56. c.Set("foo", "bar")
  57. c.reset()
  58. assert.False(t, c.IsAborted())
  59. assert.Nil(t, c.Keys)
  60. assert.Nil(t, c.Accepted)
  61. assert.Len(t, c.Errors, 0)
  62. assert.Empty(t, c.Errors.Errors())
  63. assert.Empty(t, c.Errors.ByType(ErrorTypeAny))
  64. assert.Len(t, c.Params, 0)
  65. assert.EqualValues(t, c.index, -1)
  66. assert.Equal(t, c.Writer.(*responseWriter), &c.writermem)
  67. }
  68. // TestContextSetGet tests that a parameter is set correctly on the
  69. // current context and can be retrieved using Get.
  70. func TestContextSetGet(t *testing.T) {
  71. c, _, _ := createTestContext()
  72. c.Set("foo", "bar")
  73. value, err := c.Get("foo")
  74. assert.Equal(t, value, "bar")
  75. assert.True(t, err)
  76. value, err = c.Get("foo2")
  77. assert.Nil(t, value)
  78. assert.False(t, err)
  79. assert.Equal(t, c.MustGet("foo"), "bar")
  80. assert.Panics(t, func() { c.MustGet("no_exist") })
  81. }
  82. func TestContextSetGetValues(t *testing.T) {
  83. c, _, _ := createTestContext()
  84. c.Set("string", "this is a string")
  85. c.Set("int32", int32(-42))
  86. c.Set("int64", int64(42424242424242))
  87. c.Set("uint64", uint64(42))
  88. c.Set("float32", float32(4.2))
  89. c.Set("float64", 4.2)
  90. var a interface{} = 1
  91. c.Set("intInterface", a)
  92. assert.Exactly(t, c.MustGet("string").(string), "this is a string")
  93. assert.Exactly(t, c.MustGet("int32").(int32), int32(-42))
  94. assert.Exactly(t, c.MustGet("int64").(int64), int64(42424242424242))
  95. assert.Exactly(t, c.MustGet("uint64").(uint64), uint64(42))
  96. assert.Exactly(t, c.MustGet("float32").(float32), float32(4.2))
  97. assert.Exactly(t, c.MustGet("float64").(float64), 4.2)
  98. assert.Exactly(t, c.MustGet("intInterface").(int), 1)
  99. }
  100. func TestContextCopy(t *testing.T) {
  101. c, _, _ := createTestContext()
  102. c.index = 2
  103. c.Request, _ = http.NewRequest("POST", "/hola", nil)
  104. c.handlers = HandlersChain{func(c *Context) {}}
  105. c.Params = Params{Param{Key: "foo", Value: "bar"}}
  106. c.Set("foo", "bar")
  107. cp := c.Copy()
  108. assert.Nil(t, cp.handlers)
  109. assert.Nil(t, cp.writermem.ResponseWriter)
  110. assert.Equal(t, &cp.writermem, cp.Writer.(*responseWriter))
  111. assert.Equal(t, cp.Request, c.Request)
  112. assert.Equal(t, cp.index, AbortIndex)
  113. assert.Equal(t, cp.Keys, c.Keys)
  114. assert.Equal(t, cp.engine, c.engine)
  115. assert.Equal(t, cp.Params, c.Params)
  116. }
  117. func TestContextQuery(t *testing.T) {
  118. c, _, _ := createTestContext()
  119. c.Request, _ = http.NewRequest("GET", "http://example.com/?foo=bar&page=10", nil)
  120. assert.Equal(t, c.DefaultQuery("foo", "none"), "bar")
  121. assert.Equal(t, c.Query("foo"), "bar")
  122. assert.Empty(t, c.PostForm("foo"))
  123. assert.Equal(t, c.DefaultQuery("page", "0"), "10")
  124. assert.Equal(t, c.Query("page"), "10")
  125. assert.Empty(t, c.PostForm("page"))
  126. assert.Equal(t, c.DefaultQuery("NoKey", "nada"), "nada")
  127. assert.Empty(t, c.Query("NoKey"))
  128. assert.Empty(t, c.PostForm("NoKey"))
  129. }
  130. func TestContextQueryAndPostForm(t *testing.T) {
  131. c, _, _ := createTestContext()
  132. body := bytes.NewBufferString("foo=bar&page=11&both=POST")
  133. c.Request, _ = http.NewRequest("POST", "/?both=GET&id=main", body)
  134. c.Request.Header.Add("Content-Type", MIMEPOSTForm)
  135. assert.Equal(t, c.DefaultPostForm("foo", "none"), "bar")
  136. assert.Equal(t, c.PostForm("foo"), "bar")
  137. assert.Empty(t, c.Query("foo"))
  138. assert.Equal(t, c.DefaultPostForm("page", "0"), "11")
  139. assert.Equal(t, c.PostForm("page"), "11")
  140. assert.Equal(t, c.Query("page"), "")
  141. assert.Equal(t, c.PostForm("both"), "POST")
  142. assert.Equal(t, c.Query("both"), "GET")
  143. assert.Equal(t, c.DefaultPostForm("id", "000"), "000")
  144. assert.Equal(t, c.Query("id"), "main")
  145. assert.Empty(t, c.PostForm("id"))
  146. assert.Equal(t, c.DefaultPostForm("NoKey", "nada"), "nada")
  147. assert.Empty(t, c.PostForm("NoKey"))
  148. assert.Empty(t, c.Query("NoKey"))
  149. var obj struct {
  150. Foo string `form:"foo"`
  151. Id string `form:"id"`
  152. Page string `form:"page"`
  153. Both string `form:"both"`
  154. }
  155. assert.NoError(t, c.Bind(&obj))
  156. assert.Equal(t, obj.Foo, "bar")
  157. assert.Equal(t, obj.Id, "main")
  158. assert.Equal(t, obj.Page, "11")
  159. assert.Equal(t, obj.Both, "POST")
  160. }
  161. func TestContextPostFormMultipart(t *testing.T) {
  162. c, _, _ := createTestContext()
  163. c.Request = createMultipartRequest()
  164. var obj struct {
  165. Foo string `form:"foo"`
  166. Bar string `form:"bar"`
  167. }
  168. assert.NoError(t, c.Bind(&obj))
  169. assert.Equal(t, obj.Bar, "foo")
  170. assert.Equal(t, obj.Foo, "bar")
  171. assert.Empty(t, c.Query("foo"))
  172. assert.Empty(t, c.Query("bar"))
  173. assert.Equal(t, c.PostForm("foo"), "bar")
  174. assert.Equal(t, c.PostForm("bar"), "foo")
  175. }
  176. // Tests that the response is serialized as JSON
  177. // and Content-Type is set to application/json
  178. func TestContextRenderJSON(t *testing.T) {
  179. c, w, _ := createTestContext()
  180. c.JSON(201, H{"foo": "bar"})
  181. assert.Equal(t, w.Code, 201)
  182. assert.Equal(t, w.Body.String(), "{\"foo\":\"bar\"}\n")
  183. assert.Equal(t, w.HeaderMap.Get("Content-Type"), "application/json; charset=utf-8")
  184. }
  185. // Tests that the response is serialized as JSON
  186. // and Content-Type is set to application/json
  187. func TestContextRenderIndentedJSON(t *testing.T) {
  188. c, w, _ := createTestContext()
  189. c.IndentedJSON(201, H{"foo": "bar", "bar": "foo", "nested": H{"foo": "bar"}})
  190. assert.Equal(t, w.Code, 201)
  191. assert.Equal(t, w.Body.String(), "{\n \"bar\": \"foo\",\n \"foo\": \"bar\",\n \"nested\": {\n \"foo\": \"bar\"\n }\n}")
  192. assert.Equal(t, w.HeaderMap.Get("Content-Type"), "application/json; charset=utf-8")
  193. }
  194. // Tests that the response executes the templates
  195. // and responds with Content-Type set to text/html
  196. func TestContextRenderHTML(t *testing.T) {
  197. c, w, router := createTestContext()
  198. templ := template.Must(template.New("t").Parse(`Hello {{.name}}`))
  199. router.SetHTMLTemplate(templ)
  200. c.HTML(201, "t", H{"name": "alexandernyquist"})
  201. assert.Equal(t, w.Code, 201)
  202. assert.Equal(t, w.Body.String(), "Hello alexandernyquist")
  203. assert.Equal(t, w.HeaderMap.Get("Content-Type"), "text/html; charset=utf-8")
  204. }
  205. // TestContextXML tests that the response is serialized as XML
  206. // and Content-Type is set to application/xml
  207. func TestContextRenderXML(t *testing.T) {
  208. c, w, _ := createTestContext()
  209. c.XML(201, H{"foo": "bar"})
  210. assert.Equal(t, w.Code, 201)
  211. assert.Equal(t, w.Body.String(), "<map><foo>bar</foo></map>")
  212. assert.Equal(t, w.HeaderMap.Get("Content-Type"), "application/xml; charset=utf-8")
  213. }
  214. // TestContextString tests that the response is returned
  215. // with Content-Type set to text/plain
  216. func TestContextRenderString(t *testing.T) {
  217. c, w, _ := createTestContext()
  218. c.String(201, "test %s %d", "string", 2)
  219. assert.Equal(t, w.Code, 201)
  220. assert.Equal(t, w.Body.String(), "test string 2")
  221. assert.Equal(t, w.HeaderMap.Get("Content-Type"), "text/plain; charset=utf-8")
  222. }
  223. // TestContextString tests that the response is returned
  224. // with Content-Type set to text/html
  225. func TestContextRenderHTMLString(t *testing.T) {
  226. c, w, _ := createTestContext()
  227. c.Header("Content-Type", "text/html; charset=utf-8")
  228. c.String(201, "<html>%s %d</html>", "string", 3)
  229. assert.Equal(t, w.Code, 201)
  230. assert.Equal(t, w.Body.String(), "<html>string 3</html>")
  231. assert.Equal(t, w.HeaderMap.Get("Content-Type"), "text/html; charset=utf-8")
  232. }
  233. // TestContextData tests that the response can be written from `bytesting`
  234. // with specified MIME type
  235. func TestContextRenderData(t *testing.T) {
  236. c, w, _ := createTestContext()
  237. c.Data(201, "text/csv", []byte(`foo,bar`))
  238. assert.Equal(t, w.Code, 201)
  239. assert.Equal(t, w.Body.String(), "foo,bar")
  240. assert.Equal(t, w.HeaderMap.Get("Content-Type"), "text/csv")
  241. }
  242. func TestContextRenderSSE(t *testing.T) {
  243. c, w, _ := createTestContext()
  244. c.SSEvent("float", 1.5)
  245. c.Render(-1, sse.Event{
  246. Id: "123",
  247. Data: "text",
  248. })
  249. c.SSEvent("chat", H{
  250. "foo": "bar",
  251. "bar": "foo",
  252. })
  253. assert.Equal(t, w.Body.String(), "event: float\ndata: 1.5\n\nid: 123\ndata: text\n\nevent: chat\ndata: {\"bar\":\"foo\",\"foo\":\"bar\"}\n\n")
  254. }
  255. func TestContextRenderFile(t *testing.T) {
  256. c, w, _ := createTestContext()
  257. c.Request, _ = http.NewRequest("GET", "/", nil)
  258. c.File("./gin.go")
  259. assert.Equal(t, w.Code, 200)
  260. assert.Contains(t, w.Body.String(), "func New() *Engine {")
  261. assert.Equal(t, w.HeaderMap.Get("Content-Type"), "text/plain; charset=utf-8")
  262. }
  263. func TestContextHeaders(t *testing.T) {
  264. c, _, _ := createTestContext()
  265. c.Header("Content-Type", "text/plain")
  266. c.Header("X-Custom", "value")
  267. assert.Equal(t, c.Writer.Header().Get("Content-Type"), "text/plain")
  268. assert.Equal(t, c.Writer.Header().Get("X-Custom"), "value")
  269. c.Header("Content-Type", "text/html")
  270. c.Header("X-Custom", "")
  271. assert.Equal(t, c.Writer.Header().Get("Content-Type"), "text/html")
  272. _, exist := c.Writer.Header()["X-Custom"]
  273. assert.False(t, exist)
  274. }
  275. // TODO
  276. func TestContextRenderRedirectWithRelativePath(t *testing.T) {
  277. c, w, _ := createTestContext()
  278. c.Request, _ = http.NewRequest("POST", "http://example.com", nil)
  279. assert.Panics(t, func() { c.Redirect(299, "/new_path") })
  280. assert.Panics(t, func() { c.Redirect(309, "/new_path") })
  281. c.Redirect(302, "/path")
  282. c.Writer.WriteHeaderNow()
  283. assert.Equal(t, w.Code, 302)
  284. assert.Equal(t, w.Header().Get("Location"), "/path")
  285. }
  286. func TestContextRenderRedirectWithAbsolutePath(t *testing.T) {
  287. c, w, _ := createTestContext()
  288. c.Request, _ = http.NewRequest("POST", "http://example.com", nil)
  289. c.Redirect(302, "http://google.com")
  290. c.Writer.WriteHeaderNow()
  291. assert.Equal(t, w.Code, 302)
  292. assert.Equal(t, w.Header().Get("Location"), "http://google.com")
  293. }
  294. func TestContextNegotiationFormat(t *testing.T) {
  295. c, _, _ := createTestContext()
  296. c.Request, _ = http.NewRequest("POST", "", nil)
  297. assert.Panics(t, func() { c.NegotiateFormat() })
  298. assert.Equal(t, c.NegotiateFormat(MIMEJSON, MIMEXML), MIMEJSON)
  299. assert.Equal(t, c.NegotiateFormat(MIMEHTML, MIMEJSON), MIMEHTML)
  300. }
  301. func TestContextNegotiationFormatWithAccept(t *testing.T) {
  302. c, _, _ := createTestContext()
  303. c.Request, _ = http.NewRequest("POST", "/", nil)
  304. c.Request.Header.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
  305. assert.Equal(t, c.NegotiateFormat(MIMEJSON, MIMEXML), MIMEXML)
  306. assert.Equal(t, c.NegotiateFormat(MIMEXML, MIMEHTML), MIMEHTML)
  307. assert.Equal(t, c.NegotiateFormat(MIMEJSON), "")
  308. }
  309. func TestContextNegotiationFormatCustum(t *testing.T) {
  310. c, _, _ := createTestContext()
  311. c.Request, _ = http.NewRequest("POST", "/", nil)
  312. c.Request.Header.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
  313. c.Accepted = nil
  314. c.SetAccepted(MIMEJSON, MIMEXML)
  315. assert.Equal(t, c.NegotiateFormat(MIMEJSON, MIMEXML), MIMEJSON)
  316. assert.Equal(t, c.NegotiateFormat(MIMEXML, MIMEHTML), MIMEXML)
  317. assert.Equal(t, c.NegotiateFormat(MIMEJSON), MIMEJSON)
  318. }
  319. // TestContextData tests that the response can be written from `bytesting`
  320. // with specified MIME type
  321. func TestContextAbortWithStatus(t *testing.T) {
  322. c, w, _ := createTestContext()
  323. c.index = 4
  324. c.AbortWithStatus(401)
  325. c.Writer.WriteHeaderNow()
  326. assert.Equal(t, c.index, AbortIndex)
  327. assert.Equal(t, c.Writer.Status(), 401)
  328. assert.Equal(t, w.Code, 401)
  329. assert.True(t, c.IsAborted())
  330. }
  331. func TestContextError(t *testing.T) {
  332. c, _, _ := createTestContext()
  333. assert.Empty(t, c.Errors)
  334. c.Error(errors.New("first error"))
  335. assert.Len(t, c.Errors, 1)
  336. assert.Equal(t, c.Errors.String(), "Error #01: first error\n")
  337. c.Error(&Error{
  338. Err: errors.New("second error"),
  339. Meta: "some data 2",
  340. Type: ErrorTypePublic,
  341. })
  342. assert.Len(t, c.Errors, 2)
  343. assert.Equal(t, c.Errors[0].Err, errors.New("first error"))
  344. assert.Nil(t, c.Errors[0].Meta)
  345. assert.Equal(t, c.Errors[0].Type, ErrorTypePrivate)
  346. assert.Equal(t, c.Errors[1].Err, errors.New("second error"))
  347. assert.Equal(t, c.Errors[1].Meta, "some data 2")
  348. assert.Equal(t, c.Errors[1].Type, ErrorTypePublic)
  349. assert.Equal(t, c.Errors.Last(), c.Errors[1])
  350. }
  351. func TestContextTypedError(t *testing.T) {
  352. c, _, _ := createTestContext()
  353. c.Error(errors.New("externo 0")).SetType(ErrorTypePublic)
  354. c.Error(errors.New("interno 0")).SetType(ErrorTypePrivate)
  355. for _, err := range c.Errors.ByType(ErrorTypePublic) {
  356. assert.Equal(t, err.Type, ErrorTypePublic)
  357. }
  358. for _, err := range c.Errors.ByType(ErrorTypePrivate) {
  359. assert.Equal(t, err.Type, ErrorTypePrivate)
  360. }
  361. assert.Equal(t, c.Errors.Errors(), []string{"externo 0", "interno 0"})
  362. }
  363. func TestContextAbortWithError(t *testing.T) {
  364. c, w, _ := createTestContext()
  365. c.AbortWithError(401, errors.New("bad input")).SetMeta("some input")
  366. c.Writer.WriteHeaderNow()
  367. assert.Equal(t, w.Code, 401)
  368. assert.Equal(t, c.index, AbortIndex)
  369. assert.True(t, c.IsAborted())
  370. }
  371. func TestContextClientIP(t *testing.T) {
  372. c, _, _ := createTestContext()
  373. c.Request, _ = http.NewRequest("POST", "/", nil)
  374. c.Request.Header.Set("X-Real-IP", " 10.10.10.10 ")
  375. c.Request.Header.Set("X-Forwarded-For", " 20.20.20.20 , 30.30.30.30")
  376. c.Request.RemoteAddr = " 40.40.40.40 "
  377. assert.Equal(t, c.ClientIP(), "10.10.10.10")
  378. c.Request.Header.Del("X-Real-IP")
  379. assert.Equal(t, c.ClientIP(), "20.20.20.20")
  380. c.Request.Header.Set("X-Forwarded-For", "30.30.30.30")
  381. assert.Equal(t, c.ClientIP(), "30.30.30.30")
  382. c.Request.Header.Del("X-Forwarded-For")
  383. assert.Equal(t, c.ClientIP(), "40.40.40.40")
  384. }
  385. func TestContextContentType(t *testing.T) {
  386. c, _, _ := createTestContext()
  387. c.Request, _ = http.NewRequest("POST", "/", nil)
  388. c.Request.Header.Set("Content-Type", "application/json; charset=utf-8")
  389. assert.Equal(t, c.ContentType(), "application/json")
  390. }
  391. func TestContextAutoBindJSON(t *testing.T) {
  392. c, _, _ := createTestContext()
  393. c.Request, _ = http.NewRequest("POST", "/", bytes.NewBufferString("{\"foo\":\"bar\", \"bar\":\"foo\"}"))
  394. c.Request.Header.Add("Content-Type", MIMEJSON)
  395. var obj struct {
  396. Foo string `json:"foo"`
  397. Bar string `json:"bar"`
  398. }
  399. assert.NoError(t, c.Bind(&obj))
  400. assert.Equal(t, obj.Bar, "foo")
  401. assert.Equal(t, obj.Foo, "bar")
  402. assert.Empty(t, c.Errors)
  403. }
  404. func TestContextBindWithJSON(t *testing.T) {
  405. c, w, _ := createTestContext()
  406. c.Request, _ = http.NewRequest("POST", "/", bytes.NewBufferString("{\"foo\":\"bar\", \"bar\":\"foo\"}"))
  407. c.Request.Header.Add("Content-Type", MIMEXML) // set fake content-type
  408. var obj struct {
  409. Foo string `json:"foo"`
  410. Bar string `json:"bar"`
  411. }
  412. assert.NoError(t, c.BindJSON(&obj))
  413. assert.Equal(t, obj.Bar, "foo")
  414. assert.Equal(t, obj.Foo, "bar")
  415. assert.Equal(t, w.Body.Len(), 0)
  416. }
  417. func TestContextBadAutoBind(t *testing.T) {
  418. c, w, _ := createTestContext()
  419. c.Request, _ = http.NewRequest("POST", "http://example.com", bytes.NewBufferString("\"foo\":\"bar\", \"bar\":\"foo\"}"))
  420. c.Request.Header.Add("Content-Type", MIMEJSON)
  421. var obj struct {
  422. Foo string `json:"foo"`
  423. Bar string `json:"bar"`
  424. }
  425. assert.False(t, c.IsAborted())
  426. assert.Error(t, c.Bind(&obj))
  427. c.Writer.WriteHeaderNow()
  428. assert.Empty(t, obj.Bar)
  429. assert.Empty(t, obj.Foo)
  430. assert.Equal(t, w.Code, 400)
  431. assert.True(t, c.IsAborted())
  432. }
  433. func TestContextGolangContext(t *testing.T) {
  434. c, _, _ := createTestContext()
  435. c.Request, _ = http.NewRequest("POST", "/", bytes.NewBufferString("{\"foo\":\"bar\", \"bar\":\"foo\"}"))
  436. assert.NoError(t, c.Err())
  437. assert.Nil(t, c.Done())
  438. ti, ok := c.Deadline()
  439. assert.Equal(t, ti, time.Time{})
  440. assert.False(t, ok)
  441. assert.Equal(t, c.Value(0), c.Request)
  442. assert.Nil(t, c.Value("foo"))
  443. c.Set("foo", "bar")
  444. assert.Equal(t, c.Value("foo"), "bar")
  445. assert.Nil(t, c.Value(1))
  446. }