-
Notifications
You must be signed in to change notification settings - Fork 173
/
storage.go
54 lines (43 loc) · 1.51 KB
/
storage.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
package storage
import (
"testing"
)
// DatastoreTestContainer represents a runnable container for testing specific datastore engines.
type DatastoreTestContainer interface {
// GetConnectionURI returns a connection string to the datastore instance running inside
// the container.
GetConnectionURI(includeCredentials bool) string
// GetDatabaseSchemaVersion returns the last migration applied (e.g. 3) when the container was created
GetDatabaseSchemaVersion() int64
GetUsername() string
GetPassword() string
}
type memoryTestContainer struct{}
func (m memoryTestContainer) GetConnectionURI(includeCredentials bool) string {
return ""
}
func (m memoryTestContainer) GetUsername() string {
return ""
}
func (m memoryTestContainer) GetPassword() string {
return ""
}
func (m memoryTestContainer) GetDatabaseSchemaVersion() int64 {
return 1
}
// RunDatastoreTestContainer constructs and runs a specifc DatastoreTestContainer for the provided
// datastore engine. If applicable, it also runs all existing database migrations.
// The resources used by the test engine will be cleaned up after the test has finished.
func RunDatastoreTestContainer(t testing.TB, engine string) DatastoreTestContainer {
switch engine {
case "mysql":
return NewMySQLTestContainer().RunMySQLTestContainer(t)
case "postgres":
return NewPostgresTestContainer().RunPostgresTestContainer(t)
case "memory":
return memoryTestContainer{}
default:
t.Fatalf("'%s' engine is not supported by RunDatastoreTestContainer", engine)
return nil
}
}