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

Function TestContextSetGetValues

context_test.go:376–394  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

374}
375
376func TestContextSetGetValues(t *testing.T) {
377 c, _ := CreateTestContext(httptest.NewRecorder())
378 c.Set("string", "this is a string")
379 c.Set("int32", int32(-42))
380 c.Set("int64", int64(42424242424242))
381 c.Set("uint64", uint64(42))
382 c.Set("float32", float32(4.2))
383 c.Set("float64", 4.2)
384 var a any = 1
385 c.Set("intInterface", a)
386
387 assert.Exactly(t, "this is a string", c.MustGet("string").(string))
388 assert.Exactly(t, int32(-42), c.MustGet("int32").(int32))
389 assert.Exactly(t, int64(42424242424242), c.MustGet("int64").(int64))
390 assert.Exactly(t, uint64(42), c.MustGet("uint64").(uint64))
391 assert.InDelta(t, float32(4.2), c.MustGet("float32").(float32), 0.01)
392 assert.InDelta(t, 4.2, c.MustGet("float64").(float64), 0.01)
393 assert.Exactly(t, 1, c.MustGet("intInterface").(int))
394}
395
396func TestContextGetString(t *testing.T) {
397 c, _ := CreateTestContext(httptest.NewRecorder())

Callers

nothing calls this directly

Calls 3

CreateTestContextFunction · 0.85
SetMethod · 0.80
MustGetMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…