storj/private/testplanet/run.go
Cameron Ayer 0038abb51b private/testplanet: use redis for live accounting
storing live accounting in memory will not work, as the core and api each create
their own instance. Using redis will allow each to access the same store

Change-Id: I4c8250b579d7b6b6d8991bc890894573626effe6
2020-01-03 21:04:50 +00:00

71 lines
1.9 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information
package testplanet
import (
"testing"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"
"storj.io/common/testcontext"
"storj.io/storj/satellite"
"storj.io/storj/satellite/metainfo"
"storj.io/storj/satellite/satellitedb/satellitedbtest"
"storj.io/storj/storage/redis/redisserver"
)
// Run runs testplanet in multiple configurations.
func Run(t *testing.T, config Config, test func(t *testing.T, ctx *testcontext.Context, planet *Planet)) {
for _, satelliteDB := range satellitedbtest.Databases() {
satelliteDB := satelliteDB
t.Run(satelliteDB.MasterDB.Name, func(t *testing.T) {
t.Parallel()
ctx := testcontext.New(t)
defer ctx.Cleanup()
if satelliteDB.MasterDB.URL == "" {
t.Skipf("Database %s connection string not provided. %s", satelliteDB.MasterDB.Name, satelliteDB.MasterDB.Message)
}
addr, cleanup, err := redisserver.Mini()
if err != nil {
t.Fatal(err)
}
defer cleanup()
planetConfig := config
reconfigSat := planetConfig.Reconfigure.Satellite
planetConfig.Reconfigure.Satellite = func(log *zap.Logger, index int, config *satellite.Config) {
config.LiveAccounting.StorageBackend = "redis://" + addr + "?db=0"
if reconfigSat != nil {
reconfigSat(log, index, config)
}
}
planetConfig.Reconfigure.NewSatelliteDB = func(log *zap.Logger, index int) (satellite.DB, error) {
return satellitedbtest.CreateMasterDB(t, "S", index, satelliteDB.MasterDB)
}
if satelliteDB.PointerDB.URL != "" {
planetConfig.Reconfigure.NewSatellitePointerDB = func(log *zap.Logger, index int) (metainfo.PointerDB, error) {
return satellitedbtest.CreatePointerDB(t, "P", index, satelliteDB.PointerDB)
}
}
planet, err := NewCustom(zaptest.NewLogger(t), planetConfig)
if err != nil {
t.Fatal(err)
}
defer ctx.Check(planet.Shutdown)
planet.Start(ctx)
test(t, ctx, planet)
})
}
}