Skip to content

Commit d9a1497

Browse files
authored
Merge pull request #5868 from cf-ainesh/ainesh/load_balancer_monitor/add-more-tests
add load_balancer_monitor acceptance tests
2 parents 158b4a5 + 3652382 commit d9a1497

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

internal/services/load_balancer_monitor/resource_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ func TestAccCloudflareLoadBalancerMonitor_Basic(t *testing.T) {
7979
resource.TestCheckResourceAttr(name, "header.%", "0"),
8080
// also expect api to generate some values
8181
testAccCheckCloudflareLoadBalancerMonitorDates(name, &loadBalancerMonitor, testStartTime),
82+
resource.TestCheckResourceAttr(name, "port", "0"),
83+
resource.TestCheckResourceAttr(name, "consecutive_up", "0"),
84+
resource.TestCheckResourceAttr(name, "consecutive_down", "0"),
8285
),
8386
},
8487
},
@@ -261,6 +264,71 @@ func TestAccCloudflareLoadBalancerMonitor_Update(t *testing.T) {
261264
})
262265
}
263266

267+
func TestAccCloudflareLoadBalancerMonitor_ConsecutiveUpDownDrift(t *testing.T) {
268+
accountID := os.Getenv("CLOUDFLARE_ACCOUNT_ID")
269+
rnd := utils.GenerateRandomResourceName()
270+
name := "cloudflare_load_balancer_monitor." + rnd
271+
var loadBalancerMonitor cloudflare.LoadBalancerMonitor
272+
273+
resource.Test(t, resource.TestCase{
274+
PreCheck: func() { acctest.TestAccPreCheck(t) },
275+
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
276+
CheckDestroy: testAccCheckCloudflareLoadBalancerMonitorDestroy,
277+
Steps: []resource.TestStep{
278+
{
279+
Config: testAccCheckCloudflareLoadBalancerMonitorConfigWithConsecutiveValues(rnd, accountID),
280+
Check: resource.ComposeTestCheckFunc(
281+
testAccCheckCloudflareLoadBalancerMonitorExists(name, &loadBalancerMonitor),
282+
resource.TestCheckResourceAttr(name, consts.AccountIDSchemaKey, accountID),
283+
resource.TestCheckResourceAttr(name, "consecutive_up", "0"),
284+
resource.TestCheckResourceAttr(name, "consecutive_down", "0"),
285+
resource.TestCheckResourceAttr(name, "port", "0"),
286+
),
287+
},
288+
{
289+
Config: testAccCheckCloudflareLoadBalancerMonitorConfigWithConsecutiveValues(rnd, accountID),
290+
ExpectNonEmptyPlan: false,
291+
},
292+
},
293+
})
294+
}
295+
296+
func TestAccCloudflareLoadBalancerMonitor_NonZeroConsecutiveValuesDrift(t *testing.T) {
297+
accountID := os.Getenv("CLOUDFLARE_ACCOUNT_ID")
298+
rnd := utils.GenerateRandomResourceName()
299+
name := "cloudflare_load_balancer_monitor." + rnd
300+
var loadBalancerMonitor cloudflare.LoadBalancerMonitor
301+
302+
resource.Test(t, resource.TestCase{
303+
PreCheck: func() { acctest.TestAccPreCheck(t) },
304+
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
305+
CheckDestroy: testAccCheckCloudflareLoadBalancerMonitorDestroy,
306+
Steps: []resource.TestStep{
307+
{
308+
Config: testAccCheckCloudflareLoadBalancerMonitorConfigWithNonZeroConsecutiveValues(rnd, accountID, "Initial description"),
309+
Check: resource.ComposeTestCheckFunc(
310+
testAccCheckCloudflareLoadBalancerMonitorExists(name, &loadBalancerMonitor),
311+
resource.TestCheckResourceAttr(name, consts.AccountIDSchemaKey, accountID),
312+
resource.TestCheckResourceAttr(name, "consecutive_up", "2"),
313+
resource.TestCheckResourceAttr(name, "consecutive_down", "2"),
314+
resource.TestCheckResourceAttr(name, "port", "8080"),
315+
resource.TestCheckResourceAttr(name, "description", "Initial description"),
316+
),
317+
},
318+
{
319+
Config: testAccCheckCloudflareLoadBalancerMonitorConfigWithNonZeroConsecutiveValues(rnd, accountID, "Updated description"),
320+
Check: resource.ComposeTestCheckFunc(
321+
testAccCheckCloudflareLoadBalancerMonitorExists(name, &loadBalancerMonitor),
322+
resource.TestCheckResourceAttr(name, "description", "Updated description"),
323+
resource.TestCheckResourceAttr(name, "consecutive_up", "2"),
324+
resource.TestCheckResourceAttr(name, "consecutive_down", "2"),
325+
resource.TestCheckResourceAttr(name, "port", "8080"),
326+
),
327+
},
328+
},
329+
})
330+
}
331+
264332
func TestAccCloudflareLoadBalancerMonitor_ChangingHeadersCauseReplacement(t *testing.T) {
265333
domain := os.Getenv("CLOUDFLARE_DOMAIN")
266334
accountID := os.Getenv("CLOUDFLARE_ACCOUNT_ID")
@@ -395,6 +463,14 @@ func testAccCheckCloudflareLoadBalancerMonitorConfigSMTP(resourceName, accountID
395463
return acctest.LoadTestCase("loadbalancermonitorconfigsmtp.tf", resourceName, accountID)
396464
}
397465

466+
func testAccCheckCloudflareLoadBalancerMonitorConfigWithConsecutiveValues(rnd, accountID string) string {
467+
return acctest.LoadTestCase("loadbalancermonitorconfigwithconsecutivevalues.tf", rnd, accountID)
468+
}
469+
470+
func testAccCheckCloudflareLoadBalancerMonitorConfigWithNonZeroConsecutiveValues(rnd, accountID, description string) string {
471+
return acctest.LoadTestCase("loadbalancermonitorconfigwithnonzeroconsecutivevalues.tf", rnd, accountID, description)
472+
}
473+
398474
func testAccCheckCloudflareLoadBalancerMonitorConfigMissingRequired(accountID string) string {
399475
return acctest.LoadTestCase("loadbalancermonitorconfigmissingrequired.tf", accountID)
400476
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
resource "cloudflare_load_balancer_monitor" "%s" {
2+
account_id = "%s"
3+
type = "http"
4+
method = "GET"
5+
path = "/"
6+
expected_codes = "200"
7+
consecutive_up = 0
8+
consecutive_down = 0
9+
port = 0
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
resource "cloudflare_load_balancer_monitor" "%s" {
2+
account_id = "%s"
3+
type = "http"
4+
method = "GET"
5+
path = "/"
6+
expected_codes = "200"
7+
description = "%s"
8+
# Non-zero values for consecutive_up, consecutive_down, and port
9+
consecutive_up = 2
10+
consecutive_down = 2
11+
port = 8080
12+
}

0 commit comments

Comments
 (0)