-
Notifications
You must be signed in to change notification settings - Fork 3
/
sql_test.go
53 lines (43 loc) · 1.13 KB
/
sql_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
package distlock
import (
"database/sql"
"testing"
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
)
const TestTableName = "ggicci_distlock_test"
func cleanupMySQL(db *sql.DB) {
_, _ = db.Exec(formatSQL("DROP TABLE IF EXISTS %s", TestTableName))
}
func cleanupPostgreSQL(db *sql.DB) {
_, _ = db.Exec(formatSQL("DROP TABLE IF EXISTS %s", TestTableName))
}
func TestMySQLProvider(t *testing.T) {
db, err := sql.Open("mysql", "root@tcp(localhost:3306)/test")
if err != nil {
t.Fatal(err)
}
cleanupMySQL(db)
provider, err := NewMySQLProvider(db, TestTableName)
if err != nil {
t.Fatalf("could not create provider: %s", err)
}
runLockTestsWithoutLifetime(t, provider)
runLockTestsWithLifetime(t, provider)
}
func TestPostgreSQLProvider(t *testing.T) {
db, err := sql.Open(
"postgres",
"user=root host=127.0.0.1 port=5432 dbname=test sslmode=disable",
)
if err != nil {
t.Fatal(err)
}
cleanupPostgreSQL(db)
provider, err := NewPostgreSQLProvider(db, TestTableName)
if err != nil {
t.Fatalf("could not create provider: %s", err)
}
runLockTestsWithoutLifetime(t, provider)
runLockTestsWithLifetime(t, provider)
}