Skip to content

Commit 2e61335

Browse files
committed
improve testing logic
1 parent 8c6ffc1 commit 2e61335

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

provider/agent.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,13 @@ func agentResource() *schema.Resource {
277277
Type: schema.TypeBool,
278278
Description: "Enable memory monitoring for this agent.",
279279
ForceNew: true,
280-
Optional: true,
281-
Default: true,
280+
Required: true,
282281
},
283282
"threshold": {
284283
Type: schema.TypeInt,
285284
Description: "The memory usage threshold in percentage at which to trigger an alert. Value should be between 0 and 100.",
286285
ForceNew: true,
287-
Optional: true,
286+
Required: true,
288287
},
289288
},
290289
},
@@ -300,20 +299,19 @@ func agentResource() *schema.Resource {
300299
Type: schema.TypeString,
301300
Description: "The path of the volume to monitor.",
302301
ForceNew: true,
303-
Optional: true,
302+
Required: true,
304303
},
305304
"enabled": {
306305
Type: schema.TypeBool,
307306
Description: "Enable volume monitoring for this agent.",
308307
ForceNew: true,
309-
Optional: true,
310-
Default: true,
308+
Required: true,
311309
},
312310
"threshold": {
313311
Type: schema.TypeInt,
314312
Description: "The volume usage threshold in percentage at which to trigger an alert. Value should be between 0 and 100.",
315313
ForceNew: true,
316-
Optional: true,
314+
Required: true,
317315
},
318316
},
319317
},

provider/agent_test.go

+39
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,45 @@ func TestAgent_ResourcesMonitoring(t *testing.T) {
264264
})
265265
}
266266

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+
}
285+
}
286+
}`,
287+
Check: func(state *terraform.State) error {
288+
require.Len(t, state.Modules, 1)
289+
require.Len(t, state.Modules[0].Resources, 1)
290+
291+
resource := state.Modules[0].Resources["coder_agent.dev"]
292+
require.NotNil(t, resource)
293+
294+
t.Logf("resource: %v", resource.Primary.Attributes)
295+
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+
})
304+
}
305+
267306
func TestAgent_MetadataDuplicateKeys(t *testing.T) {
268307
t.Parallel()
269308
resource.Test(t, resource.TestCase{

0 commit comments

Comments
 (0)