forked from chararch/gobatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context_test.go
48 lines (42 loc) · 880 Bytes
/
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
package batch
import (
"fmt"
"github.com/bmizerany/assert"
"github.com/supreness/batch/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)
}