TestContextSetGet tests that a parameter is set correctly on the current context and can be retrieved using Get.
(t *testing.T)
| 319 | // TestContextSetGet tests that a parameter is set correctly on the |
| 320 | // current context and can be retrieved using Get. |
| 321 | func TestContextSetGet(t *testing.T) { |
| 322 | c, _ := CreateTestContext(httptest.NewRecorder()) |
| 323 | c.Set("foo", "bar") |
| 324 | |
| 325 | value, err := c.Get("foo") |
| 326 | assert.Equal(t, "bar", value) |
| 327 | assert.True(t, err) |
| 328 | |
| 329 | value, err = c.Get("foo2") |
| 330 | assert.Nil(t, value) |
| 331 | assert.False(t, err) |
| 332 | |
| 333 | assert.Equal(t, "bar", c.MustGet("foo")) |
| 334 | assert.Panicsf(t, func() { |
| 335 | c.MustGet("no_exist") |
| 336 | }, "key no_exist does not exist") |
| 337 | } |
| 338 | |
| 339 | func TestContextSetGetAnyKey(t *testing.T) { |
| 340 | c, _ := CreateTestContext(httptest.NewRecorder()) |
nothing calls this directly
no test coverage detected
searching dependent graphs…