From cdeea1c9991b4c2375f8812bfffefd4435606c27 Mon Sep 17 00:00:00 2001 From: Michal Niewrzal Date: Fri, 4 Dec 2020 12:06:06 +0100 Subject: [PATCH] private/testplanet: add helper OpenProject method to testplanet uplink This will simplify opening pure uplink.Project in tests. Change-Id: I076875e15e21608f49dc875bb445412f34609bdb --- private/testplanet/uplink.go | 10 ++++++++++ private/testplanet/uplink_test.go | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/private/testplanet/uplink.go b/private/testplanet/uplink.go index 5ad85a84b..b35e98d59 100644 --- a/private/testplanet/uplink.go +++ b/private/testplanet/uplink.go @@ -180,6 +180,16 @@ func (client *Uplink) DialPiecestore(ctx context.Context, destination Peer) (*pi return piecestore.DialNodeURL(ctx, client.Dialer, destination.NodeURL(), client.Log.Named("uplink>piecestore"), piecestore.DefaultConfig) } +// OpenProject opens project with predefined access grant and gives access to pure uplink API. +func (client *Uplink) OpenProject(ctx context.Context, satellite *Satellite) (*uplink.Project, error) { + _, found := testuplink.GetMaxSegmentSize(ctx) + if !found { + ctx = testuplink.WithMaxSegmentSize(ctx, satellite.Config.Metainfo.MaxSegmentSize) + } + + return uplink.OpenProject(ctx, client.Access[satellite.ID()]) +} + // Upload data to specific satellite. func (client *Uplink) Upload(ctx context.Context, satellite *Satellite, bucket string, path storj.Path, data []byte) error { return client.UploadWithExpiration(ctx, satellite, bucket, path, data, time.Time{}) diff --git a/private/testplanet/uplink_test.go b/private/testplanet/uplink_test.go index 4f2a36d00..7d1a34f62 100644 --- a/private/testplanet/uplink_test.go +++ b/private/testplanet/uplink_test.go @@ -276,3 +276,16 @@ func TestDeleteWithOfflineStoragenode(t *testing.T) { require.Equal(t, 0, len(objects)) }) } + +func TestUplinkOpenProject(t *testing.T) { + testplanet.Run(t, testplanet.Config{ + SatelliteCount: 1, StorageNodeCount: 0, UplinkCount: 1, + }, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { + project, err := planet.Uplinks[0].OpenProject(ctx, planet.Satellites[0]) + require.NoError(t, err) + defer ctx.Check(project.Close) + + _, err = project.EnsureBucket(ctx, "bucket-name") + require.NoError(t, err) + }) +}