2020-05-26 13:24:31 +00:00
|
|
|
package querylog
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestJSON(t *testing.T) {
|
|
|
|
s := `
|
|
|
|
{"keystr":"val","obj":{"keybool":true,"keyint":123456}}
|
|
|
|
`
|
|
|
|
k, v, jtype := readJSON(&s)
|
|
|
|
assert.Equal(t, jtype, int32(jsonTStr))
|
|
|
|
assert.Equal(t, "keystr", k)
|
|
|
|
assert.Equal(t, "val", v)
|
|
|
|
|
2020-10-30 16:18:51 +00:00
|
|
|
k, _, jtype = readJSON(&s)
|
2020-05-26 13:24:31 +00:00
|
|
|
assert.Equal(t, jtype, int32(jsonTObj))
|
|
|
|
assert.Equal(t, "obj", k)
|
|
|
|
|
|
|
|
k, v, jtype = readJSON(&s)
|
|
|
|
assert.Equal(t, jtype, int32(jsonTBool))
|
|
|
|
assert.Equal(t, "keybool", k)
|
|
|
|
assert.Equal(t, "true", v)
|
|
|
|
|
|
|
|
k, v, jtype = readJSON(&s)
|
|
|
|
assert.Equal(t, jtype, int32(jsonTNum))
|
|
|
|
assert.Equal(t, "keyint", k)
|
|
|
|
assert.Equal(t, "123456", v)
|
|
|
|
|
2020-10-30 16:18:51 +00:00
|
|
|
_, _, jtype = readJSON(&s)
|
2020-05-26 13:24:31 +00:00
|
|
|
assert.True(t, jtype == jsonTErr)
|
|
|
|
}
|