| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867 |
- package prepare
- import (
- "fmt"
- "testing"
- "time"
- . "git.wecise.com/wecise/odbserver/odb"
- "git.wecise.com/wecise/odbserver/odb/test"
- "gitee.com/wecisecode/util/logger"
- "github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/require"
- )
- type PrepareTests struct {
- Test *testing.T
- g *Gutil
- }
- func PrepareTest(t *testing.T) {
- g := test.TestG()
- t.Run("InitG", func(t *testing.T) {
- test := &PrepareTests{Test: t, g: g}
- test.InitG()
- })
- t.Run("Class", func(t *testing.T) {
- test := &PrepareTests{Test: t, g: g}
- test.Class()
- })
- t.Run("Data", func(t *testing.T) {
- test := &PrepareTests{Test: t, g: g}
- test.Data()
- })
- time.Sleep(time.Duration(1) * time.Second)
- t.Run("Valid", func(t *testing.T) {
- test := &PrepareTests{Test: t, g: g}
- test.Valid()
- })
- t.Run("Int", func(t *testing.T) {
- test := &PrepareTests{Test: t, g: g}
- test.Int()
- })
- t.Run("Bool", func(t *testing.T) {
- test := &PrepareTests{Test: t, g: g}
- test.Bool()
- })
- t.Run("FullSearch", func(t *testing.T) {
- test := &PrepareTests{Test: t, g: g}
- test.FullSearch()
- })
- t.Run("Prefix", func(t *testing.T) {
- test := &PrepareTests{Test: t, g: g}
- test.Prefix()
- })
- t.Run("NotIn", func(t *testing.T) {
- test := &PrepareTests{Test: t, g: g}
- test.NotIn()
- })
- /*t.Run("Rename", func(t *testing.T) {
- test := &PrepareTests{Test: t, g: g}
- test.Rename()
- })*/
- t.Run("Float", func(t *testing.T) {
- test := &PrepareTests{Test: t, g: g}
- test.Float()
- })
- t.Run("Double", func(t *testing.T) {
- test := &PrepareTests{Test: t, g: g}
- test.Double()
- })
- }
- func (t *PrepareTests) InitG() {
- require.NotNil(t.Test, t.g)
- }
- func (t *PrepareTests) Class() {
- _, _, err := t.g.Query(`
- create class if not exists /test/prepare (
-
- v_varchar varchar,
- v_text text,
- v_int int,
- v_bigint bigint,
- v_smalldouble double,
- v_double double,
- v_float float,
- v_bool bool,
- v_timestamp timestamp,
- v_blob blob,
-
- indexes(v_varchar, v_text, v_int, v_bigint, v_double, v_float, v_smalldouble, v_bool, v_timestamp),
- keys(v_varchar, v_text)
- );`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- require.Nil(t.Test, err, fmt.Sprint(err))
- }
- func (t *PrepareTests) Data() {
- stat, err := t.g.Prepare(`insert into /test/prepare (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool, v_timestamp, v_blob) values (?, ?, ?, ?, ?, ?, ?, ? ,?, ? )`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- require.Nil(t.Test, err, fmt.Sprint(err))
- _, _, err = stat.Exec("*abc*", `hello word 2003 123-456-789 中华人民共和国是中国的唯一合法政府,台湾是中国一部分。 Mercury, Venus2,Earch%。Mars$Uranus CeresAndJupiterOrSaturn #Neptune Pluto_Charon"\""`, 1, 1234567890123456789, 1.1, 1.1234567890123456, 1.123456, true, nil, []byte("hello"))
- if err != nil {
- logger.Errorf("%v", err)
- }
- require.Nil(t.Test, err, fmt.Sprint(err))
- _, _, err = stat.Exec("2", `because in both case, Cassandra guarantees that these queries performance will be proportional to the amount of data returned. In particular, if no users are born in 1981, then the second query performance will not depend of the number of user profile stored in the database (not directly at least: due to secondary index implementation consideration, this query may still depend on the number of node in the cluster, which indirectly depends on the amount of data stored. Nevertheless, the number of nodes will always be multiple number of magnitude lower than the number of user profile stored). Of course, both query may return very large result set in practice, but the amount of data returned can always be controlled by adding a LIMIT.`, 1, 1234567890123456789, 1.1, 1.1234567890123456, 1.123456, false, nil)
- if err != nil {
- logger.Errorf("%v", err)
- }
- require.Nil(t.Test, err, fmt.Sprint(err))
- _, _, err = stat.Exec("3", `{
- "id": "omdb-query-query",
- "bid": "omdb-query-query",
- "type": "json-update",
- "data": {
- "message": [
- {
- "graph": {
- "nodes": [
- {
- "_icon": "app",
- "class": "/matrix/entity/app",
- "id": "app:demoapp3",
- "name": "app:demoapp3",
- "status": 5
- },
- {
- "class": "/matrix/entity/pod",
- "id": "pod:web-demo-f6dsp"
- },
- {
- "_icon": "mysql",
- "class": "/matrix/entity/mysql",
- "id": "mysql:demodb",
- "name": "mysql:demodb",
- "status": 0
- },
- {
- "_icon": "biz",
- "class": "/matrix/entity/biz",
- "id": "biz:开发测试",
- "name": "biz:开发测试",
- "status": 4
- },
- {
- "_icon": "linux",
- "class": "/matrix/entity/linux",
- "id": "linux:node2",
- "name": "linux:node2",
- "status": 0
- },
- {
- "_icon": "mysql",
- "class": "/matrix/entity/mysql",
- "id": "mysql:appdb",
- "name": "mysql:appdb",
- "status": 0
- },
- {
- "_icon": "app",
- "class": "/matrix/entity/app",
- "id": "app:demoapp2",
- "name": "app:demoapp2",
- "status": 0
- },
- {
- "_icon": "app",
- "class": "/matrix/entity/app",
- "id": "app:tomcat-app3",
- "name": "app:tomcat-app3",
- "status": 5
- },
- {
- "_icon": "linux",
- "class": "/matrix/entity/linux",
- "id": "linux:node1",
- "name": "linux:node1",
- "status": 0
- },
- {
- "_icon": "pod",
- "class": "/matrix/entity/pod",
- "id": "pod:tomcat-pod1",
- "name": "pod:tomcat-pod1",
- "status": 4
- },
- {
- "_icon": "linux",
- "class": "/matrix/entity/linux",
- "id": "linux:node4",
- "name": "linux:node4",
- "status": 0
- },
- {
- "_icon": "app",
- "class": "/matrix/entity/app",
- "id": "app:demoapp1",
- "name": "app:demoapp1",
- "status": 0
- },
- {
- "_icon": "pod",
- "class": "/matrix/entity/pod",
- "id": "pod:mysql-demo-pod1",
- "name": "pod:mysql-demo-pod1",
- "status": 4
- },
- {
- "_icon": "pod",
- "class": "/matrix/entity/pod",
- "id": "pod:tomcat-pod2",
- "name": "pod:tomcat-pod2",
- "status": 4
- },
- {
- "class": "/matrix/entity/pod",
- "id": "pod:tomcat-pod3"
- },
- {
- "_icon": "app",
- "class": "/matrix/entity/app",
- "id": "app:tomcat-app1",
- "name": "app:tomcat-app1",
- "status": 0
- },
- {
- "_icon": "app",
- "class": "/matrix/entity/app",
- "id": "app:tomcat-app2",
- "name": "app:tomcat-app2",
- "status": 0
- },
- {
- "class": "/matrix/entity/pod",
- "id": "pod:web-demo-j6qxj"
- },
- {
- "class": "/matrix/entity/pod",
- "id": "pod:web-demo-9rfxj"
- },
- {
- "_icon": "biz",
- "class": "/matrix/entity/biz",
- "id": "biz:数字国网",
- "name": "biz:数字国网",
- "status": 4
- }
- ],
- "edges": [
- {
- "attrs": {},
- "class": "connect",
- "id": "app:demoapp1-mysql:demodb",
- "source": "app:demoapp1",
- "target": "mysql:demodb"
- },
- {
- "attrs": {},
- "class": "contain",
- "id": "biz:开发测试-app:demoapp2",
- "source": "biz:开发测试",
- "target": "app:demoapp2"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "mysql:appdb-linux:node4",
- "source": "mysql:appdb",
- "target": "linux:node4"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "mysql:demodb-pod:mysql",
- "source": "mysql:demodb",
- "target": "pod:mysql"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "app:tomcat-app2",
- "source": "app:tomcat",
- "target": "app2"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "pod:tomcat-pod2",
- "source": "pod:tomcat",
- "target": "pod2"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "app:demoapp1-pod:web",
- "source": "app:demoapp1",
- "target": "pod:web"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "pod:mysql-demo",
- "source": "pod:mysql",
- "target": "demo"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "app:demoapp2-pod:web",
- "source": "app:demoapp2",
- "target": "pod:web"
- },
- {
- "attrs": {},
- "class": "connect",
- "id": "app:demoapp3-mysql:demodb",
- "source": "app:demoapp3",
- "target": "mysql:demodb"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "app:demoapp3-pod:web",
- "source": "app:demoapp3",
- "target": "pod:web"
- },
- {
- "attrs": {
- "floatp": 3.4,
- "intp": 1
- },
- "class": "contain",
- "id": "biz:数字国网-app:tomcat",
- "source": "biz:数字国网",
- "target": "app:tomcat"
- },
- {
- "attrs": {},
- "class": "connect",
- "id": "app:tomcat-app3",
- "source": "app:tomcat",
- "target": "app3"
- },
- {
- "attrs": {},
- "class": "contain",
- "id": "biz:开发测试-app:demoapp3",
- "source": "biz:开发测试",
- "target": "app:demoapp3"
- },
- {
- "attrs": {},
- "class": "contain",
- "id": "biz:开发测试-app:demoapp1",
- "source": "biz:开发测试",
- "target": "app:demoapp1"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "pod:tomcat-pod1",
- "source": "pod:tomcat",
- "target": "pod1"
- },
- {
- "attrs": {},
- "class": "connect",
- "id": "app:tomcat-app1",
- "source": "app:tomcat",
- "target": "app1"
- },
- {
- "attrs": {},
- "class": "connect",
- "id": "app:demoapp2-mysql:demodb",
- "source": "app:demoapp2",
- "target": "mysql:demodb"
- }
- ],
- "paths": null,
- "diff": null,
- "pathtags": null
- }
- }
- ],
- "meta": {
- "type": "graph"
- },
- "status": "ok"
- }
- }`, 1, 1234567890123456789, 1.1, 1.1234567890123456, 1.123456, true, "2022-03-02 20:22:19")
- if err != nil {
- logger.Errorf("%v", err)
- }
- require.Nil(t.Test, err, fmt.Sprint(err))
- }
- func (t *PrepareTests) Valid() {
- rtn, _, err := t.g.Query(`select * from /test/prepare`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, 3, len(rtn), "they should be equal")
- for _, row := range rtn {
- switch row["v_varchar"].(string) {
- case "*abc*":
- assert.Equal(t.Test, `hello word 2003 123-456-789 中华人民共和国是中国的唯一合法政府,台湾是中国一部分。 Mercury, Venus2,Earch%。Mars$Uranus CeresAndJupiterOrSaturn #Neptune Pluto_Charon"\""`, row["v_text"].(string), "they should be equal")
- }
- }
- }
- }
- rtn, _, err = t.g.Query(` select * from /test/prepare where v_varchar=='*abc*' `)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, 1, len(rtn), "they should be equal")
- }
- }
- rtn, _, err = t.g.Query(`select class from / where id='3991197448023402669'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, 1, len(rtn), "they should be equal")
- }
- }
- rtn, _, err = t.g.Query(`select class from /test/ where id='3991197448023402669'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, 1, len(rtn), "they should be equal")
- }
- }
- stat, errr := t.g.Prepare(`select class from /test/ where id='3991197448023402669' limit ?`)
- if errr != nil {
- logger.Errorf("%v", err)
- }
- _, _, err = stat.Exec(10)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, 1, len(rtn), "they should be equal")
- }
- }
- }
- func (t *PrepareTests) Int() {
- var err error
- var rtn []map[string]interface{}
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_int = 1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_int = %v", "1"))
- }
- }
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_int > 0`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_int > %v", "0"))
- }
- }
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_int < 2`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_int < %v", "2"))
- }
- }
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_int >= 1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_int >= %v", "1"))
- }
- }
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_int <= 1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_int <= %v", "1"))
- }
- }
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_int >= 1.1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(0), rtn[0]["count"].(int64), fmt.Sprintf("not find v_int >= %v", "1.1"))
- }
- }
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_int > 1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(0), rtn[0]["count"].(int64), fmt.Sprintf("not find v_int > %v", "1"))
- }
- }
- }
- func (t *PrepareTests) Bool() {
- var err error
- var rtn []map[string]interface{}
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_bool = true`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(2), rtn[0]["count"].(int64), fmt.Sprintf("not find v_bool = %v", "true"))
- }
- }
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_bool = false`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(1), rtn[0]["count"].(int64), fmt.Sprintf("not find v_bool = %v", "false"))
- }
- }
- }
- func (t *PrepareTests) Float() {
- var err error
- var rtn []map[string]interface{}
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_float >= 1.1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_float >= %v", "1.1"))
- }
- }
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_float > 1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_float > %v", "1"))
- }
- }
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_float = 1.1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_float = %v", "1.1"))
- }
- }
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_float < 2`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_float < %v", "2"))
- }
- }
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_float <= 1.1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_float <= %v", "1.1"))
- }
- }
- }
- func (t *PrepareTests) Double() {
- var err error
- var rtn []map[string]interface{}
- rtn, _, err = t.g.Query(`select * from /test/prepare where v_double >= 1.1234567890123456`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_double >= %v", "1.1234567890123456"))
- }
- }
- //??????
- rtn, _, err = t.g.Query(`select * from /test/prepare where v_smalldouble >= 1.123456`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find , v_smalldouble >= %v", "1.123456"))
- }
- }
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_double > 1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_double > %v", "1"))
- }
- }
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_double = 1.1234567890123456`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_double = %v", "1.1234567890123456"))
- }
- }
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_double < 2`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_double < %v", "2"))
- }
- }
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_double <= 1.1234567890123456`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_double <= %v", "1.1234567890123456"))
- }
- }
- }
- func (t *PrepareTests) NotIn() {
- var err error
- var rtn []map[string]interface{}
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_varchar not in('2', '3')`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(1), rtn[0]["count"].(int64), fmt.Sprintf("not find %v", "hello"))
- }
- }
- }
- /*
- func (t *PrepareTests) Rename() {
- var err error
- //var rtn []map[string]interface{}
- _,_,err = t.g.Query(`alter /test/prepare rename v_bool v_bool2`)
- if err !=nil {
- logger.Errorf("%v", err)
- }
- assert.Nil(t.Test, err)
- }
- */
- func (t *PrepareTests) Prefix() {
- var err error
- var rtn []map[string]interface{}
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_text=^'hell'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(1), rtn[0]["count"].(int64), fmt.Sprintf("not find %v", "hello"))
- }
- }
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_text='*20*'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(1), rtn[0]["count"].(int64), fmt.Sprintf("not find %v", "2003"))
- }
- }
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_text='*123-456*'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(1), rtn[0]["count"].(int64), fmt.Sprintf("not find %v", "123-456-789"))
- }
- }
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_text='*中*'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(1), rtn[0]["count"].(int64), fmt.Sprintf("not find %v", "中国"))
- }
- }
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_text='*magni*'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(1), rtn[0]["count"].(int64), fmt.Sprintf("not find %v", "magnitude"))
- }
- }
- }
- func (t *PrepareTests) FullSearch() {
- var err error
- var rtn []map[string]interface{}
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_text='hello'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(1), rtn[0]["count"].(int64), fmt.Sprintf("not find %v", "hello"))
- }
- }
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_text='2003'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(1), rtn[0]["count"].(int64), fmt.Sprintf("not find %v", "2003"))
- }
- }
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_text='123-456-789'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(1), rtn[0]["count"].(int64), fmt.Sprintf("not find %v", "123-456-789"))
- }
- }
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_text='中国'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(1), rtn[0]["count"].(int64), fmt.Sprintf("not find %v", "中国"))
- }
- }
- rtn, _, err = t.g.Query(`select count(*) as count from /test/prepare where v_text='magnitude'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, int64(1), rtn[0]["count"].(int64), fmt.Sprintf("not find %v", "magnitude"))
- }
- }
- }
|