@@ -3,201 +3,53 @@ package cli_test
3
3
import (
4
4
"bytes"
5
5
"context"
6
- "encoding/json"
7
- "os"
8
6
"path/filepath"
9
7
"testing"
10
8
11
- "github.com/stretchr/testify/assert"
12
9
"github.com/stretchr/testify/require"
13
10
14
11
"github.com/coder/coder/cli/clitest"
15
12
"github.com/coder/coder/coderd/coderdtest"
16
- "github.com/coder/coder/codersdk"
17
13
"github.com/coder/coder/pty/ptytest"
18
- "github.com/coder/coder/scaletest/harness"
19
14
"github.com/coder/coder/testutil"
20
15
)
21
16
22
17
func TestScaleTestCreateWorkspaces (t * testing.T ) {
23
- t .Skipf ("This test is flakey. See https://github.com/coder/coder/issues/4942" )
24
18
t .Parallel ()
25
19
26
- // This test does a create-workspaces scale test with --no-cleanup, checks
27
- // that the created resources are OK, and then runs a cleanup.
28
- t .Run ("WorkspaceBuildNoCleanup" , func (t * testing.T ) {
29
- t .Parallel ()
30
-
31
- ctx , cancelFunc := context .WithTimeout (context .Background (), testutil .WaitLong )
32
- defer cancelFunc ()
33
-
34
- client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
35
- user := coderdtest .CreateFirstUser (t , client )
36
-
37
- version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
38
- coderdtest .AwaitTemplateVersionJob (t , client , version .ID )
39
- template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
40
-
41
- // Write a parameters file.
42
- tDir := t .TempDir ()
43
- paramsFile := filepath .Join (tDir , "params.yaml" )
44
- outputFile := filepath .Join (tDir , "output.json" )
45
-
46
- f , err := os .Create (paramsFile )
47
- require .NoError (t , err )
48
- defer f .Close ()
49
- _ , err = f .WriteString (`---
50
- param1: foo
51
- param2: true
52
- param3: 1
53
- ` )
54
- require .NoError (t , err )
55
- err = f .Close ()
56
- require .NoError (t , err )
57
-
58
- inv , root := clitest .New (t , "scaletest" , "create-workspaces" ,
59
- "--count" , "2" ,
60
- "--template" , template .Name ,
61
- "--parameters-file" , paramsFile ,
62
- "--parameter" , "param1=bar" ,
63
- "--parameter" , "param4=baz" ,
64
- "--no-cleanup" ,
65
- // This flag is important for tests because agents will never be
66
- // started.
67
- "--no-wait-for-agents" ,
68
- // Run and connect flags cannot be tested because they require an
69
- // agent.
70
- "--concurrency" , "2" ,
71
- "--timeout" , "30s" ,
72
- "--job-timeout" , "15s" ,
73
- "--cleanup-concurrency" , "1" ,
74
- "--cleanup-timeout" , "30s" ,
75
- "--cleanup-job-timeout" , "15s" ,
76
- "--output" , "text" ,
77
- "--output" , "json:" + outputFile ,
78
- )
79
- clitest .SetupConfig (t , client , root )
80
- pty := ptytest .New (t )
81
- inv .Stdout = pty .Output ()
82
- inv .Stderr = pty .Output ()
83
-
84
- done := make (chan any )
85
- go func () {
86
- err := inv .WithContext (ctx ).Run ()
87
- assert .NoError (t , err )
88
- close (done )
89
- }()
90
- pty .ExpectMatch ("Test results:" )
91
- pty .ExpectMatch ("Pass: 2" )
92
- select {
93
- case <- done :
94
- case <- ctx .Done ():
95
- }
96
- cancelFunc ()
97
- <- done
98
-
99
- // Recreate the context.
100
- ctx , cancelFunc = context .WithTimeout (context .Background (), testutil .WaitLong )
101
- defer cancelFunc ()
102
-
103
- // Verify the output file.
104
- f , err = os .Open (outputFile )
105
- require .NoError (t , err )
106
- defer f .Close ()
107
- var res harness.Results
108
- err = json .NewDecoder (f ).Decode (& res )
109
- require .NoError (t , err )
110
-
111
- require .EqualValues (t , 2 , res .TotalRuns )
112
- require .EqualValues (t , 2 , res .TotalPass )
113
-
114
- // Find the workspaces and users and check that they are what we expect.
115
- workspaces , err := client .Workspaces (ctx , codersdk.WorkspaceFilter {
116
- Offset : 0 ,
117
- Limit : 100 ,
118
- })
119
- require .NoError (t , err )
120
- require .Len (t , workspaces .Workspaces , 2 )
121
-
122
- seenUsers := map [string ]struct {}{}
123
- for _ , w := range workspaces .Workspaces {
124
- // Sadly we can't verify params as the API doesn't seem to return
125
- // them.
126
-
127
- // Verify that the user is a unique scaletest user.
128
- u , err := client .User (ctx , w .OwnerID .String ())
129
- require .NoError (t , err )
130
-
131
- _ , ok := seenUsers [u .ID .String ()]
132
- require .False (t , ok , "user has more than one workspace" )
133
- seenUsers [u .ID .String ()] = struct {}{}
134
-
135
- require .Contains (t , u .Username , "scaletest-" )
136
- require .Contains (t , u .Email , "scaletest" )
137
- }
138
-
139
- require .Len (t , seenUsers , len (workspaces .Workspaces ))
140
-
141
- // Check that there are exactly 3 users.
142
- users , err := client .Users (ctx , codersdk.UsersRequest {
143
- Pagination : codersdk.Pagination {
144
- Offset : 0 ,
145
- Limit : 100 ,
146
- },
147
- })
148
- require .NoError (t , err )
149
- require .Len (t , users .Users , len (seenUsers )+ 1 )
150
-
151
- // Cleanup.
152
- inv , root = clitest .New (t , "scaletest" , "cleanup" ,
153
- "--cleanup-concurrency" , "1" ,
154
- "--cleanup-timeout" , "30s" ,
155
- "--cleanup-job-timeout" , "15s" ,
156
- )
157
- clitest .SetupConfig (t , client , root )
158
- pty = ptytest .New (t )
159
- inv .Stdout = pty .Output ()
160
- inv .Stderr = pty .Output ()
161
-
162
- done = make (chan any )
163
- go func () {
164
- err := inv .WithContext (ctx ).Run ()
165
- assert .NoError (t , err )
166
- close (done )
167
- }()
168
- pty .ExpectMatch ("Test results:" )
169
- pty .ExpectMatch ("Pass: 2" )
170
- pty .ExpectMatch ("Test results:" )
171
- pty .ExpectMatch ("Pass: 2" )
172
- select {
173
- case <- done :
174
- case <- ctx .Done ():
175
- }
176
- cancelFunc ()
177
- <- done
20
+ // This test only validates that the CLI command accepts known arguments.
21
+ // More thorough testing is done in scaletest/createworkspaces/run_test.go.
22
+ ctx , cancelFunc := context .WithTimeout (context .Background (), testutil .WaitLong )
23
+ defer cancelFunc ()
178
24
179
- // Recreate the context (again).
180
- ctx , cancelFunc = context .WithTimeout (context .Background (), testutil .WaitLong )
181
- defer cancelFunc ()
25
+ client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
26
+ _ = coderdtest .CreateFirstUser (t , client )
182
27
183
- // Verify that the workspaces are gone.
184
- workspaces , err = client .Workspaces (ctx , codersdk.WorkspaceFilter {
185
- Offset : 0 ,
186
- Limit : 100 ,
187
- })
188
- require .NoError (t , err )
189
- require .Len (t , workspaces .Workspaces , 0 )
28
+ // Write a parameters file.
29
+ tDir := t .TempDir ()
30
+ outputFile := filepath .Join (tDir , "output.json" )
31
+
32
+ inv , root := clitest .New (t , "scaletest" , "create-workspaces" ,
33
+ "--count" , "2" ,
34
+ "--template" , "doesnotexist" ,
35
+ "--no-cleanup" ,
36
+ "--no-wait-for-agents" ,
37
+ "--concurrency" , "2" ,
38
+ "--timeout" , "30s" ,
39
+ "--job-timeout" , "15s" ,
40
+ "--cleanup-concurrency" , "1" ,
41
+ "--cleanup-timeout" , "30s" ,
42
+ "--cleanup-job-timeout" , "15s" ,
43
+ "--output" , "text" ,
44
+ "--output" , "json:" + outputFile ,
45
+ )
46
+ clitest .SetupConfig (t , client , root )
47
+ pty := ptytest .New (t )
48
+ inv .Stdout = pty .Output ()
49
+ inv .Stderr = pty .Output ()
190
50
191
- // Verify that the users are gone.
192
- users , err = client .Users (ctx , codersdk.UsersRequest {
193
- Pagination : codersdk.Pagination {
194
- Offset : 0 ,
195
- Limit : 100 ,
196
- },
197
- })
198
- require .NoError (t , err )
199
- require .Len (t , users .Users , 1 )
200
- })
51
+ err := inv .WithContext (ctx ).Run ()
52
+ require .ErrorContains (t , err , "could not find template \" doesnotexist\" in any organization" )
201
53
}
202
54
203
55
// This test just validates that the CLI command accepts its known arguments.
0 commit comments