|
4 | 4 | "fmt"
|
5 | 5 | "log"
|
6 | 6 | "os"
|
| 7 | + "strconv" |
7 | 8 | "strings"
|
8 | 9 | "sync"
|
9 | 10 | "testing"
|
@@ -691,6 +692,59 @@ func TestClient(t *testing.T) {
|
691 | 692 | if val != 11 {
|
692 | 693 | t.Errorf("5 + 6 == 11, but got %v", val)
|
693 | 694 | }
|
| 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 |
694 | 748 | }
|
695 | 749 |
|
696 | 750 | func TestSchema(t *testing.T) {
|
|
0 commit comments