storagenode/console/consoleapi: use fixed time.Now()

It seems the tests relied on time.Now(), which might cause some
discrepancies in calculations. Use a fixed time.Now() rather than
recalculating.

As a sidefix, remove "Test" prefix from t.Run. These are unnecessary.

Change-Id: I1de903fcf0fcf46fc8e3acf2463e17239b8e3cc6
This commit is contained in:
Egon Elbre 2022-07-01 12:32:17 +03:00
parent 6c5edf436e
commit 05e165283f
10 changed files with 69 additions and 67 deletions

View File

@ -11,20 +11,20 @@ import (
) )
func TestParseHumanDate(t *testing.T) { func TestParseHumanDate(t *testing.T) {
t.Run("test parse relative date", func(t *testing.T) { t.Run("parse relative date", func(t *testing.T) {
parsed, err := parseHumanDate("+24h") parsed, err := parseHumanDate("+24h")
require.NoError(t, err) require.NoError(t, err)
require.Less(t, parsed.Unix(), time.Now().Add(25*time.Hour).Unix()) require.Less(t, parsed.Unix(), time.Now().Add(25*time.Hour).Unix())
require.Greater(t, parsed.Unix(), time.Now().Add(23*time.Hour).Unix()) require.Greater(t, parsed.Unix(), time.Now().Add(23*time.Hour).Unix())
}) })
t.Run("test parse absolute date", func(t *testing.T) { t.Run("parse absolute date", func(t *testing.T) {
parsed, err := parseHumanDate("2030-02-03T12:13:14+01:00") parsed, err := parseHumanDate("2030-02-03T12:13:14+01:00")
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, "2030-02-03T12:13:14+01:00", parsed.Format(time.RFC3339)) require.Equal(t, "2030-02-03T12:13:14+01:00", parsed.Format(time.RFC3339))
}) })
t.Run("test parse nonsense", func(t *testing.T) { t.Run("parse nonsense", func(t *testing.T) {
parsed, err := parseHumanDate("999999") parsed, err := parseHumanDate("999999")
require.Equal(t, time.Time{}, parsed) require.Equal(t, time.Time{}, parsed)
require.Error(t, err) require.Error(t, err)

View File

@ -694,7 +694,7 @@ func TestUsageRollups(t *testing.T) {
usageRollups := db.ProjectAccounting() usageRollups := db.ProjectAccounting()
t.Run("test project total", func(t *testing.T) { t.Run("project total", func(t *testing.T) {
projTotal1, err := usageRollups.GetProjectTotal(ctx, project1, start, now) projTotal1, err := usageRollups.GetProjectTotal(ctx, project1, start, now)
require.NoError(t, err) require.NoError(t, err)
require.NotNil(t, projTotal1) require.NotNil(t, projTotal1)
@ -718,7 +718,7 @@ func TestUsageRollups(t *testing.T) {
require.NotZero(t, projTotal3Prev3Hours.Egress) require.NotZero(t, projTotal3Prev3Hours.Egress)
}) })
t.Run("test bucket usage rollups", func(t *testing.T) { t.Run("bucket usage rollups", func(t *testing.T) {
rollups1, err := usageRollups.GetBucketUsageRollups(ctx, project1, start, now) rollups1, err := usageRollups.GetBucketUsageRollups(ctx, project1, start, now)
require.NoError(t, err) require.NoError(t, err)
require.NotNil(t, rollups1) require.NotNil(t, rollups1)
@ -740,7 +740,7 @@ func TestUsageRollups(t *testing.T) {
require.NotNil(t, rollups3Prev3Hours) require.NotNil(t, rollups3Prev3Hours)
}) })
t.Run("test bucket totals", func(t *testing.T) { t.Run("bucket totals", func(t *testing.T) {
cursor := accounting.BucketUsageCursor{ cursor := accounting.BucketUsageCursor{
Limit: 20, Limit: 20,
Page: 1, Page: 1,

View File

@ -52,7 +52,7 @@ func TestService(t *testing.T) {
userCtx2, err := sat.UserContext(ctx, up2Pro1.OwnerID) userCtx2, err := sat.UserContext(ctx, up2Pro1.OwnerID)
require.NoError(t, err) require.NoError(t, err)
t.Run("TestGetProject", func(t *testing.T) { t.Run("GetProject", func(t *testing.T) {
// Getting own project details should work // Getting own project details should work
project, err := service.GetProject(userCtx1, up1Pro1.ID) project, err := service.GetProject(userCtx1, up1Pro1.ID)
require.NoError(t, err) require.NoError(t, err)
@ -64,7 +64,7 @@ func TestService(t *testing.T) {
require.Nil(t, project) require.Nil(t, project)
}) })
t.Run("TestUpdateProject", func(t *testing.T) { t.Run("UpdateProject", func(t *testing.T) {
updatedName := "newName" updatedName := "newName"
updatedDescription := "newDescription" updatedDescription := "newDescription"
updatedStorageLimit := memory.Size(100) updatedStorageLimit := memory.Size(100)
@ -161,7 +161,7 @@ func TestService(t *testing.T) {
require.Equal(t, updateInfo.BandwidthLimit, *project.BandwidthLimit) require.Equal(t, updateInfo.BandwidthLimit, *project.BandwidthLimit)
}) })
t.Run("TestAddProjectMembers", func(t *testing.T) { t.Run("AddProjectMembers", func(t *testing.T) {
// Adding members to own project should work // Adding members to own project should work
addedUsers, err := service.AddProjectMembers(userCtx1, up1Pro1.ID, []string{up2User.Email}) addedUsers, err := service.AddProjectMembers(userCtx1, up1Pro1.ID, []string{up2User.Email})
require.NoError(t, err) require.NoError(t, err)
@ -174,7 +174,7 @@ func TestService(t *testing.T) {
require.Nil(t, addedUsers) require.Nil(t, addedUsers)
}) })
t.Run("TestGetProjectMembers", func(t *testing.T) { t.Run("GetProjectMembers", func(t *testing.T) {
// Getting the project members of an own project that one is a part of should work // Getting the project members of an own project that one is a part of should work
userPage, err := service.GetProjectMembers(userCtx1, up1Pro1.ID, console.ProjectMembersCursor{Page: 1, Limit: 10}) userPage, err := service.GetProjectMembers(userCtx1, up1Pro1.ID, console.ProjectMembersCursor{Page: 1, Limit: 10})
require.NoError(t, err) require.NoError(t, err)
@ -191,7 +191,7 @@ func TestService(t *testing.T) {
require.Nil(t, userPage) require.Nil(t, userPage)
}) })
t.Run("TestDeleteProjectMembers", func(t *testing.T) { t.Run("DeleteProjectMembers", func(t *testing.T) {
// Deleting project members of an own project should work // Deleting project members of an own project should work
err := service.DeleteProjectMembers(userCtx1, up1Pro1.ID, []string{up2User.Email}) err := service.DeleteProjectMembers(userCtx1, up1Pro1.ID, []string{up2User.Email})
require.NoError(t, err) require.NoError(t, err)
@ -201,7 +201,7 @@ func TestService(t *testing.T) {
require.Error(t, err) require.Error(t, err)
}) })
t.Run("TestDeleteProject", func(t *testing.T) { t.Run("DeleteProject", func(t *testing.T) {
// Deleting the own project should not work before deleting the API-Key // Deleting the own project should not work before deleting the API-Key
err := service.DeleteProject(userCtx1, up1Pro1.ID) err := service.DeleteProject(userCtx1, up1Pro1.ID)
require.Error(t, err) require.Error(t, err)
@ -230,7 +230,7 @@ func TestService(t *testing.T) {
require.Equal(t, "console service: project usage: some buckets still exist", err.Error()) require.Equal(t, "console service: project usage: some buckets still exist", err.Error())
}) })
t.Run("TestChangeEmail", func(t *testing.T) { t.Run("ChangeEmail", func(t *testing.T) {
const newEmail = "newEmail@example.com" const newEmail = "newEmail@example.com"
err = service.ChangeEmail(userCtx2, newEmail) err = service.ChangeEmail(userCtx2, newEmail)
@ -244,7 +244,7 @@ func TestService(t *testing.T) {
require.Error(t, err) require.Error(t, err)
}) })
t.Run("TestGetAllBucketNames", func(t *testing.T) { t.Run("GetAllBucketNames", func(t *testing.T) {
bucket1 := storj.Bucket{ bucket1 := storj.Bucket{
ID: testrand.UUID(), ID: testrand.UUID(),
Name: "testBucket1", Name: "testBucket1",
@ -274,7 +274,7 @@ func TestService(t *testing.T) {
require.Nil(t, bucketsForUnauthorizedUser) require.Nil(t, bucketsForUnauthorizedUser)
}) })
t.Run("TestDeleteAPIKeyByNameAndProjectID", func(t *testing.T) { t.Run("DeleteAPIKeyByNameAndProjectID", func(t *testing.T) {
secret, err := macaroon.NewSecret() secret, err := macaroon.NewSecret()
require.NoError(t, err) require.NoError(t, err)
@ -405,7 +405,7 @@ func TestMFA(t *testing.T) {
userCtx, user := updateContext() userCtx, user := updateContext()
var key string var key string
t.Run("TestResetMFASecretKey", func(t *testing.T) { t.Run("ResetMFASecretKey", func(t *testing.T) {
key, err = service.ResetMFASecretKey(userCtx) key, err = service.ResetMFASecretKey(userCtx)
require.NoError(t, err) require.NoError(t, err)
@ -413,7 +413,7 @@ func TestMFA(t *testing.T) {
require.NotEmpty(t, user.MFASecretKey) require.NotEmpty(t, user.MFASecretKey)
}) })
t.Run("TestEnableUserMFABadPasscode", func(t *testing.T) { t.Run("EnableUserMFABadPasscode", func(t *testing.T) {
// Expect MFA-enabling attempt to be rejected when providing stale passcode. // Expect MFA-enabling attempt to be rejected when providing stale passcode.
badCode, err := console.NewMFAPasscode(key, time.Time{}.Add(time.Hour)) badCode, err := console.NewMFAPasscode(key, time.Time{}.Add(time.Hour))
require.NoError(t, err) require.NoError(t, err)
@ -429,7 +429,7 @@ func TestMFA(t *testing.T) {
require.False(t, user.MFAEnabled) require.False(t, user.MFAEnabled)
}) })
t.Run("TestEnableUserMFAGoodPasscode", func(t *testing.T) { t.Run("EnableUserMFAGoodPasscode", func(t *testing.T) {
// Expect MFA-enabling attempt to succeed when providing valid passcode. // Expect MFA-enabling attempt to succeed when providing valid passcode.
goodCode, err := console.NewMFAPasscode(key, time.Time{}) goodCode, err := console.NewMFAPasscode(key, time.Time{})
require.NoError(t, err) require.NoError(t, err)
@ -443,7 +443,7 @@ func TestMFA(t *testing.T) {
require.Equal(t, user.MFASecretKey, key) require.Equal(t, user.MFASecretKey, key)
}) })
t.Run("TestMFAGetToken", func(t *testing.T) { t.Run("MFAGetToken", func(t *testing.T) {
request := console.AuthUser{Email: user.Email, Password: user.FullName} request := console.AuthUser{Email: user.Email, Password: user.FullName}
// Expect no token due to lack of MFA passcode. // Expect no token due to lack of MFA passcode.
@ -470,7 +470,7 @@ func TestMFA(t *testing.T) {
require.NotEmpty(t, token) require.NotEmpty(t, token)
}) })
t.Run("TestMFARecoveryCodes", func(t *testing.T) { t.Run("MFARecoveryCodes", func(t *testing.T) {
_, err = service.ResetMFARecoveryCodes(userCtx) _, err = service.ResetMFARecoveryCodes(userCtx)
require.NoError(t, err) require.NoError(t, err)
@ -500,7 +500,7 @@ func TestMFA(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
}) })
t.Run("TestDisableUserMFABadPasscode", func(t *testing.T) { t.Run("DisableUserMFABadPasscode", func(t *testing.T) {
// Expect MFA-disabling attempt to fail when providing valid passcode. // Expect MFA-disabling attempt to fail when providing valid passcode.
badCode, err := console.NewMFAPasscode(key, time.Time{}.Add(time.Hour)) badCode, err := console.NewMFAPasscode(key, time.Time{}.Add(time.Hour))
require.NoError(t, err) require.NoError(t, err)
@ -515,7 +515,7 @@ func TestMFA(t *testing.T) {
require.NotEmpty(t, user.MFARecoveryCodes) require.NotEmpty(t, user.MFARecoveryCodes)
}) })
t.Run("TestDisableUserMFAConflict", func(t *testing.T) { t.Run("DisableUserMFAConflict", func(t *testing.T) {
// Expect MFA-disabling attempt to fail when providing both recovery code and passcode. // Expect MFA-disabling attempt to fail when providing both recovery code and passcode.
goodCode, err := console.NewMFAPasscode(key, time.Time{}) goodCode, err := console.NewMFAPasscode(key, time.Time{})
require.NoError(t, err) require.NoError(t, err)
@ -530,7 +530,7 @@ func TestMFA(t *testing.T) {
require.NotEmpty(t, user.MFARecoveryCodes) require.NotEmpty(t, user.MFARecoveryCodes)
}) })
t.Run("TestDisableUserMFAGoodPasscode", func(t *testing.T) { t.Run("DisableUserMFAGoodPasscode", func(t *testing.T) {
// Expect MFA-disabling attempt to succeed when providing valid passcode. // Expect MFA-disabling attempt to succeed when providing valid passcode.
goodCode, err := console.NewMFAPasscode(key, time.Time{}) goodCode, err := console.NewMFAPasscode(key, time.Time{})
require.NoError(t, err) require.NoError(t, err)
@ -545,7 +545,7 @@ func TestMFA(t *testing.T) {
require.Empty(t, user.MFARecoveryCodes) require.Empty(t, user.MFARecoveryCodes)
}) })
t.Run("TestDisableUserMFAGoodRecoveryCode", func(t *testing.T) { t.Run("DisableUserMFAGoodRecoveryCode", func(t *testing.T) {
// Expect MFA-disabling attempt to succeed when providing valid recovery code. // Expect MFA-disabling attempt to succeed when providing valid recovery code.
// Enable MFA // Enable MFA
key, err = service.ResetMFASecretKey(userCtx) key, err = service.ResetMFASecretKey(userCtx)

View File

@ -55,7 +55,7 @@ func TestNotificationsApi(t *testing.T) {
require.Equal(t, newNotification2.Type, notif2.Type) require.Equal(t, newNotification2.Type, notif2.Type)
require.Equal(t, newNotification2.SenderID, notif2.SenderID) require.Equal(t, newNotification2.SenderID, notif2.SenderID)
t.Run("test ListNotifications", func(t *testing.T) { t.Run("ListNotifications", func(t *testing.T) {
// should return notifications list. // should return notifications list.
url := fmt.Sprintf("%s/list?limit=3&page=1", baseURL) url := fmt.Sprintf("%s/list?limit=3&page=1", baseURL)
res, err := httpGet(ctx, url) res, err := httpGet(ctx, url)
@ -76,7 +76,7 @@ func TestNotificationsApi(t *testing.T) {
require.Equal(t, "{\"page\":{\"notifications\":"+string(expected)+",\"offset\":0,\"limit\":3,\"currentPage\":1,\"pageCount\":1},\"unreadCount\":2,\"totalCount\":2}"+"\n", string(body)) require.Equal(t, "{\"page\":{\"notifications\":"+string(expected)+",\"offset\":0,\"limit\":3,\"currentPage\":1,\"pageCount\":1},\"unreadCount\":2,\"totalCount\":2}"+"\n", string(body))
}) })
t.Run("test ReadNotification", func(t *testing.T) { t.Run("ReadNotification", func(t *testing.T) {
// should change status of notification by id to read. // should change status of notification by id to read.
url := fmt.Sprintf("%s/%s/read", baseURL, notif1.ID.String()) url := fmt.Sprintf("%s/%s/read", baseURL, notif1.ID.String())
res, err := httpPost(ctx, url, "application/json", nil) res, err := httpPost(ctx, url, "application/json", nil)
@ -97,7 +97,7 @@ func TestNotificationsApi(t *testing.T) {
require.NotEqual(t, nil, notificationList.Notifications[1].ReadAt) require.NotEqual(t, nil, notificationList.Notifications[1].ReadAt)
}) })
t.Run("test ReadAllNotifications", func(t *testing.T) { t.Run("ReadAllNotifications", func(t *testing.T) {
// should change status of notification by id to read. // should change status of notification by id to read.
url := fmt.Sprintf("%s/readall", baseURL) url := fmt.Sprintf("%s/readall", baseURL)
res, err := httpPost(ctx, url, "application/json", nil) res, err := httpPost(ctx, url, "application/json", nil)

View File

@ -67,7 +67,7 @@ func TestHeldAmountApi(t *testing.T) {
err := payoutsDB.StorePayStub(ctx, paystub) err := payoutsDB.StorePayStub(ctx, paystub)
require.NoError(t, err) require.NoError(t, err)
t.Run("test SatellitePayStubMonthly", func(t *testing.T) { t.Run("SatellitePayStubMonthly", func(t *testing.T) {
// should return paystub inserted earlier // should return paystub inserted earlier
url := fmt.Sprintf("%s/paystubs/%s?id=%s", baseURL, period, satellite.ID().String()) url := fmt.Sprintf("%s/paystubs/%s?id=%s", baseURL, period, satellite.ID().String())
res, err := httpGet(ctx, url) res, err := httpGet(ctx, url)
@ -145,7 +145,7 @@ func TestHeldAmountApi(t *testing.T) {
err = payoutsDB.StorePayStub(ctx, paystub2) err = payoutsDB.StorePayStub(ctx, paystub2)
require.NoError(t, err) require.NoError(t, err)
t.Run("test AllPayStubsMonthly", func(t *testing.T) { t.Run("AllPayStubsMonthly", func(t *testing.T) {
// should return 2 paystubs inserted earlier // should return 2 paystubs inserted earlier
url := fmt.Sprintf("%s/paystubs/%s", baseURL, period) url := fmt.Sprintf("%s/paystubs/%s", baseURL, period)
res, err := httpGet(ctx, url) res, err := httpGet(ctx, url)
@ -211,7 +211,7 @@ func TestHeldAmountApi(t *testing.T) {
err = payoutsDB.StorePayStub(ctx, paystub3) err = payoutsDB.StorePayStub(ctx, paystub3)
require.NoError(t, err) require.NoError(t, err)
t.Run("test SatellitePayStubPeriod", func(t *testing.T) { t.Run("SatellitePayStubPeriod", func(t *testing.T) {
// should return all paystubs inserted earlier // should return all paystubs inserted earlier
url := fmt.Sprintf("%s/paystubs/%s/%s?id=%s", baseURL, period2, period, satellite.ID().String()) url := fmt.Sprintf("%s/paystubs/%s/%s?id=%s", baseURL, period2, period, satellite.ID().String())
res, err := httpGet(ctx, url) res, err := httpGet(ctx, url)
@ -299,7 +299,7 @@ func TestHeldAmountApi(t *testing.T) {
require.Equal(t, "{\"error\":\"consoleapi payouts: wrong period format: period has wrong format\"}\n", string(body5)) require.Equal(t, "{\"error\":\"consoleapi payouts: wrong period format: period has wrong format\"}\n", string(body5))
}) })
t.Run("test AllPayStubsPeriod", func(t *testing.T) { t.Run("AllPayStubsPeriod", func(t *testing.T) {
// should return all paystubs inserted earlier // should return all paystubs inserted earlier
url := fmt.Sprintf("%s/paystubs/%s/%s", baseURL, period2, period) url := fmt.Sprintf("%s/paystubs/%s/%s", baseURL, period2, period)
res, err := httpGet(ctx, url) res, err := httpGet(ctx, url)
@ -355,7 +355,7 @@ func TestHeldAmountApi(t *testing.T) {
require.Equal(t, "{\"error\":\"consoleapi payouts: wrong period format: period has wrong format\"}\n", string(body5)) require.Equal(t, "{\"error\":\"consoleapi payouts: wrong period format: period has wrong format\"}\n", string(body5))
}) })
t.Run("test HeldbackHistory", func(t *testing.T) { t.Run("HeldbackHistory", func(t *testing.T) {
date := time.Now().UTC().AddDate(0, -2, 0).Round(time.Minute) date := time.Now().UTC().AddDate(0, -2, 0).Round(time.Minute)
err = reputationDB.Store(context.Background(), reputation.Stats{ err = reputationDB.Store(context.Background(), reputation.Stats{
SatelliteID: satellite.ID(), SatelliteID: satellite.ID(),
@ -399,7 +399,7 @@ func TestHeldAmountApi(t *testing.T) {
require.Equal(t, string(expected)+"\n", string(body)) require.Equal(t, string(expected)+"\n", string(body))
}) })
t.Run("test Periods", func(t *testing.T) { t.Run("Periods", func(t *testing.T) {
url := fmt.Sprintf("%s/periods", baseURL) url := fmt.Sprintf("%s/periods", baseURL)
res, err := httpGet(ctx, url) res, err := httpGet(ctx, url)
require.NoError(t, err) require.NoError(t, err)

View File

@ -72,10 +72,11 @@ func TestStorageNodeApi(t *testing.T) {
// pause nodestats reputation cache because later tests assert a specific joinedat. // pause nodestats reputation cache because later tests assert a specific joinedat.
sno.NodeStats.Cache.Reputation.Pause() sno.NodeStats.Cache.Reputation.Pause()
now := time.Now().UTC().Add(-2 * time.Hour) now := time.Now().UTC()
startingPoint := now.Add(-2 * time.Hour)
for _, action := range actions { for _, action := range actions {
err := bandwidthdb.Add(ctx, satellite.ID(), action, 2300000000000, now) err := bandwidthdb.Add(ctx, satellite.ID(), action, 2300000000000, startingPoint)
require.NoError(t, err) require.NoError(t, err)
} }
var satellites []storj.NodeID var satellites []storj.NodeID
@ -88,7 +89,7 @@ func TestStorageNodeApi(t *testing.T) {
err = reputationdb.Store(ctx, reputation.Stats{ err = reputationdb.Store(ctx, reputation.Stats{
SatelliteID: satellite.ID(), SatelliteID: satellite.ID(),
JoinedAt: now.AddDate(0, -2, 0), JoinedAt: startingPoint.AddDate(0, -2, 0),
}) })
require.NoError(t, err) require.NoError(t, err)
@ -103,7 +104,7 @@ func TestStorageNodeApi(t *testing.T) {
}) })
require.NoError(t, err) require.NoError(t, err)
t.Run("test EstimatedPayout", func(t *testing.T) { t.Run("EstimatedPayout", func(t *testing.T) {
// should return estimated payout for both satellites in current month and empty for previous // should return estimated payout for both satellites in current month and empty for previous
req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("%s/estimated-payout", baseURL), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("%s/estimated-payout", baseURL), nil)
require.NoError(t, err) require.NoError(t, err)
@ -122,7 +123,7 @@ func TestStorageNodeApi(t *testing.T) {
bodyPayout := &estimatedpayouts.EstimatedPayout{} bodyPayout := &estimatedpayouts.EstimatedPayout{}
require.NoError(t, json.Unmarshal(body, bodyPayout)) require.NoError(t, json.Unmarshal(body, bodyPayout))
estimation, err := sno.Console.Service.GetAllSatellitesEstimatedPayout(ctx, time.Now()) estimation, err := sno.Console.Service.GetAllSatellitesEstimatedPayout(ctx, now)
require.NoError(t, err) require.NoError(t, err)
expectedPayout := &estimatedpayouts.EstimatedPayout{ expectedPayout := &estimatedpayouts.EstimatedPayout{
CurrentMonth: estimation.CurrentMonth, CurrentMonth: estimation.CurrentMonth,
@ -143,14 +144,15 @@ func makeStorageUsageStamps(satellites []storj.NodeID) ([]storageusage.Stamp, ma
var stamps []storageusage.Stamp var stamps []storageusage.Stamp
summary := make(map[storj.NodeID]float64) summary := make(map[storj.NodeID]float64)
now := time.Now().UTC().Day() now := time.Now().UTC()
currentDay := now.Day()
for _, satellite := range satellites { for _, satellite := range satellites {
for i := 0; i < now; i++ { for i := 0; i < currentDay; i++ {
stamp := storageusage.Stamp{ stamp := storageusage.Stamp{
SatelliteID: satellite, SatelliteID: satellite,
AtRestTotal: 30000000000000, AtRestTotal: 30000000000000,
IntervalStart: time.Now().UTC().Add(time.Hour * -24 * time.Duration(i)), IntervalStart: now.Add(time.Hour * -24 * time.Duration(i)),
} }
summary[satellite] += stamp.AtRestTotal summary[satellite] += stamp.AtRestTotal

View File

@ -195,7 +195,7 @@ func TestPayoutsEndpointEstimations(t *testing.T) {
}) })
require.NoError(t, err) require.NoError(t, err)
t.Run("test EstimatedPayoutTotal", func(t *testing.T) { t.Run("EstimatedPayoutTotal", func(t *testing.T) {
estimation, err := estimatedPayoutsService.GetAllSatellitesEstimatedPayout(ctx, time.Now()) estimation, err := estimatedPayoutsService.GetAllSatellitesEstimatedPayout(ctx, time.Now())
require.NoError(t, err) require.NoError(t, err)

View File

@ -77,7 +77,7 @@ func TestNotificationsDB(t *testing.T) {
page := notifications.Page{} page := notifications.Page{}
// test List method to return right form of page depending on cursor. // test List method to return right form of page depending on cursor.
t.Run("test paged list", func(t *testing.T) { t.Run("paged list", func(t *testing.T) {
page, err = notificationsdb.List(ctx, notificationCursor) page, err = notificationsdb.List(ctx, notificationCursor)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 2, len(page.Notifications)) require.Equal(t, 2, len(page.Notifications))
@ -96,7 +96,7 @@ func TestNotificationsDB(t *testing.T) {
} }
// test Read method to make specific notification's status as read. // test Read method to make specific notification's status as read.
t.Run("test notification read", func(t *testing.T) { t.Run("notification read", func(t *testing.T) {
err = notificationsdb.Read(ctx, notificationFromDB0.ID) err = notificationsdb.Read(ctx, notificationFromDB0.ID)
require.NoError(t, err) require.NoError(t, err)
@ -115,7 +115,7 @@ func TestNotificationsDB(t *testing.T) {
}) })
// test ReadAll method to make all notifications' status as read. // test ReadAll method to make all notifications' status as read.
t.Run("test notification read all", func(t *testing.T) { t.Run("notification read all", func(t *testing.T) {
err = notificationsdb.ReadAll(ctx) err = notificationsdb.ReadAll(ctx)
require.NoError(t, err) require.NoError(t, err)
@ -138,7 +138,7 @@ func TestEmptyNotificationsDB(t *testing.T) {
} }
// test List method to return right form of page depending on cursor with empty database. // test List method to return right form of page depending on cursor with empty database.
t.Run("test empty paged list", func(t *testing.T) { t.Run("empty paged list", func(t *testing.T) {
page, err := notificationsdb.List(ctx, notificationCursor) page, err := notificationsdb.List(ctx, notificationCursor)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, len(page.Notifications), 0) require.Equal(t, len(page.Notifications), 0)
@ -150,13 +150,13 @@ func TestEmptyNotificationsDB(t *testing.T) {
}) })
// test notification read with not existing id. // test notification read with not existing id.
t.Run("test notification read with not existing id", func(t *testing.T) { t.Run("notification read with not existing id", func(t *testing.T) {
err := notificationsdb.Read(ctx, testrand.UUID()) err := notificationsdb.Read(ctx, testrand.UUID())
require.Error(t, err, "no rows affected") require.Error(t, err, "no rows affected")
}) })
// test read for all notifications if they don't exist. // test read for all notifications if they don't exist.
t.Run("test notification readAll on empty page", func(t *testing.T) { t.Run("notification readAll on empty page", func(t *testing.T) {
err := notificationsdb.ReadAll(ctx) err := notificationsdb.ReadAll(ctx)
require.NoError(t, err) require.NoError(t, err)
}) })

View File

@ -49,7 +49,7 @@ func TestHeldAmountDB(t *testing.T) {
paystub2.Period = "2020-02" paystub2.Period = "2020-02"
paystub2.Created = paystub.Created.Add(time.Hour * 24 * 30) paystub2.Created = paystub.Created.Add(time.Hour * 24 * 30)
t.Run("Test StorePayStub", func(t *testing.T) { t.Run("StorePayStub", func(t *testing.T) {
err := payout.StorePayStub(ctx, paystub) err := payout.StorePayStub(ctx, paystub)
assert.NoError(t, err) assert.NoError(t, err)
}) })
@ -60,7 +60,7 @@ func TestHeldAmountDB(t *testing.T) {
Receipt: "test", Receipt: "test",
} }
t.Run("Test GetPayStub", func(t *testing.T) { t.Run("GetPayStub", func(t *testing.T) {
err := payout.StorePayment(ctx, payment) err := payout.StorePayment(ctx, payment)
assert.NoError(t, err) assert.NoError(t, err)
@ -107,7 +107,7 @@ func TestHeldAmountDB(t *testing.T) {
assert.NotNil(t, receipt) assert.NotNil(t, receipt)
}) })
t.Run("Test AllPayStubs", func(t *testing.T) { t.Run("AllPayStubs", func(t *testing.T) {
stubs, err := payout.AllPayStubs(ctx, period) stubs, err := payout.AllPayStubs(ctx, period)
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, stubs) assert.NotNil(t, stubs)
@ -149,19 +149,19 @@ func TestHeldAmountDB(t *testing.T) {
Notes: "notes", Notes: "notes",
} }
t.Run("Test StorePayment", func(t *testing.T) { t.Run("StorePayment", func(t *testing.T) {
err := payout.StorePayment(ctx, payment) err := payout.StorePayment(ctx, payment)
assert.NoError(t, err) assert.NoError(t, err)
}) })
t.Run("Test SatellitesHeldbackHistory", func(t *testing.T) { t.Run("SatellitesHeldbackHistory", func(t *testing.T) {
heldback, err := payout.SatellitesHeldbackHistory(ctx, satelliteID) heldback, err := payout.SatellitesHeldbackHistory(ctx, satelliteID)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, heldback[0].Amount, paystub.Held) assert.Equal(t, heldback[0].Amount, paystub.Held)
assert.Equal(t, heldback[0].Period, paystub.Period) assert.Equal(t, heldback[0].Period, paystub.Period)
}) })
t.Run("Test SatellitePeriods", func(t *testing.T) { t.Run("SatellitePeriods", func(t *testing.T) {
periods, err := payout.SatellitePeriods(ctx, paystub.SatelliteID) periods, err := payout.SatellitePeriods(ctx, paystub.SatelliteID)
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, periods) assert.NotNil(t, periods)
@ -179,7 +179,7 @@ func TestHeldAmountDB(t *testing.T) {
assert.Equal(t, paystub2.Period, periods[1]) assert.Equal(t, paystub2.Period, periods[1])
}) })
t.Run("Test AllPeriods", func(t *testing.T) { t.Run("AllPeriods", func(t *testing.T) {
periods, err := payout.AllPeriods(ctx) periods, err := payout.AllPeriods(ctx)
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, periods) assert.NotNil(t, periods)
@ -318,7 +318,7 @@ func TestAllPayStubPeriodCached(t *testing.T) {
func TestPayouts(t *testing.T) { func TestPayouts(t *testing.T) {
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) { storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
payout := db.Payout() payout := db.Payout()
t.Run("Test SatelliteIDs", func(t *testing.T) { t.Run("SatelliteIDs", func(t *testing.T) {
id1 := testrand.NodeID() id1 := testrand.NodeID()
id2 := testrand.NodeID() id2 := testrand.NodeID()
id3 := testrand.NodeID() id3 := testrand.NodeID()
@ -350,7 +350,7 @@ func TestPayouts(t *testing.T) {
require.Equal(t, len(listIDs), 3) require.Equal(t, len(listIDs), 3)
require.NoError(t, err) require.NoError(t, err)
}) })
t.Run("Test GetSatelliteEarned", func(t *testing.T) { t.Run("GetSatelliteEarned", func(t *testing.T) {
id1 := testrand.NodeID() id1 := testrand.NodeID()
id2 := testrand.NodeID() id2 := testrand.NodeID()
id3 := testrand.NodeID() id3 := testrand.NodeID()
@ -407,7 +407,7 @@ func TestPayouts(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
}) })
t.Run("Test GetSatelliteSummary", func(t *testing.T) { t.Run("GetSatelliteSummary", func(t *testing.T) {
id1 := testrand.NodeID() id1 := testrand.NodeID()
id2 := testrand.NodeID() id2 := testrand.NodeID()

View File

@ -55,12 +55,12 @@ func TestStorageUsage(t *testing.T) {
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) { storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
storageUsageDB := db.StorageUsage() storageUsageDB := db.StorageUsage()
t.Run("test store", func(t *testing.T) { t.Run("store", func(t *testing.T) {
err := storageUsageDB.Store(ctx, stamps) err := storageUsageDB.Store(ctx, stamps)
assert.NoError(t, err) assert.NoError(t, err)
}) })
t.Run("test get daily", func(t *testing.T) { t.Run("get daily", func(t *testing.T) {
res, err := storageUsageDB.GetDaily(ctx, satelliteID, time.Time{}, now) res, err := storageUsageDB.GetDaily(ctx, satelliteID, time.Time{}, now)
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, res) assert.NotNil(t, res)
@ -72,7 +72,7 @@ func TestStorageUsage(t *testing.T) {
} }
}) })
t.Run("test get daily total", func(t *testing.T) { t.Run("get daily total", func(t *testing.T) {
res, err := storageUsageDB.GetDailyTotal(ctx, time.Time{}, now) res, err := storageUsageDB.GetDailyTotal(ctx, time.Time{}, now)
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, res) assert.NotNil(t, res)
@ -83,13 +83,13 @@ func TestStorageUsage(t *testing.T) {
} }
}) })
t.Run("test summary satellite", func(t *testing.T) { t.Run("summary satellite", func(t *testing.T) {
summ, err := storageUsageDB.SatelliteSummary(ctx, satelliteID, time.Time{}, now) summ, err := storageUsageDB.SatelliteSummary(ctx, satelliteID, time.Time{}, now)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, summary[satelliteID], summ) assert.Equal(t, summary[satelliteID], summ)
}) })
t.Run("test summary", func(t *testing.T) { t.Run("summary", func(t *testing.T) {
summ, err := storageUsageDB.Summary(ctx, time.Time{}, now) summ, err := storageUsageDB.Summary(ctx, time.Time{}, now)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, totalSummary, summ) assert.Equal(t, totalSummary, summ)
@ -104,25 +104,25 @@ func TestEmptyStorageUsage(t *testing.T) {
storageUsageDB := db.StorageUsage() storageUsageDB := db.StorageUsage()
t.Run("test get daily", func(t *testing.T) { t.Run("get daily", func(t *testing.T) {
res, err := storageUsageDB.GetDaily(ctx, storj.NodeID{}, time.Time{}, now) res, err := storageUsageDB.GetDaily(ctx, storj.NodeID{}, time.Time{}, now)
assert.NoError(t, err) assert.NoError(t, err)
assert.Nil(t, res) assert.Nil(t, res)
}) })
t.Run("test get daily total", func(t *testing.T) { t.Run("get daily total", func(t *testing.T) {
res, err := storageUsageDB.GetDailyTotal(ctx, time.Time{}, now) res, err := storageUsageDB.GetDailyTotal(ctx, time.Time{}, now)
assert.NoError(t, err) assert.NoError(t, err)
assert.Nil(t, res) assert.Nil(t, res)
}) })
t.Run("test summary satellite", func(t *testing.T) { t.Run("summary satellite", func(t *testing.T) {
summ, err := storageUsageDB.SatelliteSummary(ctx, storj.NodeID{}, time.Time{}, now) summ, err := storageUsageDB.SatelliteSummary(ctx, storj.NodeID{}, time.Time{}, now)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, emptySummary, summ) assert.Equal(t, emptySummary, summ)
}) })
t.Run("test summary", func(t *testing.T) { t.Run("summary", func(t *testing.T) {
summ, err := storageUsageDB.Summary(ctx, time.Time{}, now) summ, err := storageUsageDB.Summary(ctx, time.Time{}, now)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, emptySummary, summ) assert.Equal(t, emptySummary, summ)