2019-02-04 20:37:46 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information
|
|
|
|
|
|
|
|
package testplanet
|
|
|
|
|
|
|
|
import (
|
2020-05-26 09:05:43 +01:00
|
|
|
"context"
|
2020-10-29 11:58:36 +00:00
|
|
|
"runtime/pprof"
|
2019-02-04 20:37:46 +00:00
|
|
|
"testing"
|
|
|
|
|
2022-05-10 12:40:54 +01:00
|
|
|
"storj.io/common/grant"
|
|
|
|
"storj.io/common/storj"
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/testcontext"
|
2021-04-23 10:52:40 +01:00
|
|
|
"storj.io/private/dbutil/pgtest"
|
2021-10-11 17:29:03 +01:00
|
|
|
"storj.io/storj/private/testmonkit"
|
2019-02-04 20:37:46 +00:00
|
|
|
"storj.io/storj/satellite/satellitedb/satellitedbtest"
|
2020-05-26 09:05:43 +01:00
|
|
|
"storj.io/uplink"
|
2019-02-04 20:37:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Run runs testplanet in multiple configurations.
|
|
|
|
func Run(t *testing.T, config Config, test func(t *testing.T, ctx *testcontext.Context, planet *Planet)) {
|
2020-04-27 20:34:42 +01:00
|
|
|
databases := satellitedbtest.Databases()
|
2021-05-11 11:08:06 +01:00
|
|
|
if len(databases) == 0 {
|
2020-04-27 20:34:42 +01:00
|
|
|
t.Fatal("Databases flag missing, set at least one:\n" +
|
|
|
|
"-postgres-test-db=" + pgtest.DefaultPostgres + "\n" +
|
|
|
|
"-cockroach-test-db=" + pgtest.DefaultCockroach)
|
|
|
|
}
|
|
|
|
|
2021-05-11 11:08:06 +01:00
|
|
|
for _, satelliteDB := range databases {
|
2019-02-06 09:16:05 +00:00
|
|
|
satelliteDB := satelliteDB
|
2020-04-27 17:28:40 +01:00
|
|
|
t.Run(satelliteDB.Name, func(t *testing.T) {
|
2020-02-27 13:31:05 +00:00
|
|
|
parallel := !config.NonParallel
|
|
|
|
if parallel {
|
|
|
|
t.Parallel()
|
|
|
|
}
|
2019-02-05 19:44:00 +00:00
|
|
|
|
2019-10-04 15:12:21 +01:00
|
|
|
if satelliteDB.MasterDB.URL == "" {
|
|
|
|
t.Skipf("Database %s connection string not provided. %s", satelliteDB.MasterDB.Name, satelliteDB.MasterDB.Message)
|
2019-02-04 20:37:46 +00:00
|
|
|
}
|
|
|
|
planetConfig := config
|
2020-03-27 16:18:19 +00:00
|
|
|
if planetConfig.Name == "" {
|
|
|
|
planetConfig.Name = t.Name()
|
2019-10-04 15:12:21 +01:00
|
|
|
}
|
|
|
|
|
2022-01-27 11:56:27 +00:00
|
|
|
log := NewLogger(t)
|
2021-09-29 08:06:51 +01:00
|
|
|
|
2021-10-11 17:29:03 +01:00
|
|
|
testmonkit.Run(context.Background(), t, func(parent context.Context) {
|
2021-10-20 14:42:41 +01:00
|
|
|
defer pprof.SetGoroutineLabels(parent)
|
|
|
|
parent = pprof.WithLabels(parent, pprof.Labels("test", t.Name()))
|
|
|
|
|
2022-04-11 12:16:47 +01:00
|
|
|
timeout := config.Timeout
|
|
|
|
if timeout == 0 {
|
|
|
|
timeout = testcontext.DefaultTimeout
|
|
|
|
}
|
|
|
|
ctx := testcontext.NewWithContextAndTimeout(parent, t, timeout)
|
2021-09-29 08:06:51 +01:00
|
|
|
defer ctx.Cleanup()
|
|
|
|
|
2021-10-20 14:42:41 +01:00
|
|
|
planet, err := NewCustom(ctx, log, planetConfig, satelliteDB)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%+v", err)
|
|
|
|
}
|
|
|
|
defer ctx.Check(planet.Shutdown)
|
2021-09-29 08:06:51 +01:00
|
|
|
|
2021-10-20 14:42:41 +01:00
|
|
|
planet.Start(ctx)
|
|
|
|
provisionUplinks(ctx, t, planet)
|
2021-09-29 08:06:51 +01:00
|
|
|
|
2021-10-20 14:42:41 +01:00
|
|
|
test(t, ctx, planet)
|
2021-10-11 17:29:03 +01:00
|
|
|
})
|
2019-02-04 20:37:46 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2020-05-26 09:05:43 +01:00
|
|
|
|
|
|
|
func provisionUplinks(ctx context.Context, t *testing.T, planet *Planet) {
|
|
|
|
for _, planetUplink := range planet.Uplinks {
|
|
|
|
for _, satellite := range planet.Satellites {
|
|
|
|
apiKey := planetUplink.APIKey[satellite.ID()]
|
2022-05-10 12:40:54 +01:00
|
|
|
|
|
|
|
// create access grant manually to avoid dialing satellite for
|
|
|
|
// project id and deriving key with argon2.IDKey method
|
|
|
|
encAccess := grant.NewEncryptionAccessWithDefaultKey(&storj.Key{})
|
|
|
|
encAccess.SetDefaultPathCipher(storj.EncAESGCM)
|
|
|
|
|
|
|
|
grantAccess := grant.Access{
|
|
|
|
SatelliteAddress: satellite.URL(),
|
|
|
|
APIKey: apiKey,
|
|
|
|
EncAccess: encAccess,
|
|
|
|
}
|
|
|
|
|
|
|
|
serializedAccess, err := grantAccess.Serialize()
|
2020-05-26 09:05:43 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%+v", err)
|
|
|
|
}
|
2022-05-10 12:40:54 +01:00
|
|
|
access, err := uplink.ParseAccess(serializedAccess)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%+v", err)
|
|
|
|
}
|
|
|
|
|
2020-05-26 09:05:43 +01:00
|
|
|
planetUplink.Access[satellite.ID()] = access
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|