2019-01-24 16:26:36 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-13 08:27:42 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2022-06-27 22:20:59 +01:00
|
|
|
package satellitedb_test
|
2018-11-13 08:27:42 +00:00
|
|
|
|
|
|
|
import (
|
2022-12-15 07:11:03 +00:00
|
|
|
"math/rand"
|
2018-11-13 08:27:42 +00:00
|
|
|
"testing"
|
|
|
|
|
2022-06-27 22:20:59 +01:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-11-29 18:39:27 +00:00
|
|
|
|
2022-06-27 22:20:59 +01:00
|
|
|
"storj.io/common/testcontext"
|
2022-11-30 22:51:53 +00:00
|
|
|
"storj.io/common/uuid"
|
2022-06-27 22:20:59 +01:00
|
|
|
"storj.io/storj/satellite"
|
|
|
|
"storj.io/storj/satellite/console"
|
|
|
|
"storj.io/storj/satellite/satellitedb/satellitedbtest"
|
2018-11-13 08:27:42 +00:00
|
|
|
)
|
|
|
|
|
2022-06-27 22:20:59 +01:00
|
|
|
func TestProjectsGetByPublicID(t *testing.T) {
|
|
|
|
satellitedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) {
|
|
|
|
projects := db.Console().Projects()
|
2020-01-08 11:42:11 +00:00
|
|
|
|
2022-06-27 22:20:59 +01:00
|
|
|
prj, err := projects.Insert(ctx, &console.Project{
|
|
|
|
Name: "ProjectName",
|
|
|
|
Description: "projects description",
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, prj)
|
2018-11-13 08:27:42 +00:00
|
|
|
|
2022-06-27 22:20:59 +01:00
|
|
|
pubID := prj.PublicID
|
|
|
|
require.NotNil(t, pubID)
|
|
|
|
require.False(t, pubID.IsZero())
|
2018-11-13 08:27:42 +00:00
|
|
|
|
2022-06-27 22:20:59 +01:00
|
|
|
prj, err = projects.GetByPublicID(ctx, pubID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, pubID, prj.PublicID)
|
2018-11-13 08:27:42 +00:00
|
|
|
})
|
|
|
|
}
|
2022-09-13 13:45:18 +01:00
|
|
|
|
|
|
|
func TestProjectsGetSalt(t *testing.T) {
|
|
|
|
satellitedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) {
|
|
|
|
projects := db.Console().Projects()
|
|
|
|
|
|
|
|
prj, err := projects.Insert(ctx, &console.Project{
|
|
|
|
Name: "ProjectName",
|
|
|
|
Description: "projects description",
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, prj)
|
|
|
|
|
|
|
|
salt, err := projects.GetSalt(ctx, prj.ID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-30 22:51:53 +00:00
|
|
|
_, err = uuid.FromBytes(salt)
|
|
|
|
require.NoError(t, err)
|
2022-09-13 13:45:18 +01:00
|
|
|
})
|
|
|
|
}
|
2022-12-15 07:11:03 +00:00
|
|
|
|
|
|
|
func TestUpdateProjectUsageLimits(t *testing.T) {
|
|
|
|
satellitedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) {
|
|
|
|
limits := console.UsageLimits{Storage: rand.Int63(), Bandwidth: rand.Int63(), Segment: rand.Int63()}
|
|
|
|
projectsRepo := db.Console().Projects()
|
|
|
|
|
|
|
|
proj, err := projectsRepo.Insert(ctx, &console.Project{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, proj)
|
|
|
|
|
|
|
|
err = projectsRepo.UpdateUsageLimits(ctx, proj.ID, limits)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
proj, err = projectsRepo.Get(ctx, proj.ID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, limits.Bandwidth, proj.BandwidthLimit.Int64())
|
|
|
|
require.Equal(t, limits.Storage, proj.StorageLimit.Int64())
|
|
|
|
require.Equal(t, limits.Segment, *proj.SegmentLimit)
|
|
|
|
})
|
|
|
|
}
|