@@ -1322,6 +1322,20 @@ func TestWorkspaceFilter(t *testing.T) {
1322
1322
func TestWorkspaceFilterManual (t * testing.T ) {
1323
1323
t .Parallel ()
1324
1324
1325
+ expectIDs := func (t * testing.T , exp []codersdk.Workspace , got []codersdk.Workspace ) {
1326
+ t .Helper ()
1327
+ expIDs := make ([]uuid.UUID , 0 , len (exp ))
1328
+ for _ , e := range exp {
1329
+ expIDs = append (expIDs , e .ID )
1330
+ }
1331
+
1332
+ gotIDs := make ([]uuid.UUID , 0 , len (got ))
1333
+ for _ , g := range got {
1334
+ gotIDs = append (gotIDs , g .ID )
1335
+ }
1336
+ require .ElementsMatchf (t , expIDs , gotIDs , "expected IDs" )
1337
+ }
1338
+
1325
1339
t .Run ("Name" , func (t * testing.T ) {
1326
1340
t .Parallel ()
1327
1341
client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
@@ -1593,7 +1607,6 @@ func TestWorkspaceFilterManual(t *testing.T) {
1593
1607
return workspaces .Count == 1
1594
1608
}, testutil .IntervalMedium , "agent status timeout" )
1595
1609
})
1596
-
1597
1610
t .Run ("Dormant" , func (t * testing.T ) {
1598
1611
// this test has a licensed counterpart in enterprise/coderd/workspaces_test.go: FilterQueryHasDeletingByAndLicensed
1599
1612
t .Parallel ()
@@ -1640,7 +1653,6 @@ func TestWorkspaceFilterManual(t *testing.T) {
1640
1653
require .Equal (t , dormantWorkspace .ID , res .Workspaces [0 ].ID )
1641
1654
require .NotNil (t , res .Workspaces [0 ].DormantAt )
1642
1655
})
1643
-
1644
1656
t .Run ("LastUsed" , func (t * testing.T ) {
1645
1657
t .Parallel ()
1646
1658
@@ -1747,6 +1759,169 @@ func TestWorkspaceFilterManual(t *testing.T) {
1747
1759
require .Len (t , res .Workspaces , 1 )
1748
1760
require .Equal (t , workspace .ID , res .Workspaces [0 ].ID )
1749
1761
})
1762
+ t .Run ("Params" , func (t * testing.T ) {
1763
+ t .Parallel ()
1764
+
1765
+ const (
1766
+ paramOneName = "one"
1767
+ paramTwoName = "two"
1768
+ paramThreeName = "three"
1769
+ paramOptional = "optional"
1770
+ )
1771
+
1772
+ makeParameters := func (extra ... * proto.RichParameter ) * echo.Responses {
1773
+ return & echo.Responses {
1774
+ Parse : echo .ParseComplete ,
1775
+ ProvisionPlan : []* proto.Response {
1776
+ {
1777
+ Type : & proto.Response_Plan {
1778
+ Plan : & proto.PlanComplete {
1779
+ Parameters : append ([]* proto.RichParameter {
1780
+ {Name : paramOneName , Description : "" , Mutable : true , Type : "string" },
1781
+ {Name : paramTwoName , DisplayName : "" , Description : "" , Mutable : true , Type : "string" },
1782
+ {Name : paramThreeName , Description : "" , Mutable : true , Type : "string" },
1783
+ }, extra ... ),
1784
+ },
1785
+ },
1786
+ },
1787
+ },
1788
+ ProvisionApply : echo .ApplyComplete ,
1789
+ }
1790
+ }
1791
+
1792
+ client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
1793
+ user := coderdtest .CreateFirstUser (t , client )
1794
+ version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , makeParameters (& proto.RichParameter {Name : paramOptional , Description : "" , Mutable : true , Type : "string" }))
1795
+ coderdtest .AwaitTemplateVersionJobCompleted (t , client , version .ID )
1796
+ template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
1797
+ noOptionalVersion := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , makeParameters (), func (request * codersdk.CreateTemplateVersionRequest ) {
1798
+ request .TemplateID = template .ID
1799
+ })
1800
+ coderdtest .AwaitTemplateVersionJobCompleted (t , client , noOptionalVersion .ID )
1801
+
1802
+ // foo :: one=foo, two=bar, one=baz, optional=optional
1803
+ foo := coderdtest .CreateWorkspace (t , client , user .OrganizationID , uuid .Nil , func (request * codersdk.CreateWorkspaceRequest ) {
1804
+ request .TemplateVersionID = version .ID
1805
+ request .RichParameterValues = []codersdk.WorkspaceBuildParameter {
1806
+ {
1807
+ Name : paramOneName ,
1808
+ Value : "foo" ,
1809
+ },
1810
+ {
1811
+ Name : paramTwoName ,
1812
+ Value : "bar" ,
1813
+ },
1814
+ {
1815
+ Name : paramThreeName ,
1816
+ Value : "baz" ,
1817
+ },
1818
+ {
1819
+ Name : paramOptional ,
1820
+ Value : "optional" ,
1821
+ },
1822
+ }
1823
+ })
1824
+
1825
+ // bar :: one=foo, two=bar, three=baz, optional=optional
1826
+ bar := coderdtest .CreateWorkspace (t , client , user .OrganizationID , uuid .Nil , func (request * codersdk.CreateWorkspaceRequest ) {
1827
+ request .TemplateVersionID = version .ID
1828
+ request .RichParameterValues = []codersdk.WorkspaceBuildParameter {
1829
+ {
1830
+ Name : paramOneName ,
1831
+ Value : "bar" ,
1832
+ },
1833
+ {
1834
+ Name : paramTwoName ,
1835
+ Value : "bar" ,
1836
+ },
1837
+ {
1838
+ Name : paramThreeName ,
1839
+ Value : "baz" ,
1840
+ },
1841
+ {
1842
+ Name : paramOptional ,
1843
+ Value : "optional" ,
1844
+ },
1845
+ }
1846
+ })
1847
+
1848
+ // baz :: one=baz, two=baz, three=baz
1849
+ baz := coderdtest .CreateWorkspace (t , client , user .OrganizationID , uuid .Nil , func (request * codersdk.CreateWorkspaceRequest ) {
1850
+ request .TemplateVersionID = noOptionalVersion .ID
1851
+ request .RichParameterValues = []codersdk.WorkspaceBuildParameter {
1852
+ {
1853
+ Name : paramOneName ,
1854
+ Value : "unique" ,
1855
+ },
1856
+ {
1857
+ Name : paramTwoName ,
1858
+ Value : "baz" ,
1859
+ },
1860
+ {
1861
+ Name : paramThreeName ,
1862
+ Value : "baz" ,
1863
+ },
1864
+ }
1865
+ })
1866
+
1867
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
1868
+ defer cancel ()
1869
+
1870
+ //nolint:tparallel,paralleltest
1871
+ t .Run ("has_param" , func (t * testing.T ) {
1872
+ // Checks the existence of a param value
1873
+ // all match
1874
+ all , err := client .Workspaces (ctx , codersdk.WorkspaceFilter {
1875
+ FilterQuery : fmt .Sprintf ("param:%s" , paramOneName ),
1876
+ })
1877
+ require .NoError (t , err )
1878
+ expectIDs (t , []codersdk.Workspace {foo , bar , baz }, all .Workspaces )
1879
+
1880
+ // Some match
1881
+ optional , err := client .Workspaces (ctx , codersdk.WorkspaceFilter {
1882
+ FilterQuery : fmt .Sprintf ("param:%s" , paramOptional ),
1883
+ })
1884
+ require .NoError (t , err )
1885
+ expectIDs (t , []codersdk.Workspace {foo , bar }, optional .Workspaces )
1886
+
1887
+ // None match
1888
+ none , err := client .Workspaces (ctx , codersdk.WorkspaceFilter {
1889
+ FilterQuery : "param:not-a-param" ,
1890
+ })
1891
+ require .NoError (t , err )
1892
+ require .Len (t , none .Workspaces , 0 )
1893
+ })
1894
+
1895
+ //nolint:tparallel,paralleltest
1896
+ t .Run ("exact_param" , func (t * testing.T ) {
1897
+ all , err := client .Workspaces (ctx , codersdk.WorkspaceFilter {
1898
+ FilterQuery : fmt .Sprintf ("param:%s=%s" , paramThreeName , "baz" ),
1899
+ })
1900
+ require .NoError (t , err )
1901
+ expectIDs (t , []codersdk.Workspace {foo , bar , baz }, all .Workspaces )
1902
+
1903
+ two , err := client .Workspaces (ctx , codersdk.WorkspaceFilter {
1904
+ FilterQuery : fmt .Sprintf ("param:%s=%s" , paramTwoName , "bar" ),
1905
+ })
1906
+ require .NoError (t , err )
1907
+ expectIDs (t , []codersdk.Workspace {foo , bar }, two .Workspaces )
1908
+
1909
+ one , err := client .Workspaces (ctx , codersdk.WorkspaceFilter {
1910
+ FilterQuery : fmt .Sprintf ("param:%s=%s" , paramOneName , "foo" ),
1911
+ })
1912
+ require .NoError (t , err )
1913
+ expectIDs (t , []codersdk.Workspace {foo , bar }, one .Workspaces )
1914
+ })
1915
+
1916
+ //nolint:tparallel,paralleltest
1917
+ t .Run ("exact_param_and_has" , func (t * testing.T ) {
1918
+ all , err := client .Workspaces (ctx , codersdk.WorkspaceFilter {
1919
+ FilterQuery : fmt .Sprintf ("param:not=athing param:%s=%s param:%s=%s" , paramOptional , "optional" , paramOneName , "unique" ),
1920
+ })
1921
+ require .NoError (t , err )
1922
+ expectIDs (t , []codersdk.Workspace {foo , bar , baz }, all .Workspaces )
1923
+ })
1924
+ })
1750
1925
}
1751
1926
1752
1927
func TestOffsetLimit (t * testing.T ) {
0 commit comments