@@ -479,55 +479,49 @@ func TestAdminViewAllWorkspaces(t *testing.T) {
479
479
func TestWorkspacesSortOrder (t * testing.T ) {
480
480
t .Parallel ()
481
481
482
- client := coderdtest .New (t ,& coderdtest. Options { IncludeProvisionerDaemon : true } )
482
+ client , db := coderdtest .NewWithDatabase (t ,nil )
483
483
firstUser := coderdtest .CreateFirstUser (t ,client )
484
- version := coderdtest .CreateTemplateVersion (t ,client ,firstUser .OrganizationID ,nil )
485
- coderdtest .AwaitTemplateVersionJobCompleted (t ,client ,version .ID )
486
- template := coderdtest .CreateTemplate (t ,client ,firstUser .OrganizationID ,version .ID )
487
484
488
485
// c-workspace should be running
489
- workspace1 := coderdtest .CreateWorkspace (t ,client ,firstUser .OrganizationID ,template .ID ,func (ctr * codersdk.CreateWorkspaceRequest ) {
490
- ctr .Name = "c-workspace"
491
- })
492
- coderdtest .AwaitWorkspaceBuildJobCompleted (t ,client ,workspace1 .LatestBuild .ID )
486
+ wsb1 := dbfake .WorkspaceBuild (t ,db , database.Workspace {Name :"c-workspace" ,OwnerID :firstUser .UserID ,OrganizationID :firstUser .OrganizationID }).Do ()
493
487
494
488
// b-workspace should be stopped
495
- workspace2 := coderdtest .CreateWorkspace (t ,client ,firstUser .OrganizationID ,template .ID ,func (ctr * codersdk.CreateWorkspaceRequest ) {
496
- ctr .Name = "b-workspace"
497
- })
498
- coderdtest .AwaitWorkspaceBuildJobCompleted (t ,client ,workspace2 .LatestBuild .ID )
499
-
500
- build2 := coderdtest .CreateWorkspaceBuild (t ,client ,workspace2 ,database .WorkspaceTransitionStop )
501
- coderdtest .AwaitWorkspaceBuildJobCompleted (t ,client ,build2 .ID )
489
+ wsb2 := dbfake .WorkspaceBuild (t ,db , database.Workspace {Name :"b-workspace" ,OwnerID :firstUser .UserID ,OrganizationID :firstUser .OrganizationID }).Seed (database.WorkspaceBuild {Transition :database .WorkspaceTransitionStop }).Do ()
502
490
503
491
// a-workspace should be running
504
- workspace3 := coderdtest .CreateWorkspace (t ,client ,firstUser .OrganizationID ,template .ID ,func (ctr * codersdk.CreateWorkspaceRequest ) {
505
- ctr .Name = "a-workspace"
506
- })
507
- coderdtest .AwaitWorkspaceBuildJobCompleted (t ,client ,workspace3 .LatestBuild .ID )
492
+ wsb3 := dbfake .WorkspaceBuild (t ,db , database.Workspace {Name :"a-workspace" ,OwnerID :firstUser .UserID ,OrganizationID :firstUser .OrganizationID }).Do ()
508
493
509
494
ctx ,cancel := context .WithTimeout (context .Background (),testutil .WaitLong )
510
495
defer cancel ()
511
496
workspacesResponse ,err := client .Workspaces (ctx , codersdk.WorkspaceFilter {})
512
497
require .NoError (t ,err ,"(first) fetch workspaces" )
513
498
workspaces := workspacesResponse .Workspaces
514
499
515
- expected := []string {
516
- workspace3 .Name ,
517
- workspace1 .Name ,
518
- workspace2 .Name ,
500
+ expectedNames := []string {
501
+ wsb3 .Workspace .Name ,
502
+ wsb1 .Workspace .Name ,
503
+ wsb2 .Workspace .Name ,
504
+ }
505
+
506
+ expectedStatus := []codersdk.WorkspaceStatus {
507
+ codersdk .WorkspaceStatusRunning ,
508
+ codersdk .WorkspaceStatusRunning ,
509
+ codersdk .WorkspaceStatusStopped ,
519
510
}
520
511
521
- var actual []string
512
+ var actualNames []string
513
+ var actualStatus []codersdk.WorkspaceStatus
522
514
for _ ,w := range workspaces {
523
- actual = append (actual ,w .Name )
515
+ actualNames = append (actualNames ,w .Name )
516
+ actualStatus = append (actualStatus ,w .LatestBuild .Status )
524
517
}
525
518
526
519
// the correct sorting order is:
527
520
// 1. Running workspaces
528
521
// 2. Sort by usernames
529
522
// 3. Sort by workspace names
530
- require .Equal (t ,expected ,actual )
523
+ assert .Equal (t ,expectedNames ,actualNames )
524
+ assert .Equal (t ,expectedStatus ,actualStatus )
531
525
}
532
526
533
527
func TestPostWorkspacesByOrganization (t * testing.T ) {