package ckeys 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 ConcatKeyTests struct { Test *testing.T g *Gutil } func ConcatKeyTest(t *testing.T) { g := test.TestG() t.Run("InitG", func(t *testing.T) { test := &ConcatKeyTests{Test: t, g: g} test.InitG() }) t.Run("Class", func(t *testing.T) { test := &ConcatKeyTests{Test: t, g: g} test.Class() }) t.Run("Data", func(t *testing.T) { test := &ConcatKeyTests{Test: t, g: g} test.Data() }) time.Sleep(time.Duration(1) * time.Second) t.Run("Valid", func(t *testing.T) { test := &ConcatKeyTests{Test: t, g: g} test.Valid() }) } func (t *ConcatKeyTests) InitG() { require.NotNil(t.Test, t.g) } func (t *ConcatKeyTests) Class() { _, _, err := t.g.Query(` create class if not exists /test/concat ( v_varchar varchar, v_text text, v_int int, v_bigint bigint, v_smalldouble double, v_double double, v_float float, v_bool bool, indexes(v_varchar, v_text, v_int, v_bigint, v_double, v_float, v_smalldouble, v_bool), keys(v_varchar , v_text) ) with ckeys=v_bool`) if err != nil { logger.Errorf("%v", err) } require.Nil(t.Test, err, fmt.Sprint(err)) } func (t *ConcatKeyTests) Data() { var err error _, _, err = t.g.Query(`insert into /test/concat (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('4006', 'hello word 2003', 4006, 4006, 1.1, 1.1234567890123456, 1.123456, true )`) _, _, err = t.g.Query(`insert into /test/concat (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('40', 'hello word 2003', 40, 40, 1.1, 1.1234567890123456, 1.123456, false )`) _, _, err = t.g.Query(`insert into /test/concat (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('400', 'hello word 2003', 400, 400, 1.1, 1.1234567890123456, 1.123456, true )`) _, _, err = t.g.Query(`insert into /test/concat (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('74006', 'hello word 2003', -4006, 4006, 1.1, 1.1234567890123456, 1.123456, false )`) _, _, err = t.g.Query(`insert into /test/concat (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('409', 'hello word 2003', -40, 40, 1.1, 1.1234567890123456, 1.123456, true )`) _, _, err = t.g.Query(`insert into /test/concat (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('500', 'hello word 2003', -400, 400, 1.1, 1.1234567890123456, 1.123456, false )`) _, _, err = t.g.Query(`insert into /test/concat (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('600', 'hello word 2003', 370, 370, 1.1, 1.1234567890123456, 1.123456, true )`) _, _, err = t.g.Query(`insert into /test/concat (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('700', 'hello word 2003', 580, 580, 1.1, 1.1234567890123456, 1.123456, true )`) _, _, err = t.g.Query(`insert into /test/concat (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('602', 'hello word 2003', -370, -370, 1.1, 1.1234567890123456, 1.123456, true )`) _, _, err = t.g.Query(`insert into /test/concat (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('708', 'hello word 2003', -580, -580, 1.1, 1.1234567890123456, 1.123456, true )`) if err != nil { logger.Errorf("%v", err) } require.Nil(t.Test, err, fmt.Sprint(err)) } func (t *ConcatKeyTests) Valid() { rtn, _, err := t.g.Query(`select * from /test/concat`) if err != nil { logger.Errorf("%v", err) } if assert.Nil(t.Test, err) { if assert.NotNil(t.Test, rtn) { assert.Equal(t.Test, 10, len(rtn), "they should be equal") } } }