@@ -405,47 +405,68 @@ func TestSearchAudit(t *testing.T) {
405
405
406
406
func TestSearchConnectionLogs (t * testing.T ) {
407
407
t .Parallel ()
408
+ t .Run ("All" , func (t * testing.T ) {
409
+ t .Parallel ()
408
410
409
- orgID := uuid .New ()
410
- workspaceOwnerID := uuid .New ()
411
- workspaceID := uuid .New ()
412
- connectionID := uuid .New ()
411
+ orgID := uuid .New ()
412
+ workspaceOwnerID := uuid .New ()
413
+ workspaceID := uuid .New ()
414
+ connectionID := uuid .New ()
413
415
414
- db , _ := dbtestutil .NewDB (t )
415
- dbgen .Organization (t , db , database.Organization {
416
- ID : orgID ,
417
- Name : "testorg" ,
418
- })
419
- dbgen .User (t , db , database.User {
420
- ID : workspaceOwnerID ,
421
- Username : "testowner" ,
422
- Email : "owner@example.com" ,
416
+ db , _ := dbtestutil .NewDB (t )
417
+ dbgen .Organization (t , db , database.Organization {
418
+ ID : orgID ,
419
+ Name : "testorg" ,
420
+ })
421
+ dbgen .User (t , db , database.User {
422
+ ID : workspaceOwnerID ,
423
+ Username : "testowner" ,
424
+ Email : "owner@example.com" ,
425
+ })
426
+
427
+ query := fmt .Sprintf (`organization:testorg workspace_owner:testowner ` +
428
+ `workspace_owner_email:owner@example.com type:port_forwarding username:testuser ` +
429
+ `user_email:test@example.com started_after:"2023-01-01T00:00:00Z" ` +
430
+ `started_before:"2023-01-16T12:00:00+12:00" workspace_id:%s connection_id:%s status:connected` ,
431
+ workspaceID .String (), connectionID .String ())
432
+
433
+ values , errs := searchquery .ConnectionLogs (context .Background (), db , query , database.APIKey {})
434
+ require .Len (t , errs , 0 )
435
+
436
+ expected := database.GetConnectionLogsOffsetParams {
437
+ OrganizationID : orgID ,
438
+ WorkspaceOwner : "testowner" ,
439
+ WorkspaceOwnerEmail : "owner@example.com" ,
440
+ Type : string (database .ConnectionTypePortForwarding ),
441
+ Username : "testuser" ,
442
+ UserEmail : "test@example.com" ,
443
+ StartedAfter : time .Date (2023 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
444
+ StartedBefore : time .Date (2023 , 1 , 16 , 0 , 0 , 0 , 0 , time .UTC ),
445
+ WorkspaceID : workspaceID ,
446
+ ConnectionID : connectionID ,
447
+ Status : string (database .ConnectionStatusConnected ),
448
+ }
449
+
450
+ require .Equal (t , expected , values )
423
451
})
424
452
425
- query := fmt . Sprintf ( `organization:testorg workspace_owner:testowner ` +
426
- `workspace_owner_email:owner@example.com type:port_forwarding username:testuser ` +
427
- `user_email:test@example.com started_after:"2023-01-01T00:00:00Z" ` +
428
- `started_before:"2023-01-16T12:00:00+12:00" workspace_id:%s connection_id:%s status:connected` ,
429
- workspaceID . String (), connectionID . String () )
453
+ t . Run ( "Me" , func ( t * testing. T ) {
454
+ t . Parallel ()
455
+
456
+ userID := uuid . New ()
457
+ db , _ := dbtestutil . NewDB ( t )
430
458
431
- values , errs := searchquery .ConnectionLogs (context .Background (), db , query )
432
- require .Len (t , errs , 0 )
459
+ query := `username:me workspace_owner:me`
460
+ values , errs := searchquery .ConnectionLogs (context .Background (), db , query , database.APIKey {UserID : userID })
461
+ require .Len (t , errs , 0 )
433
462
434
- expected := database.GetConnectionLogsOffsetParams {
435
- OrganizationID : orgID ,
436
- WorkspaceOwner : "testowner" ,
437
- WorkspaceOwnerEmail : "owner@example.com" ,
438
- Type : string (database .ConnectionTypePortForwarding ),
439
- Username : "testuser" ,
440
- UserEmail : "test@example.com" ,
441
- StartedAfter : time .Date (2023 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
442
- StartedBefore : time .Date (2023 , 1 , 16 , 0 , 0 , 0 , 0 , time .UTC ),
443
- WorkspaceID : workspaceID ,
444
- ConnectionID : connectionID ,
445
- Status : string (database .ConnectionStatusConnected ),
446
- }
463
+ expected := database.GetConnectionLogsOffsetParams {
464
+ UserID : userID ,
465
+ WorkspaceOwnerID : userID ,
466
+ }
447
467
448
- require .Equal (t , expected , values )
468
+ require .Equal (t , expected , values )
469
+ })
449
470
}
450
471
451
472
func TestSearchUsers (t * testing.T ) {
0 commit comments