From 821a077f7c9dce5f99077b9ed28bdfe96b161301 Mon Sep 17 00:00:00 2001 From: Ivan Fraixedes Date: Fri, 1 Oct 2021 14:14:45 +0200 Subject: [PATCH] satellite/{admin,console}: Move tests Move tests which where related with the `admin` package to the `console` one because it's where the interface for the methods that the tests check is defined. Change-Id: I1bbccfe0badd989ed146a260af8d207d47737ef1 --- satellite/admin/project_test.go | 74 ---------------------------- satellite/console/projects_test.go | 79 +++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 76 deletions(-) diff --git a/satellite/admin/project_test.go b/satellite/admin/project_test.go index 188cc9803..0b9143c34 100644 --- a/satellite/admin/project_test.go +++ b/satellite/admin/project_test.go @@ -16,11 +16,9 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/zap" - "storj.io/common/errs2" "storj.io/common/macaroon" "storj.io/common/storj" "storj.io/common/testcontext" - "storj.io/common/testrand" "storj.io/common/uuid" "storj.io/storj/private/testplanet" "storj.io/storj/satellite" @@ -568,75 +566,3 @@ func TestDeleteProjectWithUsagePreviousMonth(t *testing.T) { require.Equal(t, http.StatusConflict, response.StatusCode) }) } - -func TestRateLimit_ProjectRateLimitZero(t *testing.T) { - rateLimit := 2 - testplanet.Run(t, testplanet.Config{ - SatelliteCount: 1, StorageNodeCount: 0, UplinkCount: 1, - Reconfigure: testplanet.Reconfigure{ - Satellite: func(log *zap.Logger, index int, config *satellite.Config) { - config.Metainfo.RateLimiter.Rate = float64(rateLimit) - // Make limit cache to refresh as quickly as possible - // if it starts to become flaky, we can then add sleeps between - // the cache update and the API calls - config.Metainfo.RateLimiter.CacheExpiration = time.Millisecond - }, - }, - }, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { - ul := planet.Uplinks[0] - satellite := planet.Satellites[0] - - projects, err := satellite.DB.Console().Projects().GetAll(ctx) - require.NoError(t, err) - require.Len(t, projects, 1) - - zeroRateLimit := 0 - err = satellite.DB.Console().Projects().UpdateRateLimit(ctx, projects[0].ID, zeroRateLimit) - require.NoError(t, err) - - var group errs2.Group - for i := 0; i <= rateLimit; i++ { - group.Go(func() error { - return ul.CreateBucket(ctx, satellite, testrand.BucketName()) - }) - } - groupErrs := group.Wait() - require.Len(t, groupErrs, 3) - }) -} - -func TestBurstLimit_ProjectBurstLimitZero(t *testing.T) { - rateLimit := 2 - testplanet.Run(t, testplanet.Config{ - SatelliteCount: 1, StorageNodeCount: 0, UplinkCount: 1, - Reconfigure: testplanet.Reconfigure{ - Satellite: func(log *zap.Logger, index int, config *satellite.Config) { - config.Metainfo.RateLimiter.Rate = float64(rateLimit) - // Make limit cache to refresh as quickly as possible - // if it starts to become flaky, we can then add sleeps between - // the cache update and the API calls - config.Metainfo.RateLimiter.CacheExpiration = time.Millisecond - }, - }, - }, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { - ul := planet.Uplinks[0] - satellite := planet.Satellites[0] - - projects, err := satellite.DB.Console().Projects().GetAll(ctx) - require.NoError(t, err) - require.Len(t, projects, 1) - - zeroRateLimit := 0 - err = satellite.DB.Console().Projects().UpdateBurstLimit(ctx, projects[0].ID, zeroRateLimit) - require.NoError(t, err) - - var group errs2.Group - for i := 0; i <= rateLimit; i++ { - group.Go(func() error { - return ul.CreateBucket(ctx, satellite, testrand.BucketName()) - }) - } - groupErrs := group.Wait() - require.Len(t, groupErrs, 3) - }) -} diff --git a/satellite/console/projects_test.go b/satellite/console/projects_test.go index a6d2225b1..dc05e14f4 100644 --- a/satellite/console/projects_test.go +++ b/satellite/console/projects_test.go @@ -14,10 +14,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/zap" + "storj.io/common/errs2" "storj.io/common/testcontext" "storj.io/common/testrand" "storj.io/common/uuid" + "storj.io/storj/private/testplanet" "storj.io/storj/satellite" "storj.io/storj/satellite/console" "storj.io/storj/satellite/satellitedb/satellitedbtest" @@ -326,7 +329,7 @@ func TestProjectsListByOwner(t *testing.T) { } // test listing for each - var testCases = []struct { + testCases := []struct { id uuid.UUID originalProjects []console.Project }{ @@ -417,8 +420,80 @@ func TestValidateNameAndDescription(t *testing.T) { }) } +func TestRateLimit_ProjectRateLimitZero(t *testing.T) { + rateLimit := 2 + testplanet.Run(t, testplanet.Config{ + SatelliteCount: 1, StorageNodeCount: 0, UplinkCount: 1, + Reconfigure: testplanet.Reconfigure{ + Satellite: func(_ *zap.Logger, _ int, config *satellite.Config) { + config.Metainfo.RateLimiter.Rate = float64(rateLimit) + // Make limit cache to refresh as quickly as possible + // if it starts to become flaky, we can then add sleeps between + // the cache update and the API calls + config.Metainfo.RateLimiter.CacheExpiration = time.Millisecond + }, + }, + }, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { + ul := planet.Uplinks[0] + satellite := planet.Satellites[0] + + projects, err := satellite.DB.Console().Projects().GetAll(ctx) + require.NoError(t, err) + require.Len(t, projects, 1) + + zeroRateLimit := 0 + err = satellite.DB.Console().Projects().UpdateRateLimit(ctx, projects[0].ID, zeroRateLimit) + require.NoError(t, err) + + var group errs2.Group + for i := 0; i <= rateLimit; i++ { + group.Go(func() error { + return ul.CreateBucket(ctx, satellite, testrand.BucketName()) + }) + } + groupErrs := group.Wait() + require.Len(t, groupErrs, 3) + }) +} + +func TestBurstLimit_ProjectBurstLimitZero(t *testing.T) { + rateLimit := 2 + testplanet.Run(t, testplanet.Config{ + SatelliteCount: 1, StorageNodeCount: 0, UplinkCount: 1, + Reconfigure: testplanet.Reconfigure{ + Satellite: func(_ *zap.Logger, _ int, config *satellite.Config) { + config.Metainfo.RateLimiter.Rate = float64(rateLimit) + // Make limit cache to refresh as quickly as possible + // if it starts to become flaky, we can then add sleeps between + // the cache update and the API calls + config.Metainfo.RateLimiter.CacheExpiration = time.Millisecond + }, + }, + }, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { + ul := planet.Uplinks[0] + satellite := planet.Satellites[0] + + projects, err := satellite.DB.Console().Projects().GetAll(ctx) + require.NoError(t, err) + require.Len(t, projects, 1) + + zeroRateLimit := 0 + err = satellite.DB.Console().Projects().UpdateBurstLimit(ctx, projects[0].ID, zeroRateLimit) + require.NoError(t, err) + + var group errs2.Group + for i := 0; i <= rateLimit; i++ { + group.Go(func() error { + return ul.CreateBucket(ctx, satellite, testrand.BucketName()) + }) + } + groupErrs := group.Wait() + require.Len(t, groupErrs, 3) + }) +} + func randString(n int) string { - var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") + letters := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") b := make([]rune, n) for i := range b {