99"testing"
1010"time"
1111
12- common_db "github.com/gitpod-io/gitpod/common-go/db "
13- "github.com/gitpod-io/gitpod/usage/pkg/db"
14- "github.com/gitpod-io/gitpod/usage/pkg/db /dbtest"
12+ db "github.com/gitpod-io/gitpod/components/gitpod-db/go "
13+
14+ "github.com/gitpod-io/gitpod/components/gitpod-db/go /dbtest"
1515"github.com/google/uuid"
1616"github.com/stretchr/testify/require"
1717"google.golang.org/grpc/codes"
@@ -73,28 +73,28 @@ func TestCostCenterManager_GetOrCreateCostCenter_ResetsExpired(t *testing.T) {
7373
7474expiredCC := db.CostCenter {
7575ID : db .NewTeamAttributionID (uuid .New ().String ()),
76- CreationTime : common_db .NewVarCharTime (now ),
76+ CreationTime : db .NewVarCharTime (now ),
7777SpendingLimit : 0 ,
7878BillingStrategy : db .CostCenter_Other ,
79- NextBillingTime : common_db .NewVarCharTime (expired ),
80- BillingCycleStart : common_db .NewVarCharTime (now ),
79+ NextBillingTime : db .NewVarCharTime (expired ),
80+ BillingCycleStart : db .NewVarCharTime (now ),
8181}
8282unexpiredCC := db.CostCenter {
8383ID : db .NewUserAttributionID (uuid .New ().String ()),
84- CreationTime : common_db .NewVarCharTime (now ),
84+ CreationTime : db .NewVarCharTime (now ),
8585SpendingLimit : 500 ,
8686BillingStrategy : db .CostCenter_Other ,
87- NextBillingTime : common_db .NewVarCharTime (unexpired ),
88- BillingCycleStart : common_db .NewVarCharTime (now ),
87+ NextBillingTime : db .NewVarCharTime (unexpired ),
88+ BillingCycleStart : db .NewVarCharTime (now ),
8989}
9090// Stripe billing strategy should not be reset
9191stripeCC := db.CostCenter {
9292ID : db .NewUserAttributionID (uuid .New ().String ()),
93- CreationTime : common_db .NewVarCharTime (now ),
93+ CreationTime : db .NewVarCharTime (now ),
9494SpendingLimit : 0 ,
9595BillingStrategy : db .CostCenter_Stripe ,
96- NextBillingTime : common_db .VarcharTime {},
97- BillingCycleStart : common_db .NewVarCharTime (now ),
96+ NextBillingTime : db .VarcharTime {},
97+ BillingCycleStart : db .NewVarCharTime (now ),
9898}
9999
100100dbtest .CreateCostCenters (t , conn ,
@@ -103,21 +103,21 @@ func TestCostCenterManager_GetOrCreateCostCenter_ResetsExpired(t *testing.T) {
103103dbtest .NewCostCenter (t , stripeCC ),
104104)
105105
106- // expired CostCenter should be reset, so we get a new CreationTime
106+ // expired db. CostCenter should be reset, so we get a new CreationTime
107107retrievedExpiredCC , err := mnr .GetOrCreateCostCenter (context .Background (), expiredCC .ID )
108108require .NoError (t , err )
109109t .Cleanup (func () {
110110conn .Model (& db.CostCenter {}).Delete (retrievedExpiredCC .ID )
111111})
112- require .Equal (t , common_db .NewVarCharTime (expired ).Time ().AddDate (0 , 1 , 0 ), retrievedExpiredCC .NextBillingTime .Time ())
112+ require .Equal (t , db .NewVarCharTime (expired ).Time ().AddDate (0 , 1 , 0 ), retrievedExpiredCC .NextBillingTime .Time ())
113113require .Equal (t , expiredCC .ID , retrievedExpiredCC .ID )
114114require .Equal (t , expiredCC .BillingStrategy , retrievedExpiredCC .BillingStrategy )
115115require .WithinDuration (t , now , expiredCC .CreationTime .Time (), 3 * time .Second , "new cost center creation time must be within 3 seconds of now" )
116116
117117// unexpired cost center must not be reset
118118retrievedUnexpiredCC , err := mnr .GetOrCreateCostCenter (context .Background (), unexpiredCC .ID )
119119require .NoError (t , err )
120- require .Equal (t , common_db .NewVarCharTime (unexpired ).Time (), retrievedUnexpiredCC .NextBillingTime .Time ())
120+ require .Equal (t , db .NewVarCharTime (unexpired ).Time (), retrievedUnexpiredCC .NextBillingTime .Time ())
121121require .Equal (t , unexpiredCC .ID , retrievedUnexpiredCC .ID )
122122require .Equal (t , unexpiredCC .BillingStrategy , retrievedUnexpiredCC .BillingStrategy )
123123require .WithinDuration (t , unexpiredCC .CreationTime .Time (), retrievedUnexpiredCC .CreationTime .Time (), 100 * time .Millisecond )
@@ -349,16 +349,16 @@ func TestCostCenter_ListLatestCostCentersWithBillingTimeBefore(t *testing.T) {
349349dbtest .NewCostCenter (t , db.CostCenter {
350350ID : db .NewTeamAttributionID (attributionID ),
351351SpendingLimit : 100 ,
352- CreationTime : common_db .NewVarCharTime (firstCreation ),
352+ CreationTime : db .NewVarCharTime (firstCreation ),
353353BillingStrategy : db .CostCenter_Other ,
354- NextBillingTime : common_db .NewVarCharTime (firstCreation ),
354+ NextBillingTime : db .NewVarCharTime (firstCreation ),
355355}),
356356dbtest .NewCostCenter (t , db.CostCenter {
357357ID : db .NewTeamAttributionID (attributionID ),
358358SpendingLimit : 100 ,
359- CreationTime : common_db .NewVarCharTime (secondCreation ),
359+ CreationTime : db .NewVarCharTime (secondCreation ),
360360BillingStrategy : db .CostCenter_Other ,
361- NextBillingTime : common_db .NewVarCharTime (secondCreation ),
361+ NextBillingTime : db .NewVarCharTime (secondCreation ),
362362}),
363363}
364364
@@ -386,14 +386,14 @@ func TestCostCenter_ListLatestCostCentersWithBillingTimeBefore(t *testing.T) {
386386dbtest .NewCostCenter (t , db.CostCenter {
387387ID : db .NewTeamAttributionID (attributionID ),
388388SpendingLimit : 100 ,
389- CreationTime : common_db .NewVarCharTime (firstCreation ),
389+ CreationTime : db .NewVarCharTime (firstCreation ),
390390BillingStrategy : db .CostCenter_Other ,
391- NextBillingTime : common_db .NewVarCharTime (firstCreation ),
391+ NextBillingTime : db .NewVarCharTime (firstCreation ),
392392}),
393393dbtest .NewCostCenter (t , db.CostCenter {
394394ID : db .NewTeamAttributionID (attributionID ),
395395SpendingLimit : 100 ,
396- CreationTime : common_db .NewVarCharTime (secondCreation ),
396+ CreationTime : db .NewVarCharTime (secondCreation ),
397397BillingStrategy : db .CostCenter_Stripe ,
398398}),
399399}
@@ -418,7 +418,7 @@ func TestCostCenterManager_ResetUsage(t *testing.T) {
418418})
419419_ , err := mnr .ResetUsage (context .Background (), db.CostCenter {
420420ID : db .NewUserAttributionID (uuid .New ().String ()),
421- CreationTime : common_db .NewVarCharTime (time .Now ()),
421+ CreationTime : db .NewVarCharTime (time .Now ()),
422422SpendingLimit : 500 ,
423423BillingStrategy : db .CostCenter_Stripe ,
424424})
@@ -433,10 +433,10 @@ func TestCostCenterManager_ResetUsage(t *testing.T) {
433433})
434434oldCC := db.CostCenter {
435435ID : db .NewTeamAttributionID (uuid .New ().String ()),
436- CreationTime : common_db .NewVarCharTime (time .Now ()),
436+ CreationTime : db .NewVarCharTime (time .Now ()),
437437SpendingLimit : 0 ,
438438BillingStrategy : db .CostCenter_Other ,
439- NextBillingTime : common_db .NewVarCharTime (ts ),
439+ NextBillingTime : db .NewVarCharTime (ts ),
440440}
441441newCC , err := mnr .ResetUsage (context .Background (), oldCC )
442442require .NoError (t , err )
0 commit comments