-
Notifications
You must be signed in to change notification settings - Fork 394
/
run.go
87 lines (70 loc) · 2.14 KB
/
run.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
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information
package testplanet
import (
"strconv"
"strings"
"testing"
"github.com/zeebo/errs"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"
"storj.io/storj/internal/dbutil/pgutil"
"storj.io/storj/internal/testcontext"
"storj.io/storj/satellite"
"storj.io/storj/satellite/satellitedb"
"storj.io/storj/satellite/satellitedb/satellitedbtest"
)
// Run runs testplanet in multiple configurations.
func Run(t *testing.T, config Config, test func(t *testing.T, ctx *testcontext.Context, planet *Planet)) {
schemaSuffix := pgutil.CreateRandomTestingSchemaName(8)
t.Log("schema-suffix ", schemaSuffix)
for _, satelliteDB := range satellitedbtest.Databases() {
satelliteDB := satelliteDB
t.Run(satelliteDB.Name, func(t *testing.T) {
t.Parallel()
ctx := testcontext.New(t)
defer ctx.Cleanup()
if satelliteDB.URL == "" {
t.Skipf("Database %s connection string not provided. %s", satelliteDB.Name, satelliteDB.Message)
}
planetConfig := config
planetConfig.Reconfigure.NewBootstrapDB = nil
planetConfig.Reconfigure.NewSatelliteDB = func(log *zap.Logger, index int) (satellite.DB, error) {
schema := strings.ToLower(t.Name() + "-satellite/" + strconv.Itoa(index) + "-" + schemaSuffix)
db, err := satellitedb.New(log, pgutil.ConnstrWithSchema(satelliteDB.URL, schema))
if err != nil {
t.Fatal(err)
}
err = db.CreateSchema(schema)
if err != nil {
t.Fatal(err)
}
return &satelliteSchema{
DB: db,
schema: schema,
}, nil
}
planetConfig.Reconfigure.NewStorageNodeDB = nil
planet, err := NewCustom(zaptest.NewLogger(t), planetConfig)
if err != nil {
t.Fatal(err)
}
defer ctx.Check(planet.Shutdown)
planet.Start(ctx)
// make sure nodes are refreshed in db
planet.Satellites[0].Discovery.Service.Refresh.TriggerWait()
test(t, ctx, planet)
})
}
}
// satelliteSchema closes database and drops the associated schema
type satelliteSchema struct {
satellite.DB
schema string
}
func (db *satelliteSchema) Close() error {
return errs.Combine(
db.DB.DropSchema(db.schema),
db.DB.Close(),
)
}