1 Star 0 Fork 7

kyle / gobatch

forked from chararch / gobatch 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
context_test.go 883 Bytes
一键复制 编辑 原始数据 按行查看 历史
chararch 提交于 2022-03-24 00:21 . format code & add comment
package gobatch
import (
"fmt"
"github.com/bmizerany/assert"
"github.com/chararch/gobatch/util"
"testing"
)
func TestBatchContext_Get(t *testing.T) {
ctx := NewBatchContext()
v := ctx.Get("key")
assert.Equal(t, v, nil)
ctx.Put("key", "1111")
assert.Equal(t, ctx.Get("key"), "1111")
}
type Key struct {
Id int64
Code string
}
func TestBatchContext_MarshalJSON(t *testing.T) {
batchCtx := NewBatchContext()
batchCtx.Put("count", 100)
batchCtx.Put("current", 5)
batchCtx.Put("keys", []Key{{
Id: 1,
Code: "1",
}, {
Id: 2,
Code: "2",
}, {
Id: 3,
Code: "3",
},
})
json, err := util.JsonString(batchCtx)
assert.Equal(t, nil, err)
fmt.Printf("json:%v\n", json)
batchCtx2 := NewBatchContext()
err = util.ParseJson(json, batchCtx2)
assert.Equal(t, nil, err)
fmt.Printf("batchCtx:%+v\n", batchCtx)
fmt.Printf("batchCtx2:%+v\n", batchCtx2)
}
Go
1
https://gitee.com/workface/gobatch.git
git@gitee.com:workface/gobatch.git
workface
gobatch
gobatch
master

搜索帮助