(t *testing.T)
| 3570 | } |
| 3571 | |
| 3572 | func TestCountConnectionLogs(t *testing.T) { |
| 3573 | t.Parallel() |
| 3574 | ctx := testutil.Context(t, testutil.WaitLong) |
| 3575 | |
| 3576 | db, _ := dbtestutil.NewDB(t) |
| 3577 | |
| 3578 | orgA := dbfake.Organization(t, db).Do() |
| 3579 | userA := dbgen.User(t, db, database.User{}) |
| 3580 | tplA := dbgen.Template(t, db, database.Template{OrganizationID: orgA.Org.ID, CreatedBy: userA.ID}) |
| 3581 | wsA := dbgen.Workspace(t, db, database.WorkspaceTable{OwnerID: userA.ID, OrganizationID: orgA.Org.ID, TemplateID: tplA.ID}) |
| 3582 | |
| 3583 | orgB := dbfake.Organization(t, db).Do() |
| 3584 | userB := dbgen.User(t, db, database.User{}) |
| 3585 | tplB := dbgen.Template(t, db, database.Template{OrganizationID: orgB.Org.ID, CreatedBy: userB.ID}) |
| 3586 | wsB := dbgen.Workspace(t, db, database.WorkspaceTable{OwnerID: userB.ID, OrganizationID: orgB.Org.ID, TemplateID: tplB.ID}) |
| 3587 | |
| 3588 | // Create logs for two different orgs. |
| 3589 | for i := 0; i < 20; i++ { |
| 3590 | dbgen.ConnectionLog(t, db, database.UpsertConnectionLogParams{ |
| 3591 | OrganizationID: wsA.OrganizationID, |
| 3592 | WorkspaceOwnerID: wsA.OwnerID, |
| 3593 | WorkspaceID: wsA.ID, |
| 3594 | Type: database.ConnectionTypeSsh, |
| 3595 | }) |
| 3596 | } |
| 3597 | for i := 0; i < 10; i++ { |
| 3598 | dbgen.ConnectionLog(t, db, database.UpsertConnectionLogParams{ |
| 3599 | OrganizationID: wsB.OrganizationID, |
| 3600 | WorkspaceOwnerID: wsB.OwnerID, |
| 3601 | WorkspaceID: wsB.ID, |
| 3602 | Type: database.ConnectionTypeSsh, |
| 3603 | }) |
| 3604 | } |
| 3605 | |
| 3606 | // Count with a filter for orgA. |
| 3607 | countParams := database.CountConnectionLogsParams{ |
| 3608 | OrganizationID: orgA.Org.ID, |
| 3609 | } |
| 3610 | totalCount, err := db.CountConnectionLogs(ctx, countParams) |
| 3611 | require.NoError(t, err) |
| 3612 | require.Equal(t, int64(20), totalCount) |
| 3613 | |
| 3614 | // Get a paginated result for the same filter. |
| 3615 | getParams := database.GetConnectionLogsOffsetParams{ |
| 3616 | OrganizationID: orgA.Org.ID, |
| 3617 | LimitOpt: 5, |
| 3618 | OffsetOpt: 10, |
| 3619 | } |
| 3620 | logs, err := db.GetConnectionLogsOffset(ctx, getParams) |
| 3621 | require.NoError(t, err) |
| 3622 | require.Len(t, logs, 5) |
| 3623 | |
| 3624 | // The count with the filter should remain the same, independent of pagination. |
| 3625 | countAfterGet, err := db.CountConnectionLogs(ctx, countParams) |
| 3626 | require.NoError(t, err) |
| 3627 | require.Equal(t, int64(20), countAfterGet) |
| 3628 | } |
| 3629 |
nothing calls this directly
no test coverage detected