ckeyint.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package ckeys
  2. import (
  3. "fmt"
  4. "testing"
  5. . "git.wecise.com/wecise/odbserver/odb"
  6. "git.wecise.com/wecise/odbserver/odb/test"
  7. "gitee.com/wecisecode/util/logger"
  8. "github.com/stretchr/testify/assert"
  9. "github.com/stretchr/testify/require"
  10. )
  11. type CKIntTests struct {
  12. Test *testing.T
  13. g *Gutil
  14. }
  15. func CKIntTest(t *testing.T) {
  16. g := test.TestG()
  17. t.Run("InitG", func(t *testing.T) {
  18. test := &CKIntTests{Test: t, g: g}
  19. test.InitG()
  20. })
  21. t.Run("Class", func(t *testing.T) {
  22. test := &CKIntTests{Test: t, g: g}
  23. test.Class()
  24. })
  25. t.Run("Data", func(t *testing.T) {
  26. test := &CKIntTests{Test: t, g: g}
  27. test.Data()
  28. })
  29. t.Run("Valid", func(t *testing.T) {
  30. test := &CKIntTests{Test: t, g: g}
  31. test.Valid()
  32. })
  33. }
  34. func (t *CKIntTests) InitG() {
  35. require.NotNil(t.Test, t.g)
  36. }
  37. func (t *CKIntTests) Class() {
  38. _, _, err := t.g.Query(`
  39. create class if not exists /test/concat3 (
  40. v_varchar varchar,
  41. v_text text,
  42. v_int int,
  43. v_bigint bigint,
  44. v_smalldouble double,
  45. v_double double,
  46. v_float float,
  47. v_bool bool,
  48. indexes(v_varchar, v_text, v_int, v_bigint, v_double, v_float, v_smalldouble, v_bool),
  49. keys(v_varchar , v_text)
  50. ) with ckeys=v_bigint`)
  51. if err != nil {
  52. logger.Errorf("%v", err)
  53. }
  54. require.Nil(t.Test, err, fmt.Sprint(err))
  55. }
  56. func (t *CKIntTests) Data() {
  57. var err error
  58. _, _, err = t.g.Query(`insert into /test/concat3 (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 )`)
  59. _, _, err = t.g.Query(`insert into /test/concat3 (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 )`)
  60. _, _, err = t.g.Query(`insert into /test/concat3 (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 )`)
  61. _, _, err = t.g.Query(`insert into /test/concat3 (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 )`)
  62. _, _, err = t.g.Query(`insert into /test/concat3 (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 )`)
  63. _, _, err = t.g.Query(`insert into /test/concat3 (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 )`)
  64. _, _, err = t.g.Query(`insert into /test/concat3 (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 )`)
  65. _, _, err = t.g.Query(`insert into /test/concat3 (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 )`)
  66. _, _, err = t.g.Query(`insert into /test/concat3 (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 )`)
  67. _, _, err = t.g.Query(`insert into /test/concat3 (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 )`)
  68. if err != nil {
  69. logger.Errorf("%v", err)
  70. }
  71. require.Nil(t.Test, err, fmt.Sprint(err))
  72. }
  73. func (t *CKIntTests) Valid() {
  74. rtn, _, err := t.g.Query(`select * from /test/concat3`)
  75. if err != nil {
  76. logger.Errorf("%v", err)
  77. }
  78. if assert.Nil(t.Test, err) {
  79. if assert.NotNil(t.Test, rtn) {
  80. assert.Equal(t.Test, 10, len(rtn), "they should be equal")
  81. }
  82. }
  83. }