mirror of https://github.com/gin-gonic/gin.git
More unit tests for Context .Set and .Get
This commit is contained in:
parent
2d8f0a4801
commit
c391520654
|
@ -16,10 +16,11 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Unit tes TODO
|
// Unit tests TODO
|
||||||
// func (c *Context) File(filepath string) {
|
// func (c *Context) File(filepath string) {
|
||||||
// func (c *Context) Negotiate(code int, config Negotiate) {
|
// func (c *Context) Negotiate(code int, config Negotiate) {
|
||||||
// BAD case: func (c *Context) Render(code int, render render.Render, obj ...interface{}) {
|
// BAD case: func (c *Context) Render(code int, render render.Render, obj ...interface{}) {
|
||||||
|
// test that information is not leaked when reusing Contexts (using the Pool)
|
||||||
|
|
||||||
func createTestContext() (c *Context, w *httptest.ResponseRecorder, r *Engine) {
|
func createTestContext() (c *Context, w *httptest.ResponseRecorder, r *Engine) {
|
||||||
w = httptest.NewRecorder()
|
w = httptest.NewRecorder()
|
||||||
|
@ -69,6 +70,23 @@ func TestContextSetGet(t *testing.T) {
|
||||||
assert.Panics(t, func() { c.MustGet("no_exist") })
|
assert.Panics(t, func() { c.MustGet("no_exist") })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContextSetGetValues(t *testing.T) {
|
||||||
|
c, _, _ := createTestContext()
|
||||||
|
c.Set("string", "this is a string")
|
||||||
|
c.Set("int32", int32(-42))
|
||||||
|
c.Set("int64", int64(42424242424242))
|
||||||
|
c.Set("uint64", uint64(42))
|
||||||
|
c.Set("float32", float32(4.2))
|
||||||
|
c.Set("float64", 4.2)
|
||||||
|
|
||||||
|
assert.Exactly(t, c.MustGet("string").(string), "this is a string")
|
||||||
|
assert.Exactly(t, c.MustGet("int32").(int32), int32(-42))
|
||||||
|
assert.Exactly(t, c.MustGet("int64").(int64), int64(42424242424242))
|
||||||
|
assert.Exactly(t, c.MustGet("uint64").(uint64), uint64(42))
|
||||||
|
assert.Exactly(t, c.MustGet("float32").(float32), float32(4.2))
|
||||||
|
assert.Exactly(t, c.MustGet("float64").(float64), 4.2)
|
||||||
|
}
|
||||||
|
|
||||||
func TestContextCopy(t *testing.T) {
|
func TestContextCopy(t *testing.T) {
|
||||||
c, _, _ := createTestContext()
|
c, _, _ := createTestContext()
|
||||||
c.index = 2
|
c.index = 2
|
||||||
|
|
Loading…
Reference in New Issue