/
main.go
62 lines (55 loc) · 1.4 KB
/
main.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
// Package db provides helpers to connect to test databases. It has no
// internal dependencies on horizon and so should be able to be imported by
// any horizon package.
package db
import (
"fmt"
"log"
"testing"
"github.com/jmoiron/sqlx"
// pq enables postgres support
_ "github.com/lib/pq"
db "github.com/stellar/go/support/db/dbtest"
)
var (
coreDB *sqlx.DB
coreUrl *string
horizonDB *sqlx.DB
horizonUrl *string
)
// Horizon returns a connection to the horizon test database
func Horizon(t *testing.T) *sqlx.DB {
if horizonDB != nil {
return horizonDB
}
postgres := db.Postgres(t)
horizonUrl = &postgres.DSN
horizonDB = postgres.Open()
return horizonDB
}
// HorizonURL returns the database connection the url any test
// use when connecting to the history/horizon database
func HorizonURL() string {
if horizonUrl == nil {
log.Panic(fmt.Errorf("Horizon not initialized"))
}
return *horizonUrl
}
// StellarCore returns a connection to the stellar core test database
func StellarCore(t *testing.T) *sqlx.DB {
if coreDB != nil {
return coreDB
}
postgres := db.Postgres(t)
coreUrl = &postgres.DSN
coreDB = postgres.Open()
return coreDB
}
// StellarCoreURL returns the database connection the url any test
// use when connecting to the stellar-core database
func StellarCoreURL() string {
if coreUrl == nil {
log.Panic(fmt.Errorf("StellarCore not initialized"))
}
return *coreUrl
}