9
9
"testing"
10
10
"time"
11
11
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"
15
15
"github.com/google/uuid"
16
16
"github.com/stretchr/testify/require"
17
17
"google.golang.org/grpc/codes"
@@ -73,28 +73,28 @@ func TestCostCenterManager_GetOrCreateCostCenter_ResetsExpired(t *testing.T) {
73
73
74
74
expiredCC := db.CostCenter {
75
75
ID : db .NewTeamAttributionID (uuid .New ().String ()),
76
- CreationTime : common_db .NewVarCharTime (now ),
76
+ CreationTime : db .NewVarCharTime (now ),
77
77
SpendingLimit : 0 ,
78
78
BillingStrategy : 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 ),
81
81
}
82
82
unexpiredCC := db.CostCenter {
83
83
ID : db .NewUserAttributionID (uuid .New ().String ()),
84
- CreationTime : common_db .NewVarCharTime (now ),
84
+ CreationTime : db .NewVarCharTime (now ),
85
85
SpendingLimit : 500 ,
86
86
BillingStrategy : 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 ),
89
89
}
90
90
// Stripe billing strategy should not be reset
91
91
stripeCC := db.CostCenter {
92
92
ID : db .NewUserAttributionID (uuid .New ().String ()),
93
- CreationTime : common_db .NewVarCharTime (now ),
93
+ CreationTime : db .NewVarCharTime (now ),
94
94
SpendingLimit : 0 ,
95
95
BillingStrategy : db .CostCenter_Stripe ,
96
- NextBillingTime : common_db .VarcharTime {},
97
- BillingCycleStart : common_db .NewVarCharTime (now ),
96
+ NextBillingTime : db .VarcharTime {},
97
+ BillingCycleStart : db .NewVarCharTime (now ),
98
98
}
99
99
100
100
dbtest .CreateCostCenters (t , conn ,
@@ -103,21 +103,21 @@ func TestCostCenterManager_GetOrCreateCostCenter_ResetsExpired(t *testing.T) {
103
103
dbtest .NewCostCenter (t , stripeCC ),
104
104
)
105
105
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
107
107
retrievedExpiredCC , err := mnr .GetOrCreateCostCenter (context .Background (), expiredCC .ID )
108
108
require .NoError (t , err )
109
109
t .Cleanup (func () {
110
110
conn .Model (& db.CostCenter {}).Delete (retrievedExpiredCC .ID )
111
111
})
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 ())
113
113
require .Equal (t , expiredCC .ID , retrievedExpiredCC .ID )
114
114
require .Equal (t , expiredCC .BillingStrategy , retrievedExpiredCC .BillingStrategy )
115
115
require .WithinDuration (t , now , expiredCC .CreationTime .Time (), 3 * time .Second , "new cost center creation time must be within 3 seconds of now" )
116
116
117
117
// unexpired cost center must not be reset
118
118
retrievedUnexpiredCC , err := mnr .GetOrCreateCostCenter (context .Background (), unexpiredCC .ID )
119
119
require .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 ())
121
121
require .Equal (t , unexpiredCC .ID , retrievedUnexpiredCC .ID )
122
122
require .Equal (t , unexpiredCC .BillingStrategy , retrievedUnexpiredCC .BillingStrategy )
123
123
require .WithinDuration (t , unexpiredCC .CreationTime .Time (), retrievedUnexpiredCC .CreationTime .Time (), 100 * time .Millisecond )
@@ -341,16 +341,16 @@ func TestCostCenter_ListLatestCostCentersWithBillingTimeBefore(t *testing.T) {
341
341
dbtest .NewCostCenter (t , db.CostCenter {
342
342
ID : db .NewTeamAttributionID (attributionID ),
343
343
SpendingLimit : 100 ,
344
- CreationTime : common_db .NewVarCharTime (firstCreation ),
344
+ CreationTime : db .NewVarCharTime (firstCreation ),
345
345
BillingStrategy : db .CostCenter_Other ,
346
- NextBillingTime : common_db .NewVarCharTime (firstCreation ),
346
+ NextBillingTime : db .NewVarCharTime (firstCreation ),
347
347
}),
348
348
dbtest .NewCostCenter (t , db.CostCenter {
349
349
ID : db .NewTeamAttributionID (attributionID ),
350
350
SpendingLimit : 100 ,
351
- CreationTime : common_db .NewVarCharTime (secondCreation ),
351
+ CreationTime : db .NewVarCharTime (secondCreation ),
352
352
BillingStrategy : db .CostCenter_Other ,
353
- NextBillingTime : common_db .NewVarCharTime (secondCreation ),
353
+ NextBillingTime : db .NewVarCharTime (secondCreation ),
354
354
}),
355
355
}
356
356
@@ -378,14 +378,14 @@ func TestCostCenter_ListLatestCostCentersWithBillingTimeBefore(t *testing.T) {
378
378
dbtest .NewCostCenter (t , db.CostCenter {
379
379
ID : db .NewTeamAttributionID (attributionID ),
380
380
SpendingLimit : 100 ,
381
- CreationTime : common_db .NewVarCharTime (firstCreation ),
381
+ CreationTime : db .NewVarCharTime (firstCreation ),
382
382
BillingStrategy : db .CostCenter_Other ,
383
- NextBillingTime : common_db .NewVarCharTime (firstCreation ),
383
+ NextBillingTime : db .NewVarCharTime (firstCreation ),
384
384
}),
385
385
dbtest .NewCostCenter (t , db.CostCenter {
386
386
ID : db .NewTeamAttributionID (attributionID ),
387
387
SpendingLimit : 100 ,
388
- CreationTime : common_db .NewVarCharTime (secondCreation ),
388
+ CreationTime : db .NewVarCharTime (secondCreation ),
389
389
BillingStrategy : db .CostCenter_Stripe ,
390
390
}),
391
391
}
@@ -410,7 +410,7 @@ func TestCostCenterManager_ResetUsage(t *testing.T) {
410
410
})
411
411
_ , err := mnr .ResetUsage (context .Background (), db.CostCenter {
412
412
ID : db .NewUserAttributionID (uuid .New ().String ()),
413
- CreationTime : common_db .NewVarCharTime (time .Now ()),
413
+ CreationTime : db .NewVarCharTime (time .Now ()),
414
414
SpendingLimit : 500 ,
415
415
BillingStrategy : db .CostCenter_Stripe ,
416
416
})
@@ -425,10 +425,10 @@ func TestCostCenterManager_ResetUsage(t *testing.T) {
425
425
})
426
426
oldCC := db.CostCenter {
427
427
ID : db .NewTeamAttributionID (uuid .New ().String ()),
428
- CreationTime : common_db .NewVarCharTime (time .Now ()),
428
+ CreationTime : db .NewVarCharTime (time .Now ()),
429
429
SpendingLimit : 0 ,
430
430
BillingStrategy : db .CostCenter_Other ,
431
- NextBillingTime : common_db .NewVarCharTime (ts ),
431
+ NextBillingTime : db .NewVarCharTime (ts ),
432
432
}
433
433
newCC , err := mnr .ResetUsage (context .Background (), oldCC )
434
434
require .NoError (t , err )
0 commit comments