storj/private/testplanet/satellite_test.go
stefanbenten 9ace375ee0 satellite/{console,satellitedb}: change project limiting based on new users field
This change switches the backend logic to use the new DB column on the users table to restrict project creation.
Furthermore it back fills the existing limits from registration tokens to the new column to ensure no users are reset to the new default.

UI is updated to reflect ability to create several projects

Change-Id: Ie29157430ae6b065411ca4c4557c9f1be69cdc4f
2020-07-16 10:57:47 +00:00

42 lines
1.2 KiB
Go

// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information
package testplanet_test
import (
"strconv"
"testing"
"github.com/stretchr/testify/require"
"storj.io/common/testcontext"
"storj.io/storj/private/testplanet"
)
func TestSatellite_AddProject(t *testing.T) {
testplanet.Run(t, testplanet.Config{
SatelliteCount: 1, StorageNodeCount: 0, UplinkCount: 0,
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
user, err := planet.Satellites[0].AddUser(ctx, "test user", "test-email@test", 4)
require.NoError(t, err)
limit, err := planet.Satellites[0].DB.Console().Users().GetProjectLimit(ctx, user.ID)
require.NoError(t, err)
require.Equal(t, 4, limit)
for i := 0; i < 4; i++ {
_, err = planet.Satellites[0].AddProject(ctx, user.ID, "test project "+strconv.Itoa(i))
require.NoError(t, err)
}
projects, err := planet.Satellites[0].DB.Console().Projects().GetByUserID(ctx, user.ID)
require.NoError(t, err)
require.Equal(t, 4, len(projects))
// test if adding over limit will end with error
_, err = planet.Satellites[0].AddProject(ctx, user.ID, "test project over limit")
require.Error(t, err)
})
}