@@ -822,6 +822,33 @@ func TestOffsetLimit(t *testing.T) {
822
822
require .Len (t , ws , 0 )
823
823
}
824
824
825
+ func TestWorkspaceCount (t * testing.T ) {
826
+ t .Parallel ()
827
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
828
+ defer cancel ()
829
+ client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
830
+ user := coderdtest .CreateFirstUser (t , client )
831
+ version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
832
+ coderdtest .AwaitTemplateVersionJob (t , client , version .ID )
833
+ template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
834
+ template2 := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
835
+ _ = coderdtest .CreateWorkspace (t , client , user .OrganizationID , template .ID )
836
+ _ = coderdtest .CreateWorkspace (t , client , user .OrganizationID , template2 .ID )
837
+ _ = coderdtest .CreateWorkspace (t , client , user .OrganizationID , template2 .ID )
838
+
839
+ response , err := client .WorkspaceCount (ctx , codersdk.WorkspaceCountRequest {})
840
+ require .NoError (t , err , "fetch workspace count" )
841
+ // counts all
842
+ require .Equal (t , int (response .Count ), 3 )
843
+
844
+ response2 , err2 := client .WorkspaceCount (ctx , codersdk.WorkspaceCountRequest {
845
+ SearchQuery : fmt .Sprintf ("template:%s" , template .Name ),
846
+ })
847
+ require .NoError (t , err2 , "fetch workspace count" )
848
+ // counts only those that pass filter
849
+ require .Equal (t , int (response2 .Count ), 1 )
850
+ }
851
+
825
852
func TestPostWorkspaceBuild (t * testing.T ) {
826
853
t .Parallel ()
827
854
t .Run ("NoTemplateVersion" , func (t * testing.T ) {
0 commit comments