@@ -213,11 +213,13 @@ func TestAgent_Metadata(t *testing.T) {
213
213
214
214
func TestAgent_ResourcesMonitoring (t * testing.T ) {
215
215
t .Parallel ()
216
- resource .Test (t , resource.TestCase {
217
- ProviderFactories : coderFactory (),
218
- IsUnitTest : true ,
219
- Steps : []resource.TestStep {{
220
- Config : `
216
+
217
+ t .Run ("OK" , func (t * testing.T ) {
218
+ resource .Test (t , resource.TestCase {
219
+ ProviderFactories : coderFactory (),
220
+ IsUnitTest : true ,
221
+ Steps : []resource.TestStep {{
222
+ Config : `
221
223
provider "coder" {
222
224
url = "https://example.com"
223
225
}
@@ -241,65 +243,115 @@ func TestAgent_ResourcesMonitoring(t *testing.T) {
241
243
}
242
244
}
243
245
}` ,
244
- Check : func (state * terraform.State ) error {
245
- require .Len (t , state .Modules , 1 )
246
- require .Len (t , state .Modules [0 ].Resources , 1 )
247
-
248
- resource := state .Modules [0 ].Resources ["coder_agent.dev" ]
249
- require .NotNil (t , resource )
246
+ Check : func (state * terraform.State ) error {
247
+ require .Len (t , state .Modules , 1 )
248
+ require .Len (t , state .Modules [0 ].Resources , 1 )
250
249
251
- t .Logf ("resource: %v" , resource .Primary .Attributes )
250
+ resource := state .Modules [0 ].Resources ["coder_agent.dev" ]
251
+ require .NotNil (t , resource )
252
252
253
- attr := resource .Primary .Attributes
254
- require .Equal (t , "1" , attr ["resources_monitoring.#" ])
255
- require .Equal (t , "1" , attr ["resources_monitoring.0.memory.#" ])
256
- require .Equal (t , "2" , attr ["resources_monitoring.0.volume.#" ])
257
- require .Equal (t , "80" , attr ["resources_monitoring.0.memory.0.threshold" ])
258
- require .Equal (t , "/volume1" , attr ["resources_monitoring.0.volume.0.path" ])
259
- require .Equal (t , "100" , attr ["resources_monitoring.0.volume.1.threshold" ])
260
- require .Equal (t , "/volume2" , attr ["resources_monitoring.0.volume.1.path" ])
261
- return nil
262
- },
263
- }},
253
+ attr := resource .Primary .Attributes
254
+ require .Equal (t , "1" , attr ["resources_monitoring.#" ])
255
+ require .Equal (t , "1" , attr ["resources_monitoring.0.memory.#" ])
256
+ require .Equal (t , "2" , attr ["resources_monitoring.0.volume.#" ])
257
+ require .Equal (t , "80" , attr ["resources_monitoring.0.memory.0.threshold" ])
258
+ require .Equal (t , "/volume1" , attr ["resources_monitoring.0.volume.0.path" ])
259
+ require .Equal (t , "100" , attr ["resources_monitoring.0.volume.1.threshold" ])
260
+ require .Equal (t , "/volume2" , attr ["resources_monitoring.0.volume.1.path" ])
261
+ return nil
262
+ },
263
+ }},
264
+ })
264
265
})
265
- }
266
266
267
- func TestAgent_ResourcesMonitoring_OnlyMemory (t * testing.T ) {
268
- t .Parallel ()
269
- resource .Test (t , resource.TestCase {
270
- ProviderFactories : coderFactory (),
271
- IsUnitTest : true ,
272
- Steps : []resource.TestStep {{
273
- Config : `
274
- provider "coder" {
275
- url = "https://example.com"
276
- }
277
- resource "coder_agent" "dev" {
278
- os = "linux"
279
- arch = "amd64"
280
- resources_monitoring {
281
- memory {
282
- enabled = true
283
- threshold = 80
284
- }
267
+ t .Run ("OnlyMemory" , func (t * testing.T ) {
268
+ resource .Test (t , resource.TestCase {
269
+ ProviderFactories : coderFactory (),
270
+ IsUnitTest : true ,
271
+ Steps : []resource.TestStep {{
272
+ Config : `
273
+ provider "coder" {
274
+ url = "https://example.com"
285
275
}
286
- }` ,
287
- Check : func (state * terraform.State ) error {
288
- require .Len (t , state .Modules , 1 )
289
- require .Len (t , state .Modules [0 ].Resources , 1 )
276
+ resource "coder_agent" "dev" {
277
+ os = "linux"
278
+ arch = "amd64"
279
+ resources_monitoring {
280
+ memory {
281
+ enabled = true
282
+ threshold = 80
283
+ }
284
+ }
285
+ }` ,
286
+ Check : func (state * terraform.State ) error {
287
+ require .Len (t , state .Modules , 1 )
288
+ require .Len (t , state .Modules [0 ].Resources , 1 )
290
289
291
- resource := state .Modules [0 ].Resources ["coder_agent.dev" ]
292
- require .NotNil (t , resource )
290
+ resource := state .Modules [0 ].Resources ["coder_agent.dev" ]
291
+ require .NotNil (t , resource )
293
292
294
- t .Logf ("resource: %v" , resource .Primary .Attributes )
293
+ attr := resource .Primary .Attributes
294
+ require .Equal (t , "1" , attr ["resources_monitoring.#" ])
295
+ require .Equal (t , "1" , attr ["resources_monitoring.0.memory.#" ])
296
+ require .Equal (t , "80" , attr ["resources_monitoring.0.memory.0.threshold" ])
297
+ return nil
298
+ },
299
+ }},
300
+ })
301
+ })
295
302
296
- attr := resource .Primary .Attributes
297
- require .Equal (t , "1" , attr ["resources_monitoring.#" ])
298
- require .Equal (t , "1" , attr ["resources_monitoring.0.memory.#" ])
299
- require .Equal (t , "80" , attr ["resources_monitoring.0.memory.0.threshold" ])
300
- return nil
301
- },
302
- }},
303
+ t .Run ("InvalidThreshold" , func (t * testing.T ) {
304
+ resource .Test (t , resource.TestCase {
305
+ ProviderFactories : coderFactory (),
306
+ IsUnitTest : true ,
307
+ Steps : []resource.TestStep {{
308
+ Config : `
309
+ provider "coder" {
310
+ url = "https://example.com"
311
+ }
312
+ resource "coder_agent" "dev" {
313
+ os = "linux"
314
+ arch = "amd64"
315
+ resources_monitoring {
316
+ memory {
317
+ enabled = true
318
+ threshold = 101
319
+ }
320
+ }
321
+ }` ,
322
+ ExpectError : regexp .MustCompile ("threshold must be between 0 and 100" ),
323
+ }},
324
+ })
325
+ })
326
+
327
+ t .Run ("DuplicatePaths" , func (t * testing.T ) {
328
+ resource .Test (t , resource.TestCase {
329
+ ProviderFactories : coderFactory (),
330
+ IsUnitTest : true ,
331
+ Steps : []resource.TestStep {{
332
+ Config : `
333
+ provider "coder" {
334
+ url = "https://example.com"
335
+ }
336
+ resource "coder_agent" "dev" {
337
+ os = "linux"
338
+ arch = "amd64"
339
+ resources_monitoring {
340
+ volume {
341
+ path = "/volume1"
342
+ enabled = true
343
+ threshold = 80
344
+ }
345
+ volume {
346
+ path = "/volume1"
347
+ enabled = true
348
+ threshold = 100
349
+ }
350
+ }
351
+ }` ,
352
+ ExpectError : regexp .MustCompile ("duplicate volume path" ),
353
+ }},
354
+ })
303
355
})
304
356
}
305
357
0 commit comments