-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathlz4_test.go
59 lines (49 loc) · 1.14 KB
/
lz4_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
package imapsql
import (
"io/ioutil"
"log"
"math/rand"
"os"
"path/filepath"
"testing"
backendtests "github.com/foxcpp/go-imap-backend-tests"
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3"
)
func initTestBackendLZ4() backendtests.Backend {
driver := TestDB
dsn := TestDSN
if TestDB == "" {
driver = "sqlite3"
dsn = ":memory:"
}
randSrc := rand.NewSource(0)
prng := rand.New(randSrc)
tempDir, err := ioutil.TempDir("", "go-imap-sql-tests-")
if err != nil {
panic(err)
}
// This is meant for DB debugging.
if os.Getenv("PRESERVE_SQLITE3_DB") == "1" {
log.Println("Using sqlite3 DB in temporary directory.")
driver = "sqlite3"
dsn = filepath.Join(tempDir, "test.db")
}
storeDir := filepath.Join(tempDir, "store")
if err := os.MkdirAll(storeDir, os.ModeDir|os.ModePerm); err != nil {
panic(err)
}
b, err := New(driver, dsn, &FSStore{Root: storeDir}, Opts{
CompressAlgo: "lz4",
PRNG: prng,
Log: DummyLogger{},
})
if err != nil {
panic(err)
}
return b
}
func TestWithLZ4(t *testing.T) {
backendtests.RunTests(t, initTestBackendLZ4, cleanBackend)
}