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

Function TestContextSetGetAnyKey

context_test.go:339–364  ·  context_test.go::TestContextSetGetAnyKey
(t *testing.T)

Source from the content-addressed store, hash-verified

337}
338
339func TestContextSetGetAnyKey(t *testing.T) {
340 c, _ := CreateTestContext(httptest.NewRecorder())
341
342 type key struct{}
343
344 tests := []struct {
345 key any
346 }{
347 {1},
348 {int32(1)},
349 {int64(1)},
350 {uint(1)},
351 {float32(1)},
352 {key{}},
353 {&key{}},
354 }
355
356 for _, tt := range tests {
357 t.Run(reflect.TypeOf(tt.key).String(), func(t *testing.T) {
358 c.Set(tt.key, 1)
359 value, ok := c.Get(tt.key)
360 assert.True(t, ok)
361 assert.Equal(t, 1, value)
362 })
363 }
364}
365
366func TestContextSetGetPanicsWhenKeyNotComparable(t *testing.T) {
367 c, _ := CreateTestContext(httptest.NewRecorder())

Callers

nothing calls this directly

Calls 5

CreateTestContextFunction · 0.85
RunMethod · 0.80
SetMethod · 0.80
StringMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected