@@ -14,6 +14,76 @@ import (
14
14
"github.com/stretchr/testify/require"
15
15
)
16
16
17
+ func TestAdminWorkspaces_ListWithFilter (t * testing.T ) {
18
+ client := testClient (t )
19
+ ctx := context .Background ()
20
+
21
+ org , orgCleanup := createOrganization (t , client )
22
+ defer orgCleanup ()
23
+
24
+ wTest1 , wTest1Cleanup := createWorkspace (t , client , org )
25
+ defer wTest1Cleanup ()
26
+
27
+ wTest2 , wTest2Cleanup := createWorkspace (t , client , org )
28
+ defer wTest2Cleanup ()
29
+
30
+ t .Run ("when filtering workspaces on a current run status" , func (t * testing.T ) {
31
+ _ , appliedCleanup := createRunApply (t , client , wTest1 )
32
+ t .Cleanup (appliedCleanup )
33
+
34
+ _ , unAppliedCleanup := createRunUnapplied (t , client , wTest2 )
35
+ t .Cleanup (unAppliedCleanup )
36
+
37
+ wl , err := client .Admin .Workspaces .List (ctx , & AdminWorkspaceListOptions {
38
+ Filter : string (RunApplied ), Include : []AdminWorkspaceIncludeOpt {AdminWorkspaceCurrentRun },
39
+ })
40
+
41
+ require .NoError (t , err )
42
+ require .NotEmpty (t , wl .Items )
43
+ assert .Equal (t , wl .Items [0 ].CurrentRun .Status , RunApplied )
44
+ assert .NotContains (t , wl .Items , wTest2 )
45
+ })
46
+ }
47
+
48
+ func TestAdminWorkspaces_ListWithSort (t * testing.T ) {
49
+ client := testClient (t )
50
+ ctx := context .Background ()
51
+
52
+ org , orgCleanup := createOrganization (t , client )
53
+ defer orgCleanup ()
54
+
55
+ wTest1 , wTest1Cleanup := createWorkspace (t , client , org )
56
+ defer wTest1Cleanup ()
57
+
58
+ wTest2 , wTest2Cleanup := createWorkspace (t , client , org )
59
+ defer wTest2Cleanup ()
60
+
61
+ t .Run ("when sorting by workspace names" , func (t * testing.T ) {
62
+ wl , err := client .Admin .Workspaces .List (ctx , & AdminWorkspaceListOptions {
63
+ Sort : "name" ,
64
+ })
65
+ require .NoError (t , err )
66
+ require .NotEmpty (t , wl .Items )
67
+ assert .Equal (t , adminWorkspaceItemsContainsID (wl .Items , wTest1 .ID ), true )
68
+ })
69
+
70
+ t .Run ("when sorting workspaces on current-run.created-at" , func (t * testing.T ) {
71
+ _ , unappliedCleanup1 := createRunUnapplied (t , client , wTest1 )
72
+ t .Cleanup (unappliedCleanup1 )
73
+
74
+ _ , unappliedCleanup2 := createRunUnapplied (t , client , wTest2 )
75
+ t .Cleanup (unappliedCleanup2 )
76
+
77
+ wl , err := client .Admin .Workspaces .List (ctx , & AdminWorkspaceListOptions {
78
+ Sort : "current-run.created-at" ,
79
+ })
80
+
81
+ require .NoError (t , err )
82
+ require .NotEmpty (t , wl .Items )
83
+ require .GreaterOrEqual (t , len (wl .Items ), 2 )
84
+ })
85
+ }
86
+
17
87
func TestAdminWorkspaces_List (t * testing.T ) {
18
88
skipUnlessEnterprise (t )
19
89
@@ -97,6 +167,8 @@ func TestAdminWorkspaces_List(t *testing.T) {
97
167
assert .NotEmpty (t , wl .Items [0 ].Organization .Name )
98
168
})
99
169
170
+ // This sub-test should remain last because it creates a run that does not apply
171
+ // Any subsequent runs will be queued until a timeout is triggered
100
172
t .Run ("with current_run included" , func (t * testing.T ) {
101
173
cvTest , cvCleanup := createUploadedConfigurationVersion (t , client , wTest1 )
102
174
defer cvCleanup ()
0 commit comments