forked from fergusstrange/embedded-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_util_test.go
81 lines (66 loc) · 1.75 KB
/
test_util_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
package embeddedpostgres
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/mholt/archiver/v3"
)
func createTempXzArchive() (string, func()) {
tempDir, err := ioutil.TempDir("", "remote_fetch_test")
if err != nil {
panic(err)
}
tempFile, err := ioutil.TempFile(tempDir, "remote_fetch_test")
if err != nil {
panic(err)
}
tarFile := filepath.Join(tempDir, "remote_fetch_test.txz")
if err := archiver.NewTarXz().Archive([]string{tempFile.Name()}, tarFile); err != nil {
panic(err)
}
return tarFile, func() {
if err := os.RemoveAll(tempDir); err != nil {
panic(err)
}
}
}
func createTempZipArchive() (string, func()) {
tempDir, err := ioutil.TempDir("", "remote_fetch_test")
if err != nil {
panic(err)
}
tempFile, err := ioutil.TempFile(tempDir, "remote_fetch_test")
if err != nil {
panic(err)
}
tarFile := filepath.Join(tempDir, "remote_fetch_test.txz")
if err := archiver.NewTarXz().Archive([]string{tempFile.Name()}, tarFile); err != nil {
panic(err)
}
jarFile := filepath.Join(tempDir, "remote_fetch_test.zip")
if err := archiver.NewZip().Archive([]string{tempFile.Name(), tarFile}, jarFile); err != nil {
panic(err)
}
return jarFile, func() {
if err := os.RemoveAll(tempDir); err != nil {
panic(err)
}
}
}
func shutdownDBAndFail(t *testing.T, err error, db *EmbeddedPostgres) {
if err := db.Stop(); err != nil {
t.Fatalf("Failed for version %s with error %s", db.config.version, err)
}
t.Fatalf("Failed for version %s with error %s", db.config.version, err)
}
func testVersionStrategy() VersionStrategy {
return func() (string, string, PostgresVersion) {
return "darwin", "amd64", "1.2.3"
}
}
func testCacheLocator() CacheLocator {
return func() (s string, b bool) {
return "", false
}
}