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
+ "github.com/gitpod-io/gitpod/common-go/db"
13
+ "github.com/gitpod-io/gitpod/common-go/db/dbtest"
15
14
"github.com/google/uuid"
16
15
"github.com/stretchr/testify/require"
17
16
"google.golang.org/grpc/codes"
@@ -73,28 +72,28 @@ func TestCostCenterManager_GetOrCreateCostCenter_ResetsExpired(t *testing.T) {
73
72
74
73
expiredCC := db.CostCenter {
75
74
ID : db .NewTeamAttributionID (uuid .New ().String ()),
76
- CreationTime : common_db .NewVarCharTime (now ),
75
+ CreationTime : db .NewVarCharTime (now ),
77
76
SpendingLimit : 0 ,
78
77
BillingStrategy : db .CostCenter_Other ,
79
- NextBillingTime : common_db .NewVarCharTime (expired ),
80
- BillingCycleStart : common_db .NewVarCharTime (now ),
78
+ NextBillingTime : db .NewVarCharTime (expired ),
79
+ BillingCycleStart : db .NewVarCharTime (now ),
81
80
}
82
81
unexpiredCC := db.CostCenter {
83
82
ID : db .NewUserAttributionID (uuid .New ().String ()),
84
- CreationTime : common_db .NewVarCharTime (now ),
83
+ CreationTime : db .NewVarCharTime (now ),
85
84
SpendingLimit : 500 ,
86
85
BillingStrategy : db .CostCenter_Other ,
87
- NextBillingTime : common_db .NewVarCharTime (unexpired ),
88
- BillingCycleStart : common_db .NewVarCharTime (now ),
86
+ NextBillingTime : db .NewVarCharTime (unexpired ),
87
+ BillingCycleStart : db .NewVarCharTime (now ),
89
88
}
90
89
// Stripe billing strategy should not be reset
91
90
stripeCC := db.CostCenter {
92
91
ID : db .NewUserAttributionID (uuid .New ().String ()),
93
- CreationTime : common_db .NewVarCharTime (now ),
92
+ CreationTime : db .NewVarCharTime (now ),
94
93
SpendingLimit : 0 ,
95
94
BillingStrategy : db .CostCenter_Stripe ,
96
- NextBillingTime : common_db .VarcharTime {},
97
- BillingCycleStart : common_db .NewVarCharTime (now ),
95
+ NextBillingTime : db .VarcharTime {},
96
+ BillingCycleStart : db .NewVarCharTime (now ),
98
97
}
99
98
100
99
dbtest .CreateCostCenters (t , conn ,
@@ -109,15 +108,15 @@ func TestCostCenterManager_GetOrCreateCostCenter_ResetsExpired(t *testing.T) {
109
108
t .Cleanup (func () {
110
109
conn .Model (& db.CostCenter {}).Delete (retrievedExpiredCC .ID )
111
110
})
112
- require .Equal (t , common_db .NewVarCharTime (expired ).Time ().AddDate (0 , 1 , 0 ), retrievedExpiredCC .NextBillingTime .Time ())
111
+ require .Equal (t , db .NewVarCharTime (expired ).Time ().AddDate (0 , 1 , 0 ), retrievedExpiredCC .NextBillingTime .Time ())
113
112
require .Equal (t , expiredCC .ID , retrievedExpiredCC .ID )
114
113
require .Equal (t , expiredCC .BillingStrategy , retrievedExpiredCC .BillingStrategy )
115
114
require .WithinDuration (t , now , expiredCC .CreationTime .Time (), 3 * time .Second , "new cost center creation time must be within 3 seconds of now" )
116
115
117
116
// unexpired cost center must not be reset
118
117
retrievedUnexpiredCC , err := mnr .GetOrCreateCostCenter (context .Background (), unexpiredCC .ID )
119
118
require .NoError (t , err )
120
- require .Equal (t , common_db .NewVarCharTime (unexpired ).Time (), retrievedUnexpiredCC .NextBillingTime .Time ())
119
+ require .Equal (t , db .NewVarCharTime (unexpired ).Time (), retrievedUnexpiredCC .NextBillingTime .Time ())
121
120
require .Equal (t , unexpiredCC .ID , retrievedUnexpiredCC .ID )
122
121
require .Equal (t , unexpiredCC .BillingStrategy , retrievedUnexpiredCC .BillingStrategy )
123
122
require .WithinDuration (t , unexpiredCC .CreationTime .Time (), retrievedUnexpiredCC .CreationTime .Time (), 100 * time .Millisecond )
@@ -289,7 +288,7 @@ func TestSaveCostCenterMovedToStripe(t *testing.T) {
289
288
teamCC , err = mnr .UpdateCostCenter (context .Background (), teamCC )
290
289
require .NoError (t , err )
291
290
require .Equal (t , db .CostCenter_Stripe , teamCC .BillingStrategy )
292
- require .Equal (t , common_db .VarcharTime {}, teamCC .NextBillingTime )
291
+ require .Equal (t , db .VarcharTime {}, teamCC .NextBillingTime )
293
292
require .Equal (t , int32 (400050 ), teamCC .SpendingLimit )
294
293
295
294
teamCC .BillingStrategy = db .CostCenter_Other
@@ -349,16 +348,16 @@ func TestCostCenter_ListLatestCostCentersWithBillingTimeBefore(t *testing.T) {
349
348
dbtest .NewCostCenter (t , db.CostCenter {
350
349
ID : db .NewTeamAttributionID (attributionID ),
351
350
SpendingLimit : 100 ,
352
- CreationTime : common_db .NewVarCharTime (firstCreation ),
351
+ CreationTime : db .NewVarCharTime (firstCreation ),
353
352
BillingStrategy : db .CostCenter_Other ,
354
- NextBillingTime : common_db .NewVarCharTime (firstCreation ),
353
+ NextBillingTime : db .NewVarCharTime (firstCreation ),
355
354
}),
356
355
dbtest .NewCostCenter (t , db.CostCenter {
357
356
ID : db .NewTeamAttributionID (attributionID ),
358
357
SpendingLimit : 100 ,
359
- CreationTime : common_db .NewVarCharTime (secondCreation ),
358
+ CreationTime : db .NewVarCharTime (secondCreation ),
360
359
BillingStrategy : db .CostCenter_Other ,
361
- NextBillingTime : common_db .NewVarCharTime (secondCreation ),
360
+ NextBillingTime : db .NewVarCharTime (secondCreation ),
362
361
}),
363
362
}
364
363
@@ -386,14 +385,14 @@ func TestCostCenter_ListLatestCostCentersWithBillingTimeBefore(t *testing.T) {
386
385
dbtest .NewCostCenter (t , db.CostCenter {
387
386
ID : db .NewTeamAttributionID (attributionID ),
388
387
SpendingLimit : 100 ,
389
- CreationTime : common_db .NewVarCharTime (firstCreation ),
388
+ CreationTime : db .NewVarCharTime (firstCreation ),
390
389
BillingStrategy : db .CostCenter_Other ,
391
- NextBillingTime : common_db .NewVarCharTime (firstCreation ),
390
+ NextBillingTime : db .NewVarCharTime (firstCreation ),
392
391
}),
393
392
dbtest .NewCostCenter (t , db.CostCenter {
394
393
ID : db .NewTeamAttributionID (attributionID ),
395
394
SpendingLimit : 100 ,
396
- CreationTime : common_db .NewVarCharTime (secondCreation ),
395
+ CreationTime : db .NewVarCharTime (secondCreation ),
397
396
BillingStrategy : db .CostCenter_Stripe ,
398
397
}),
399
398
}
@@ -418,7 +417,7 @@ func TestCostCenterManager_ResetUsage(t *testing.T) {
418
417
})
419
418
_ , err := mnr .ResetUsage (context .Background (), db.CostCenter {
420
419
ID : db .NewUserAttributionID (uuid .New ().String ()),
421
- CreationTime : common_db .NewVarCharTime (time .Now ()),
420
+ CreationTime : db .NewVarCharTime (time .Now ()),
422
421
SpendingLimit : 500 ,
423
422
BillingStrategy : db .CostCenter_Stripe ,
424
423
})
@@ -433,10 +432,10 @@ func TestCostCenterManager_ResetUsage(t *testing.T) {
433
432
})
434
433
oldCC := db.CostCenter {
435
434
ID : db .NewTeamAttributionID (uuid .New ().String ()),
436
- CreationTime : common_db .NewVarCharTime (time .Now ()),
435
+ CreationTime : db .NewVarCharTime (time .Now ()),
437
436
SpendingLimit : 0 ,
438
437
BillingStrategy : db .CostCenter_Other ,
439
- NextBillingTime : common_db .NewVarCharTime (ts ),
438
+ NextBillingTime : db .NewVarCharTime (ts ),
440
439
}
441
440
newCC , err := mnr .ResetUsage (context .Background (), oldCC )
442
441
require .NoError (t , err )
0 commit comments