MCPcopy
hub / github.com/gin-gonic/gin / TestContextSetGet

Function TestContextSetGet

context_test.go:321–337  ·  view source on GitHub ↗

TestContextSetGet tests that a parameter is set correctly on the current context and can be retrieved using Get.

(t *testing.T)

Source from the content-addressed store, hash-verified

319// TestContextSetGet tests that a parameter is set correctly on the
320// current context and can be retrieved using Get.
321func 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
339func TestContextSetGetAnyKey(t *testing.T) {
340 c, _ := CreateTestContext(httptest.NewRecorder())

Callers

nothing calls this directly

Calls 4

CreateTestContextFunction · 0.85
SetMethod · 0.80
MustGetMethod · 0.80
GetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…