@@ -281,41 +281,35 @@ func (s *MethodTestSuite) TestAPIKey() {
281
281
}
282
282
283
283
func (s * MethodTestSuite ) TestAuditLogs () {
284
- s .Run ("InsertAuditLog" , s .Subtest (func (db database.Store , check * expects ) {
285
- check .Args (database.InsertAuditLogParams {
286
- ResourceType : database .ResourceTypeOrganization ,
287
- Action : database .AuditActionCreate ,
288
- Diff : json .RawMessage ("{}" ),
289
- AdditionalFields : json .RawMessage ("{}" ),
290
- }).Asserts (rbac .ResourceAuditLog , policy .ActionCreate )
291
- }))
292
- s .Run ("GetAuditLogsOffset" , s .Subtest (func (db database.Store , check * expects ) {
293
- _ = dbgen .AuditLog (s .T (), db , database.AuditLog {})
294
- _ = dbgen .AuditLog (s .T (), db , database.AuditLog {})
295
- check .Args (database.GetAuditLogsOffsetParams {
296
- LimitOpt : 10 ,
297
- }).Asserts (rbac .ResourceAuditLog , policy .ActionRead ).WithNotAuthorized ("nil" )
298
- }))
299
- s .Run ("GetAuthorizedAuditLogsOffset" , s .Subtest (func (db database.Store , check * expects ) {
300
- dbtestutil .DisableForeignKeysAndTriggers (s .T (), db )
301
- _ = dbgen .AuditLog (s .T (), db , database.AuditLog {})
302
- _ = dbgen .AuditLog (s .T (), db , database.AuditLog {})
303
- check .Args (database.GetAuditLogsOffsetParams {
304
- LimitOpt : 10 ,
305
- }, emptyPreparedAuthorized {}).Asserts (rbac .ResourceAuditLog , policy .ActionRead )
306
- }))
307
- s .Run ("CountAuditLogs" , s .Subtest (func (db database.Store , check * expects ) {
308
- _ = dbgen .AuditLog (s .T (), db , database.AuditLog {})
309
- _ = dbgen .AuditLog (s .T (), db , database.AuditLog {})
284
+ s .Run ("InsertAuditLog" , s .Mocked (func (dbm * dbmock.MockStore , _ * gofakeit.Faker , check * expects ) {
285
+ arg := database.InsertAuditLogParams {ResourceType : database .ResourceTypeOrganization , Action : database .AuditActionCreate , Diff : json .RawMessage ("{}" ), AdditionalFields : json .RawMessage ("{}" )}
286
+ dbm .EXPECT ().InsertAuditLog (gomock .Any (), arg ).Return (database.AuditLog {}, nil ).AnyTimes ()
287
+ check .Args (arg ).Asserts (rbac .ResourceAuditLog , policy .ActionCreate )
288
+ }))
289
+ s .Run ("GetAuditLogsOffset" , s .Mocked (func (dbm * dbmock.MockStore , _ * gofakeit.Faker , check * expects ) {
290
+ arg := database.GetAuditLogsOffsetParams {LimitOpt : 10 }
291
+ dbm .EXPECT ().GetAuditLogsOffset (gomock .Any (), arg ).Return ([]database.GetAuditLogsOffsetRow {}, nil ).AnyTimes ()
292
+ dbm .EXPECT ().GetAuthorizedAuditLogsOffset (gomock .Any (), arg , gomock .Any ()).Return ([]database.GetAuditLogsOffsetRow {}, nil ).AnyTimes ()
293
+ check .Args (arg ).Asserts (rbac .ResourceAuditLog , policy .ActionRead ).WithNotAuthorized ("nil" )
294
+ }))
295
+ s .Run ("GetAuthorizedAuditLogsOffset" , s .Mocked (func (dbm * dbmock.MockStore , _ * gofakeit.Faker , check * expects ) {
296
+ arg := database.GetAuditLogsOffsetParams {LimitOpt : 10 }
297
+ dbm .EXPECT ().GetAuthorizedAuditLogsOffset (gomock .Any (), arg , gomock .Any ()).Return ([]database.GetAuditLogsOffsetRow {}, nil ).AnyTimes ()
298
+ dbm .EXPECT ().GetAuditLogsOffset (gomock .Any (), arg ).Return ([]database.GetAuditLogsOffsetRow {}, nil ).AnyTimes ()
299
+ check .Args (arg , emptyPreparedAuthorized {}).Asserts (rbac .ResourceAuditLog , policy .ActionRead )
300
+ }))
301
+ s .Run ("CountAuditLogs" , s .Mocked (func (dbm * dbmock.MockStore , _ * gofakeit.Faker , check * expects ) {
302
+ dbm .EXPECT ().CountAuditLogs (gomock .Any (), database.CountAuditLogsParams {}).Return (int64 (0 ), nil ).AnyTimes ()
303
+ dbm .EXPECT ().CountAuthorizedAuditLogs (gomock .Any (), database.CountAuditLogsParams {}, gomock .Any ()).Return (int64 (0 ), nil ).AnyTimes ()
310
304
check .Args (database.CountAuditLogsParams {}).Asserts (rbac .ResourceAuditLog , policy .ActionRead ).WithNotAuthorized ("nil" )
311
305
}))
312
- s .Run ("CountAuthorizedAuditLogs" , s .Subtest (func (db database. Store , check * expects ) {
313
- _ = dbgen . AuditLog ( s . T ( ), db , database.AuditLog {} )
314
- _ = dbgen . AuditLog ( s . T ( ), db , database.AuditLog {} )
306
+ s .Run ("CountAuthorizedAuditLogs" , s .Mocked (func (dbm * dbmock. MockStore , _ * gofakeit. Faker , check * expects ) {
307
+ dbm . EXPECT (). CountAuthorizedAuditLogs ( gomock . Any ( ), database.CountAuditLogsParams {}, gomock . Any ()). Return ( int64 ( 0 ), nil ). AnyTimes ( )
308
+ dbm . EXPECT (). CountAuditLogs ( gomock . Any ( ), database.CountAuditLogsParams {}). Return ( int64 ( 0 ), nil ). AnyTimes ( )
315
309
check .Args (database.CountAuditLogsParams {}, emptyPreparedAuthorized {}).Asserts (rbac .ResourceAuditLog , policy .ActionRead )
316
310
}))
317
- s .Run ("DeleteOldAuditLogConnectionEvents" , s .Subtest (func (db database. Store , check * expects ) {
318
- _ = dbgen . AuditLog ( s . T ( ), db , database.AuditLog {} )
311
+ s .Run ("DeleteOldAuditLogConnectionEvents" , s .Mocked (func (dbm * dbmock. MockStore , _ * gofakeit. Faker , check * expects ) {
312
+ dbm . EXPECT (). DeleteOldAuditLogConnectionEvents ( gomock . Any ( ), database.DeleteOldAuditLogConnectionEventsParams {}). Return ( nil ). AnyTimes ( )
319
313
check .Args (database.DeleteOldAuditLogConnectionEventsParams {}).Asserts (rbac .ResourceSystem , policy .ActionDelete )
320
314
}))
321
315
}
0 commit comments