-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsql_test.go
91 lines (75 loc) · 1.93 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
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
package cachita
import (
"database/sql"
"os"
"testing"
"time"
_ "github.com/lib/pq"
"github.com/stretchr/testify/assert"
)
func TestNewSqlCache(t *testing.T) {
newCache(sc(t), t)
}
func TestSqlCacheExpires(t *testing.T) {
t.Parallel()
sqlDriver, err := sql.Open("postgres", "postgres://postgres@localhost/test?sslmode=disable")
isError(err, t)
c, err := NewSqlCache(2*time.Minute, time.Second, sqlDriver, "cachita_cache", true)
isError(err, t)
cacheExpires(c, t, time.Second, 1200*time.Millisecond)
}
func TestSqlCacheWithInt(t *testing.T) {
t.Parallel()
cacheWithInt(sc(t), t)
}
func BenchmarkSqlCacheWithInt(b *testing.B) {
benchmarkCacheWithInt(sc(b), b)
}
func TestSqlCacheWithString(t *testing.T) {
t.Parallel()
cacheWithString(sc(t), t)
}
func BenchmarkSqlCacheWithString(b *testing.B) {
benchmarkCacheWithString(sc(b), b)
}
func TestSqlCacheWithMapInterface(t *testing.T) {
t.Parallel()
cacheWithMapInterface(sc(t), t)
}
func BenchmarkSqlCacheWithMapInterface(b *testing.B) {
benchmarkCacheWithMapInterface(sc(b), b)
}
func TestSqlCacheWithStruct(t *testing.T) {
t.Parallel()
cacheWithStruct(sc(t), t)
}
func BenchmarkSqlCacheWithStruct(b *testing.B) {
benchmarkCacheWithStruct(sc(b), b)
}
func TestSql_Incr(t *testing.T) {
t.Parallel()
cacheIncr(sc(t), t)
}
func BenchmarkSql_Incr(b *testing.B) {
benchmarkCacheIncr(sc(b), b)
}
func sc(t assert.TestingT) (c Cache) {
h := "localhost"
if os.Getenv("POSTGRES_HOST") != "" {
h = os.Getenv("POSTGRES_HOST")
}
p := "5432"
if os.Getenv("POSTGRES_PORT") != "" {
h = os.Getenv("POSTGRES_PORT")
}
c, err := Sql("postgres", "postgres://postgres@"+h+":"+p+"/test?sslmode=disable")
isError(err, t)
return
}
func TestSql_Tag(t *testing.T) {
t.Parallel()
cacheTag(sc(t), t)
}
func BenchmarkSql_Tag(b *testing.B) {
benchmarkCacheTag(sc(b), b)
}