@@ -12,6 +12,8 @@ import (
12
12
"github.com/coder/coder/v2/cli/clitest"
13
13
"github.com/coder/coder/v2/coderd/coderdtest"
14
14
"github.com/coder/coder/v2/coderd/database/dbauthz"
15
+ "github.com/coder/coder/v2/coderd/database/dbtestutil"
16
+ "github.com/coder/coder/v2/coderd/rbac"
15
17
"github.com/coder/coder/v2/codersdk"
16
18
"github.com/coder/coder/v2/pty/ptytest"
17
19
"github.com/coder/coder/v2/testutil"
@@ -164,4 +166,46 @@ func TestDelete(t *testing.T) {
164
166
}()
165
167
<- doneChan
166
168
})
169
+
170
+ t .Run ("WarnNoProvisioners" ,func (t * testing.T ) {
171
+ t .Parallel ()
172
+ if ! dbtestutil .WillUsePostgres () {
173
+ t .Skip ("this test requires postgres" )
174
+ }
175
+
176
+ store ,ps ,db := dbtestutil .NewDBWithSQLDB (t )
177
+ client ,closeDaemon := coderdtest .NewWithProvisionerCloser (t ,& coderdtest.Options {
178
+ Database :store ,
179
+ Pubsub :ps ,
180
+ IncludeProvisionerDaemon :true ,
181
+ })
182
+
183
+ // Given: a user, template, and workspace
184
+ user := coderdtest .CreateFirstUser (t ,client )
185
+ templateAdmin ,_ := coderdtest .CreateAnotherUser (t ,client ,user .OrganizationID ,rbac .RoleTemplateAdmin ())
186
+ version := coderdtest .CreateTemplateVersion (t ,templateAdmin ,user .OrganizationID ,nil )
187
+ template := coderdtest .CreateTemplate (t ,templateAdmin ,user .OrganizationID ,version .ID )
188
+ workspace := coderdtest .CreateWorkspace (t ,templateAdmin ,template .ID )
189
+ coderdtest .AwaitWorkspaceBuildJobCompleted (t ,templateAdmin ,workspace .LatestBuild .ID )
190
+
191
+ // When: all provisioner daemons disappear
192
+ require .NoError (t ,closeDaemon .Close ())
193
+ _ ,err := db .Exec ("DELETE FROM provisioner_daemons;" )
194
+ require .NoError (t ,err )
195
+
196
+ // Then: the workspace deletion should warn about no provisioners
197
+ inv ,root := clitest .New (t ,"delete" ,workspace .Name ,"-y" )
198
+ pty := ptytest .New (t ).Attach (inv )
199
+ clitest .SetupConfig (t ,templateAdmin ,root )
200
+ doneChan := make (chan struct {})
201
+ ctx ,cancel := context .WithTimeout (context .Background (),testutil .WaitLong )
202
+ defer cancel ()
203
+ go func () {
204
+ defer close (doneChan )
205
+ _ = inv .WithContext (ctx ).Run ()
206
+ }()
207
+ pty .ExpectMatch ("there are no provisioners that accept the required tags" )
208
+ cancel ()
209
+ <- doneChan
210
+ })
167
211
}