-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext_test.go
51 lines (39 loc) · 1.2 KB
/
context_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package golden
import (
//"fmt"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestGetSetHttpContext(t *testing.T) {
c := HttpContext{
context: &gin.Context{},
}
tmp := "1"
c.Set("A", tmp)
assert.Equal(t, c.GetString("A"), "1")
c.Set("A'", &tmp)
assert.Equal(t, c.GetString("A'"), "")
c.Set("B", true)
assert.Equal(t, c.GetBool("B"), true)
c.Set("C", 3)
assert.Equal(t, c.GetInt("C"), 3)
c.Set("D", int64(4))
assert.Equal(t, c.GetInt64("D"), int64(4))
c.Set("E", float64(5))
assert.Equal(t, c.GetFloat64("E"), float64(5))
tt := time.Now()
c.Set("F", tt)
assert.Equal(t, c.GetTime("F"), tt)
c.Set("G", time.Duration(3)*time.Second)
assert.Equal(t, c.GetDuration("G"), time.Duration(3)*time.Second)
c.Set("H", []string{"1", "2"})
assert.Equal(t, c.GetStringSlice("H"), []string{"1", "2"})
c.Set("I", map[string]interface{}{"a": "b"})
assert.Equal(t, c.GetStringMap("I"), map[string]interface{}{"a": "b"})
c.Set("J", map[string]string{"a": "b"})
assert.Equal(t, c.GetStringMapString("J"), map[string]string{"a": "b"})
c.Set("K", map[string][]string{"a": {"b"}})
assert.Equal(t, c.GetStringMapStringSlice("K"), map[string][]string{"a": {"b"}})
}