Skip to content

Commit 5baa19e

Browse files
committed
tests: add SQL tests
Added SQL tests. Updated config.lua for creation the space for using SQL in tests. Added the check of Tarantool version to skip SQL tests if tarantool version < 2.0.0. Follows up #62
1 parent 2d7a3fd commit 5baa19e

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

config.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,22 @@ box.once("init", function()
4040
})
4141
st:truncate()
4242

43+
local sp = box.schema.space.create('SQL_TEST', {
44+
id = 515,
45+
temporary = true,
46+
if_not_exists = true,
47+
field_count = 2,
48+
format = {
49+
{name = "ID", type = "unsigned"},
50+
{name = "NAME", type = "string"},
51+
},
52+
})
53+
sp:create_index('primary', {
54+
type = 'tree',
55+
parts = {1, 'uint'},
56+
unique = true,
57+
if_not_exists = true,
58+
})
4359
--box.schema.user.grant('guest', 'read,write,execute', 'universe')
4460
box.schema.func.create('box.info')
4561
box.schema.func.create('simple_incr')
@@ -49,6 +65,7 @@ box.once("init", function()
4965
box.schema.user.grant('test', 'execute', 'universe')
5066
box.schema.user.grant('test', 'read,write', 'space', 'test')
5167
box.schema.user.grant('test', 'read,write', 'space', 'schematest')
68+
box.schema.user.grant('test', 'read,write', 'space', 'SQL_TEST')
5269
end)
5370

5471
local function simple_incr(a)

tarantool_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"log"
66
"os"
7+
"strconv"
78
"strings"
89
"sync"
910
"testing"
@@ -691,6 +692,59 @@ func TestClient(t *testing.T) {
691692
if val != 11 {
692693
t.Errorf("5 + 6 == 11, but got %v", val)
693694
}
695+
696+
// Check for skip SQL tests if tarantool version < 2.0.0
697+
resp, err = conn.Eval("return box.info.version", []interface{}{})
698+
if err != nil {
699+
t.Errorf("Failed to Eval for checking Tarantool version")
700+
}
701+
ver := parseTarantoolVersion(resp.Data[0].(string))
702+
if !sqlSupported(ver) {
703+
return
704+
}
705+
706+
// SQL Execute
707+
// prepare map for sql bind
708+
sqlBind := map[string]interface{}{
709+
"id": 1,
710+
"name": "test",
711+
}
712+
// insert data using sql query
713+
resp, err = conn.Execute("INSERT INTO SQL_TEST VALUES (:id, :name);", sqlBind)
714+
if err != nil {
715+
t.Errorf("Failed to Execute: %s", err.Error())
716+
}
717+
if resp == nil {
718+
t.Errorf("Response is nil after Execute")
719+
}
720+
if resp.Code != 0 {
721+
t.Errorf("Failed to Execute: %d", resp.Code)
722+
}
723+
724+
sqlSelectBind := map[string]interface{}{"name": "test"}
725+
// select data using sql query
726+
resp, err = conn.Execute("SELECT id, name FROM SQL_TEST WHERE name=:name", sqlSelectBind)
727+
if err != nil {
728+
t.Errorf("Failed to Execute: %s", err.Error())
729+
}
730+
if resp == nil {
731+
t.Errorf("Response is nil after Execute")
732+
}
733+
if resp.Data[0] == sqlBind["id"] && resp.Data[1] == sqlBind["name"] {
734+
t.Errorf("Select failed")
735+
}
736+
}
737+
738+
// for internal use
739+
func parseTarantoolVersion(ver string) string {
740+
i := strings.Index(ver, "-")
741+
ver = ver[:i]
742+
return ver
743+
}
744+
745+
func sqlSupported(ver string) bool {
746+
num, _ := strconv.Atoi(string(ver[0]))
747+
return num > 1
694748
}
695749

696750
func TestSchema(t *testing.T) {

0 commit comments

Comments
 (0)