-
Notifications
You must be signed in to change notification settings - Fork 36
/
gorqlite_test.go
61 lines (47 loc) · 1.02 KB
/
gorqlite_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
package gorqlite_test
import (
"log"
"math/rand"
"os"
"testing"
"time"
"github.com/rqlite/gorqlite"
)
var globalConnection *gorqlite.Connection
func TestMain(m *testing.M) {
rand.Seed(time.Now().UnixNano())
conn, err := gorqlite.Open(testUrl())
if err != nil {
log.Fatalf("opening connection: %v", err)
}
err = conn.SetConsistencyLevel(gorqlite.ConsistencyLevelStrong)
if err != nil {
log.Fatalf("setting consistency level: %v", err)
}
globalConnection = conn
exitCode := m.Run()
conn.Close()
os.Exit(exitCode)
}
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
func RandStringBytes(n int) string {
b := make([]byte, n)
for i := range b {
b[i] = letterBytes[rand.Intn(len(letterBytes))]
}
return string(b)
}
func testUrl() string {
url := os.Getenv("GORQLITE_TEST_URL")
if url == "" {
url = "http://"
}
return url
}
func testTableName() string {
tableName := os.Getenv("GORQLITE_TEST_TABLE")
if tableName == "" {
tableName = "gorqlite_test"
}
return tableName
}