(t *testing.T)
| 594 | } |
| 595 | |
| 596 | func TestSearchConnectionLogs(t *testing.T) { |
| 597 | t.Parallel() |
| 598 | t.Run("All", func(t *testing.T) { |
| 599 | t.Parallel() |
| 600 | |
| 601 | orgID := uuid.New() |
| 602 | workspaceOwnerID := uuid.New() |
| 603 | workspaceID := uuid.New() |
| 604 | connectionID := uuid.New() |
| 605 | |
| 606 | db, _ := dbtestutil.NewDB(t) |
| 607 | dbgen.Organization(t, db, database.Organization{ |
| 608 | ID: orgID, |
| 609 | Name: "testorg", |
| 610 | }) |
| 611 | dbgen.User(t, db, database.User{ |
| 612 | ID: workspaceOwnerID, |
| 613 | Username: "testowner", |
| 614 | Email: "owner@example.com", |
| 615 | }) |
| 616 | |
| 617 | query := fmt.Sprintf(`organization:testorg workspace_owner:testowner `+ |
| 618 | `workspace_owner_email:owner@example.com type:port_forwarding username:testuser `+ |
| 619 | `user_email:test@example.com connected_after:"2023-01-01T00:00:00Z" `+ |
| 620 | `connected_before:"2023-01-16T12:00:00+12:00" workspace_id:%s connection_id:%s status:ongoing`, |
| 621 | workspaceID.String(), connectionID.String()) |
| 622 | |
| 623 | values, _, errs := searchquery.ConnectionLogs(context.Background(), db, query, database.APIKey{}) |
| 624 | require.Len(t, errs, 0) |
| 625 | |
| 626 | expected := database.GetConnectionLogsOffsetParams{ |
| 627 | OrganizationID: orgID, |
| 628 | WorkspaceOwner: "testowner", |
| 629 | WorkspaceOwnerEmail: "owner@example.com", |
| 630 | Type: string(database.ConnectionTypePortForwarding), |
| 631 | Username: "testuser", |
| 632 | UserEmail: "test@example.com", |
| 633 | ConnectedAfter: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC), |
| 634 | ConnectedBefore: time.Date(2023, 1, 16, 0, 0, 0, 0, time.UTC), |
| 635 | WorkspaceID: workspaceID, |
| 636 | ConnectionID: connectionID, |
| 637 | Status: string(codersdk.ConnectionLogStatusOngoing), |
| 638 | } |
| 639 | |
| 640 | require.Equal(t, expected, values) |
| 641 | }) |
| 642 | |
| 643 | t.Run("Me", func(t *testing.T) { |
| 644 | t.Parallel() |
| 645 | |
| 646 | userID := uuid.New() |
| 647 | db, _ := dbtestutil.NewDB(t) |
| 648 | |
| 649 | query := `username:me workspace_owner:me` |
| 650 | values, _, errs := searchquery.ConnectionLogs(context.Background(), db, query, database.APIKey{UserID: userID}) |
| 651 | require.Len(t, errs, 0) |
| 652 | |
| 653 | expected := database.GetConnectionLogsOffsetParams{ |
nothing calls this directly
no test coverage detected