mirror of
https://github.com/gin-gonic/gin.git
synced 2025-05-22 20:49:23 +08:00
refactor(context): refactor keys to map[any]any
Signed-off-by: Flc゛ <four_leaf_clover@foxmail.com>
This commit is contained in:
parent
1188f19b0a
commit
0336111c45
@ -217,6 +217,34 @@ func TestContextSetGet(t *testing.T) {
|
||||
|
||||
assert.Equal(t, "bar", c.MustGet("foo"))
|
||||
assert.Panics(t, func() { c.MustGet("no_exist") })
|
||||
|
||||
// other types
|
||||
type key struct{}
|
||||
tests := []struct {
|
||||
key any
|
||||
}{
|
||||
{1},
|
||||
{int32(1)},
|
||||
{int64(1)},
|
||||
{uint(1)},
|
||||
{float32(1)},
|
||||
{key{}},
|
||||
{&key{}},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(reflect.TypeOf(tt.key).String(), func(t *testing.T) {
|
||||
c.Set(tt.key, 1)
|
||||
assert.Equal(t, 1, c.MustGet(tt.key))
|
||||
})
|
||||
}
|
||||
|
||||
// no comparable
|
||||
assert.Panics(t, func() {
|
||||
c.Set([]int{1}, 1)
|
||||
c.Set(func() {}, 1)
|
||||
c.Set(make(chan int), 1)
|
||||
})
|
||||
}
|
||||
|
||||
func TestContextSetGetValues(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user