satellite: simplify tests

satellite.DB.Console().Projects().GetAll database query
can be replaced with planet.Uplinks[0].Projects[0].ID

Change-Id: I73b82b91afb2dde7b690917345b798f9d81f6831
This commit is contained in:
Egon Elbre 2020-08-28 18:55:59 +03:00 committed by Yingrong Zhao
parent 4645805b18
commit c86c732fc0
7 changed files with 31 additions and 88 deletions

View File

@ -122,11 +122,7 @@ func TestDisqualifiedNodesGetNoDownload(t *testing.T) {
err := uplinkPeer.Upload(ctx, satellitePeer, "testbucket", "test/path", testData)
require.NoError(t, err)
projects, err := satellitePeer.DB.Console().Projects().GetAll(ctx)
require.NoError(t, err)
require.Len(t, projects, 1)
bucket := metabase.BucketLocation{ProjectID: projects[0].ID, BucketName: "testbucket"}
bucket := metabase.BucketLocation{ProjectID: uplinkPeer.Projects[0].ID, BucketName: "testbucket"}
items, _, err := satellitePeer.Metainfo.Service.List(ctx, "", "", true, 10, meta.All)
require.NoError(t, err)

View File

@ -67,10 +67,7 @@ func TestReverifySuccess(t *testing.T) {
orders := satellite.Orders.Service
containment := satellite.DB.Containment()
projects, err := satellite.DB.Console().Projects().GetAll(ctx)
require.NoError(t, err)
bucket := metabase.BucketLocation{ProjectID: projects[0].ID, BucketName: "testbucket"}
bucket := metabase.BucketLocation{ProjectID: ul.Projects[0].ID, BucketName: "testbucket"}
shareSize := pointer.GetRemote().GetRedundancy().GetErasureShareSize()
pieces := pointer.GetRemote().GetRemotePieces()
@ -151,10 +148,7 @@ func TestReverifyFailMissingShare(t *testing.T) {
orders := satellite.Orders.Service
containment := satellite.DB.Containment()
projects, err := satellite.DB.Console().Projects().GetAll(ctx)
require.NoError(t, err)
bucket := metabase.BucketLocation{ProjectID: projects[0].ID, BucketName: "testbucket"}
bucket := metabase.BucketLocation{ProjectID: ul.Projects[0].ID, BucketName: "testbucket"}
shareSize := pointer.GetRemote().GetRedundancy().GetErasureShareSize()
pieces := pointer.GetRemote().GetRemotePieces()
@ -237,10 +231,7 @@ func TestReverifyFailMissingShareNotVerified(t *testing.T) {
orders := satellite.Orders.Service
containment := satellite.DB.Containment()
projects, err := satellite.DB.Console().Projects().GetAll(ctx)
require.NoError(t, err)
bucket := metabase.BucketLocation{ProjectID: projects[0].ID, BucketName: "testbucket"}
bucket := metabase.BucketLocation{ProjectID: ul.Projects[0].ID, BucketName: "testbucket"}
shareSize := pointer.GetRemote().GetRedundancy().GetErasureShareSize()
pieces := pointer.GetRemote().GetRemotePieces()
@ -857,10 +848,7 @@ func TestReverifyDifferentShare(t *testing.T) {
orders := satellite.Orders.Service
containment := satellite.DB.Containment()
projects, err := satellite.DB.Console().Projects().GetAll(ctx)
require.NoError(t, err)
bucket := metabase.BucketLocation{ProjectID: projects[0].ID, BucketName: "testbucket"}
bucket := metabase.BucketLocation{ProjectID: ul.Projects[0].ID, BucketName: "testbucket"}
shareSize := pointer1.GetRemote().GetRedundancy().GetErasureShareSize()
rootPieceID := pointer1.GetRemote().RootPieceId
@ -1025,10 +1013,7 @@ func TestReverifyExpired2(t *testing.T) {
orders := satellite.Orders.Service
containment := satellite.DB.Containment()
projects, err := satellite.DB.Console().Projects().GetAll(ctx)
require.NoError(t, err)
bucket := metabase.BucketLocation{ProjectID: projects[0].ID, BucketName: "testbucket"}
bucket := metabase.BucketLocation{ProjectID: ul.Projects[0].ID, BucketName: "testbucket"}
shareSize := pointer1.GetRemote().GetRedundancy().GetErasureShareSize()
rootPieceID := pointer1.GetRemote().RootPieceId
@ -1135,10 +1120,7 @@ func TestReverifySlowDownload(t *testing.T) {
orders := satellite.Orders.Service
containment := satellite.DB.Containment()
projects, err := satellite.DB.Console().Projects().GetAll(ctx)
require.NoError(t, err)
bucket := metabase.BucketLocation{ProjectID: projects[0].ID, BucketName: "testbucket"}
bucket := metabase.BucketLocation{ProjectID: ul.Projects[0].ID, BucketName: "testbucket"}
shareSize := pointer.GetRemote().GetRedundancy().GetErasureShareSize()
pieces := pointer.GetRemote().GetRemotePieces()
@ -1222,10 +1204,7 @@ func TestReverifyUnknownError(t *testing.T) {
orders := satellite.Orders.Service
containment := satellite.DB.Containment()
projects, err := satellite.DB.Console().Projects().GetAll(ctx)
require.NoError(t, err)
bucket := metabase.BucketLocation{ProjectID: projects[0].ID, BucketName: "testbucket"}
bucket := metabase.BucketLocation{ProjectID: ul.Projects[0].ID, BucketName: "testbucket"}
shareSize := pointer.GetRemote().GetRedundancy().GetErasureShareSize()
pieces := pointer.GetRemote().GetRemotePieces()

View File

@ -51,10 +51,7 @@ func TestDownloadSharesHappyPath(t *testing.T) {
err := uplink.Upload(ctx, satellite, "testbucket", "test/path", testData)
require.NoError(t, err)
projects, err := satellite.DB.Console().Projects().GetAll(ctx)
require.NoError(t, err)
bucket := metabase.BucketLocation{ProjectID: projects[0].ID, BucketName: "testbucket"}
bucket := metabase.BucketLocation{ProjectID: uplink.Projects[0].ID, BucketName: "testbucket"}
audits.Chore.Loop.TriggerWait()
path, err := queue.Next()
@ -105,10 +102,7 @@ func TestDownloadSharesOfflineNode(t *testing.T) {
err := uplink.Upload(ctx, satellite, "testbucket", "test/path", testData)
require.NoError(t, err)
projects, err := satellite.DB.Console().Projects().GetAll(ctx)
require.NoError(t, err)
bucket := metabase.BucketLocation{ProjectID: projects[0].ID, BucketName: "testbucket"}
bucket := metabase.BucketLocation{ProjectID: uplink.Projects[0].ID, BucketName: "testbucket"}
audits.Chore.Loop.TriggerWait()
path, err := queue.Next()
@ -177,10 +171,7 @@ func TestDownloadSharesMissingPiece(t *testing.T) {
randomIndex, err := audit.GetRandomStripe(ctx, pointer)
require.NoError(t, err)
projects, err := satellite.DB.Console().Projects().GetAll(ctx)
require.NoError(t, err)
bucket := metabase.BucketLocation{ProjectID: projects[0].ID, BucketName: "testbucket"}
bucket := metabase.BucketLocation{ProjectID: uplink.Projects[0].ID, BucketName: "testbucket"}
// replace the piece id of the selected stripe with a new random one
// to simulate missing piece on the storage nodes
@ -235,10 +226,7 @@ func TestDownloadSharesDialTimeout(t *testing.T) {
randomIndex, err := audit.GetRandomStripe(ctx, pointer)
require.NoError(t, err)
projects, err := satellite.DB.Console().Projects().GetAll(ctx)
require.NoError(t, err)
bucket := metabase.BucketLocation{ProjectID: projects[0].ID, BucketName: "testbucket"}
bucket := metabase.BucketLocation{ProjectID: upl.Projects[0].ID, BucketName: "testbucket"}
tlsOptions, err := tlsopts.NewOptions(satellite.Identity, tlsopts.Config{}, nil)
require.NoError(t, err)
@ -309,10 +297,7 @@ func TestDownloadSharesDownloadTimeout(t *testing.T) {
err := upl.Upload(ctx, satellite, "testbucket", "test/path", testData)
require.NoError(t, err)
projects, err := satellite.DB.Console().Projects().GetAll(ctx)
require.NoError(t, err)
bucket := metabase.BucketLocation{ProjectID: projects[0].ID, BucketName: "testbucket"}
bucket := metabase.BucketLocation{ProjectID: upl.Projects[0].ID, BucketName: "testbucket"}
audits.Chore.Loop.TriggerWait()
path, err := queue.Next()

View File

@ -21,6 +21,7 @@ import (
"storj.io/common/testrand"
"storj.io/storj/private/testplanet"
"storj.io/storj/satellite"
"storj.io/storj/satellite/metainfo/metabase"
"storj.io/storj/storage"
"storj.io/storj/storagenode"
)
@ -124,10 +125,6 @@ func TestGarbageCollection(t *testing.T) {
}
func getPointer(ctx *testcontext.Context, t *testing.T, satellite *testplanet.Satellite, upl *testplanet.Uplink, bucket, path string) (lastSegPath string, pointer *pb.Pointer) {
projects, err := satellite.DB.Console().Projects().GetAll(ctx)
require.NoError(t, err)
require.Len(t, projects, 1)
access := upl.Access[satellite.ID()]
serializedAccess, err := access.Serialize()
@ -139,7 +136,14 @@ func getPointer(ctx *testcontext.Context, t *testing.T, satellite *testplanet.Sa
encryptedPath, err := encryption.EncryptPathWithStoreCipher(bucket, paths.NewUnencrypted(path), store)
require.NoError(t, err)
lastSegPath = storj.JoinPaths(projects[0].ID.String(), "l", bucket, encryptedPath.Raw())
segmentLocation := metabase.SegmentLocation{
ProjectID: upl.Projects[0].ID,
BucketName: bucket,
Index: metabase.LastSegmentIndex,
ObjectKey: metabase.ObjectKey(encryptedPath.Raw()),
}
lastSegPath = string(segmentLocation.Encode())
pointer, err = satellite.Metainfo.Service.Get(ctx, lastSegPath)
require.NoError(t, err)

View File

@ -623,15 +623,11 @@ func TestBeginCommitListSegment(t *testing.T) {
apiKey := planet.Uplinks[0].APIKey[planet.Satellites[0].ID()]
metainfoService := planet.Satellites[0].Metainfo.Service
projects, err := planet.Satellites[0].DB.Console().Projects().GetAll(ctx)
require.NoError(t, err)
projectID := projects[0].ID
bucket := storj.Bucket{
Name: "initial-bucket",
ProjectID: projectID,
ProjectID: planet.Uplinks[0].Projects[0].ID,
}
_, err = metainfoService.CreateBucket(ctx, bucket)
_, err := metainfoService.CreateBucket(ctx, bucket)
require.NoError(t, err)
metainfoClient, err := planet.Uplinks[0].DialMetainfo(ctx, planet.Satellites[0], apiKey)
@ -805,10 +801,6 @@ func TestInlineSegment(t *testing.T) {
metainfoService := planet.Satellites[0].Metainfo.Service
projects, err := planet.Satellites[0].DB.Console().Projects().GetAll(ctx)
require.NoError(t, err)
projectID := projects[0].ID
// TODO maybe split into separate cases
// Test:
// * create bucket
@ -822,9 +814,9 @@ func TestInlineSegment(t *testing.T) {
bucket := storj.Bucket{
Name: "inline-segments-bucket",
ProjectID: projectID,
ProjectID: planet.Uplinks[0].Projects[0].ID,
}
_, err = metainfoService.CreateBucket(ctx, bucket)
_, err := metainfoService.CreateBucket(ctx, bucket)
require.NoError(t, err)
metainfoClient, err := planet.Uplinks[0].DialMetainfo(ctx, planet.Satellites[0], apiKey)
@ -1597,15 +1589,11 @@ func TestCommitObjectMetadataSize(t *testing.T) {
apiKey := planet.Uplinks[0].APIKey[planet.Satellites[0].ID()]
metainfoService := planet.Satellites[0].Metainfo.Service
projects, err := planet.Satellites[0].DB.Console().Projects().GetAll(ctx)
require.NoError(t, err)
projectID := projects[0].ID
bucket := storj.Bucket{
Name: "initial-bucket",
ProjectID: projectID,
ProjectID: planet.Uplinks[0].Projects[0].ID,
}
_, err = metainfoService.CreateBucket(ctx, bucket)
_, err := metainfoService.CreateBucket(ctx, bucket)
require.NoError(t, err)
metainfoClient, err := planet.Uplinks[0].DialMetainfo(ctx, planet.Satellites[0], apiKey)

View File

@ -188,12 +188,9 @@ func TestUploadDownloadBandwidth(t *testing.T) {
reportedRollupChore := planet.Satellites[0].Core.Accounting.ReportedRollupChore
require.NoError(t, reportedRollupChore.RunOnce(ctx, now))
projects, err := planet.Satellites[0].DB.Console().Projects().GetAll(ctx)
require.NoError(t, err)
ordersDB := planet.Satellites[0].DB.Orders()
bucketBandwidth, err := ordersDB.GetBucketBandwidth(ctx, projects[0].ID, []byte(bucketName), beforeRollup, afterRollup)
bucketBandwidth, err := ordersDB.GetBucketBandwidth(ctx, planet.Uplinks[0].Projects[0].ID, []byte(bucketName), beforeRollup, afterRollup)
require.NoError(t, err)
require.Equal(t, expectedBucketBandwidth, bucketBandwidth)

View File

@ -33,12 +33,9 @@ func TestOrderDBSettle(t *testing.T) {
service.Sender.Pause()
service.Cleanup.Pause()
projects, err := satellite.DB.Console().Projects().GetAll(ctx)
require.NoError(t, err)
_, orderLimits, piecePrivateKey, err := satellite.Orders.Service.CreatePutOrderLimits(
ctx,
metabase.BucketLocation{ProjectID: projects[0].ID, BucketName: "testbucket"},
metabase.BucketLocation{ProjectID: planet.Uplinks[0].Projects[0].ID, BucketName: "testbucket"},
[]*overlay.SelectedNode{
{ID: node.ID(), LastIPPort: "fake", Address: new(pb.NodeAddress)},
},
@ -134,12 +131,9 @@ func TestOrderFileStoreAndDBSettle(t *testing.T) {
tomorrow := time.Now().Add(24 * time.Hour)
// add orders to orders DB
projects, err := satellite.DB.Console().Projects().GetAll(ctx)
require.NoError(t, err)
_, orderLimits, piecePrivateKey, err := satellite.Orders.Service.CreatePutOrderLimits(
ctx,
metabase.BucketLocation{ProjectID: projects[0].ID, BucketName: "testbucket"},
metabase.BucketLocation{ProjectID: uplinkPeer.Projects[0].ID, BucketName: "testbucket"},
[]*overlay.SelectedNode{
{ID: node.ID(), LastIPPort: "fake", Address: new(pb.NodeAddress)},
},