2019-07-12 13:57:02 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package uplink_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2019-08-01 12:14:09 +01:00
|
|
|
"go.uber.org/zap/zaptest"
|
2019-07-12 13:57:02 +01:00
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/storj"
|
|
|
|
"storj.io/common/testcontext"
|
2019-07-12 13:57:02 +01:00
|
|
|
"storj.io/storj/lib/uplink"
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/testplanet"
|
2019-07-12 13:57:02 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestProjectListBuckets(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1,
|
|
|
|
StorageNodeCount: 1,
|
|
|
|
UplinkCount: 1},
|
|
|
|
func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
cfg := uplink.Config{}
|
2019-08-01 12:14:09 +01:00
|
|
|
cfg.Volatile.Log = zaptest.NewLogger(t)
|
2019-07-12 13:57:02 +01:00
|
|
|
cfg.Volatile.TLS.SkipPeerCAWhitelist = true
|
|
|
|
|
2020-01-09 12:24:49 +00:00
|
|
|
access, err := planet.Uplinks[0].GetConfig(planet.Satellites[0]).GetAccess()
|
2019-08-05 18:01:20 +01:00
|
|
|
require.NoError(t, err)
|
2019-07-12 13:57:02 +01:00
|
|
|
|
|
|
|
ul, err := uplink.NewUplink(ctx, &cfg)
|
|
|
|
require.NoError(t, err)
|
2019-07-19 18:24:49 +01:00
|
|
|
defer ctx.Check(ul.Close)
|
2019-07-12 13:57:02 +01:00
|
|
|
|
2020-01-09 12:24:49 +00:00
|
|
|
p, err := ul.OpenProject(ctx, access.SatelliteAddr, access.APIKey)
|
2019-07-12 13:57:02 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// create 6 test buckets
|
|
|
|
for i := 0; i < 6; i++ {
|
|
|
|
_, err = p.CreateBucket(ctx, "test"+strconv.Itoa(i), nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// setup list options so that we only list 3 buckets
|
|
|
|
// at a time in alphabetical order starting at ""
|
|
|
|
list := uplink.BucketListOptions{
|
|
|
|
Direction: storj.Forward,
|
|
|
|
Limit: 3,
|
|
|
|
}
|
|
|
|
|
|
|
|
result, err := p.ListBuckets(ctx, &list)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 3, len(result.Items))
|
|
|
|
require.Equal(t, "test0", result.Items[0].Name)
|
|
|
|
require.Equal(t, "test1", result.Items[1].Name)
|
|
|
|
require.Equal(t, "test2", result.Items[2].Name)
|
|
|
|
require.True(t, result.More)
|
|
|
|
|
|
|
|
list = list.NextPage(result)
|
|
|
|
result, err = p.ListBuckets(ctx, &list)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 3, len(result.Items))
|
|
|
|
require.Equal(t, "test3", result.Items[0].Name)
|
|
|
|
require.Equal(t, "test4", result.Items[1].Name)
|
|
|
|
require.Equal(t, "test5", result.Items[2].Name)
|
|
|
|
require.False(t, result.More)
|
|
|
|
|
|
|
|
// List with restrictions
|
2020-01-09 12:24:49 +00:00
|
|
|
access.APIKey, access.EncryptionAccess, err =
|
|
|
|
access.EncryptionAccess.Restrict(access.APIKey,
|
2019-11-14 08:31:30 +00:00
|
|
|
uplink.EncryptionRestriction{Bucket: "test0"},
|
|
|
|
uplink.EncryptionRestriction{Bucket: "test1"})
|
2019-07-12 13:57:02 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-01-09 12:24:49 +00:00
|
|
|
p, err = ul.OpenProject(ctx, access.SatelliteAddr, access.APIKey)
|
2019-07-12 13:57:02 +01:00
|
|
|
require.NoError(t, err)
|
2019-07-19 18:24:49 +01:00
|
|
|
defer ctx.Check(p.Close)
|
2019-07-12 13:57:02 +01:00
|
|
|
|
|
|
|
list = uplink.BucketListOptions{
|
|
|
|
Direction: storj.Forward,
|
|
|
|
Limit: 3,
|
|
|
|
}
|
|
|
|
result, err = p.ListBuckets(ctx, &list)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 2, len(result.Items))
|
|
|
|
require.Equal(t, "test0", result.Items[0].Name)
|
|
|
|
require.Equal(t, "test1", result.Items[1].Name)
|
|
|
|
require.False(t, result.More)
|
|
|
|
})
|
|
|
|
}
|