forked from rqlite/gorqlite
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwrite_test.go
108 lines (91 loc) · 2.44 KB
/
write_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package gorqlite
import "testing"
// import "os"
func TestWriteOne (t *testing.T) {
var wr WriteResult
var err error
t.Logf("trying Open")
conn, err := Open(testUrl())
if ( err != nil ) {
t.Logf("--> FATAL")
t.Fatal(err)
}
t.Logf("trying WriteOne DROP")
wr, err = conn.WriteOne("DROP TABLE IF EXISTS " + testTableName() + "")
if ( err != nil ) {
t.Logf("--> FAILED")
t.Fail()
}
t.Logf("trying WriteOne CTHULHU (should fail, bad SQL)")
wr, err = conn.WriteOne("CTHULHU")
if ( err == nil ) {
t.Logf("--> FAILED")
t.Fail()
}
t.Logf("trying WriteOne CREATE")
wr, err = conn.WriteOne("CREATE TABLE " + testTableName() + " (id integer, name text)")
if ( err != nil ) {
t.Logf("--> FAILED")
t.Fail()
}
t.Logf("trying WriteOne INSERT")
wr, err = conn.WriteOne("INSERT INTO " + testTableName() + " (id, name) VALUES ( 1, 'aaa bbb ccc' )")
if ( err != nil ) {
t.Logf("--> FAILED")
t.Fail()
}
t.Logf("checking WriteOne RowsAffected")
if ( wr.RowsAffected != 1 ) {
t.Logf("--> FAILED")
t.Fail()
}
t.Logf("trying WriteOne DROP")
wr, err = conn.WriteOne("DROP TABLE IF EXISTS " + testTableName() + "")
if ( err != nil ) {
t.Logf("--> FAILED")
t.Fail()
}
}
func TestWrite (t *testing.T) {
var results []WriteResult
var err error
var s []string
t.Logf("trying Open")
conn, err := Open(testUrl())
if ( err != nil ) {
t.Logf("--> FATAL")
t.Fatal(err)
}
t.Logf("trying Write DROP & CREATE")
s = make([]string,0)
s = append(s, "DROP TABLE IF EXISTS " + testTableName() + "")
s = append(s, "CREATE TABLE " + testTableName() + " (id integer, name text)")
results, err = conn.Write(s)
if ( err != nil ) {
t.Logf("--> FAILED")
t.Fail()
}
t.Logf("trying Write INSERT")
s = make([]string,0)
s = append (s, "INSERT INTO " + testTableName() + " (id, name) VALUES ( 1, 'aaa bbb ccc' )")
s = append (s, "INSERT INTO " + testTableName() + " (id, name) VALUES ( 2, 'ddd eee fff' )")
s = append (s, "INSERT INTO " + testTableName() + " (id, name) VALUES ( 3, 'ggg hhh iii' )")
s = append (s, "INSERT INTO " + testTableName() + " (id, name) VALUES ( 4, 'jjj kkk lll' )")
results, err = conn.Write(s)
if ( err != nil ) {
t.Logf("--> FAILED")
t.Fail()
}
if ( len(results) != 4 ) {
t.Logf("--> FAILED")
t.Fail()
}
t.Logf("trying Write DROP")
s = make([]string,0)
s = append(s, "DROP TABLE IF EXISTS " + testTableName() + "")
results, err = conn.Write(s)
if ( err != nil ) {
t.Logf("--> FAILED")
t.Fail()
}
}