Repository: cloudflare/cloudflare-go
Pull request #1380 (2023-08-27 20:17:11)

Add Consecutive_up and Consecutive_down for load_balancer_monitor res…
## Description

We can set the consecutive_down and consecutive_up parameter values for the Cloudflare Load Balancer Monitor via [API](https://developers.cloudflare.com/api/operations/load-balancer-monitors-create-monitor ) but not via terraform.

[Issue from terraform-provider-cloudflare](https://github.com/cloudflare/terraform-provider-cloudflare/issues/1876)

## Has your change been tested?

Yes, relevant unit tests have been updated to handle the addition of this field. Additionally, changes were ran against the pre-existing test suite to verify that no regressions were introduced.

## Types of changes

What sort of change does your code introduce/modify?

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

## Checklist:

- [x] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [x] I have updated the documentation accordingly.
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.
- [x] This change is using publicly documented in [cloudflare/api-schemas](https://github.com/cloudflare/api-schemas) 
      and relies on stable APIs.

[1]: https://help.github.com/articles/closing-issues-using-keywords/



Patch:
diff --git a/.changelog/1380.txt b/.changelog/1380.txt
new file mode 100644
index 000000000..9c00e73ad
--- /dev/null
+++ b/.changelog/1380.txt
@@ -0,0 +1,3 @@
+```release-note:enhancement
+load_balancer_monitor: add support for `consecutive_up`, `consecutive_down`
+```
diff --git a/load_balancing.go b/load_balancing.go
index d23a2a961..8acf121fd 100644
--- a/load_balancing.go
+++ b/load_balancing.go
@@ -75,6 +75,8 @@ type LoadBalancerMonitor struct {
 	Timeout         int                 `json:"timeout"`
 	Retries         int                 `json:"retries"`
 	Interval        int                 `json:"interval"`
+	ConsecutiveUp   int                 `json:"consecutive_up"`
+	ConsecutiveDown int                 `json:"consecutive_down"`
 	Port            uint16              `json:"port,omitempty"`
 	ExpectedBody    string              `json:"expected_body"`
 	ExpectedCodes   string              `json:"expected_codes"`


Test patch:
diff --git a/load_balancing_test.go b/load_balancing_test.go
index 148746bbc..2b3d3ae6c 100644
--- a/load_balancing_test.go
+++ b/load_balancing_test.go
@@ -623,6 +623,8 @@ func TestCreateLoadBalancerMonitor(t *testing.T) {
               "timeout": 3,
               "retries": 0,
               "interval": 90,
+              "consecutive_up": 2,
+              "consecutive_down": 2,
               "expected_body": "alive",
               "expected_codes": "2xx",
               "follow_redirects": true,
@@ -653,6 +655,8 @@ func TestCreateLoadBalancerMonitor(t *testing.T) {
                 "timeout": 3,
                 "retries": 0,
                 "interval": 90,
+                "consecutive_up": 2,
+                "consecutive_down": 2,
                 "expected_body": "alive",
                 "expected_codes": "2xx",
                 "follow_redirects": true,
@@ -677,11 +681,13 @@ func TestCreateLoadBalancerMonitor(t *testing.T) {
 			"Host":     {"example.com"},
 			"X-App-ID": {"abc123"},
 		},
-		Timeout:       3,
-		Retries:       0,
-		Interval:      90,
-		ExpectedBody:  "alive",
-		ExpectedCodes: "2xx",
+		Timeout:         3,
+		Retries:         0,
+		Interval:        90,
+		ConsecutiveUp:   2,
+		ConsecutiveDown: 2,
+		ExpectedBody:    "alive",
+		ExpectedCodes:   "2xx",
 
 		FollowRedirects: true,
 		AllowInsecure:   true,
@@ -695,11 +701,13 @@ func TestCreateLoadBalancerMonitor(t *testing.T) {
 			"Host":     {"example.com"},
 			"X-App-ID": {"abc123"},
 		},
-		Timeout:       3,
-		Retries:       0,
-		Interval:      90,
-		ExpectedBody:  "alive",
-		ExpectedCodes: "2xx",
+		Timeout:         3,
+		Retries:         0,
+		Interval:        90,
+		ConsecutiveUp:   2,
+		ConsecutiveDown: 2,
+		ExpectedBody:    "alive",
+		ExpectedCodes:   "2xx",
 
 		FollowRedirects: true,
 		AllowInsecure:   true,
@@ -752,6 +760,8 @@ func TestListLoadBalancerMonitors(t *testing.T) {
                     "timeout": 3,
                     "retries": 0,
                     "interval": 90,
+                    "consecutive_up": 2,
+                    "consecutive_down": 2,
                     "expected_body": "alive",
                     "expected_codes": "2xx"
                 }
@@ -781,11 +791,13 @@ func TestListLoadBalancerMonitors(t *testing.T) {
 				"Host":     {"example.com"},
 				"X-App-ID": {"abc123"},
 			},
-			Timeout:       3,
-			Retries:       0,
-			Interval:      90,
-			ExpectedBody:  "alive",
-			ExpectedCodes: "2xx",
+			Timeout:         3,
+			Retries:         0,
+			Interval:        90,
+			ConsecutiveUp:   2,
+			ConsecutiveDown: 2,
+			ExpectedBody:    "alive",
+			ExpectedCodes:   "2xx",
 		},
 	}
 
@@ -835,6 +847,8 @@ func TestGetLoadBalancerMonitor(t *testing.T) {
                 "timeout": 3,
                 "retries": 0,
                 "interval": 90,
+                "consecutive_up": 2,
+                "consecutive_down": 2,
                 "expected_body": "alive",
                 "expected_codes": "2xx",
                 "follow_redirects": true,
@@ -859,11 +873,13 @@ func TestGetLoadBalancerMonitor(t *testing.T) {
 			"Host":     {"example.com"},
 			"X-App-ID": {"abc123"},
 		},
-		Timeout:       3,
-		Retries:       0,
-		Interval:      90,
-		ExpectedBody:  "alive",
-		ExpectedCodes: "2xx",
+		Timeout:         3,
+		Retries:         0,
+		Interval:        90,
+		ConsecutiveUp:   2,
+		ConsecutiveDown: 2,
+		ExpectedBody:    "alive",
+		ExpectedCodes:   "2xx",
 
 		FollowRedirects: true,
 		AllowInsecure:   true,
@@ -947,6 +963,8 @@ func TestUpdateLoadBalancerMonitor(t *testing.T) {
                 "timeout": 3,
                 "retries": 0,
                 "interval": 90,
+                "consecutive_up": 2,
+                "consecutive_down": 2,
                 "expected_body": "kicking",
                 "expected_codes": "200",
                 "follow_redirects": true,
@@ -977,6 +995,8 @@ func TestUpdateLoadBalancerMonitor(t *testing.T) {
                 "timeout": 3,
                 "retries": 0,
                 "interval": 90,
+                "consecutive_up": 2,
+                "consecutive_down": 2,
                 "expected_body": "kicking",
                 "expected_codes": "200",
                 "follow_redirects": true,
@@ -1001,11 +1021,13 @@ func TestUpdateLoadBalancerMonitor(t *testing.T) {
 			"Host":     {"example.com"},
 			"X-App-ID": {"easy"},
 		},
-		Timeout:       3,
-		Retries:       0,
-		Interval:      90,
-		ExpectedBody:  "kicking",
-		ExpectedCodes: "200",
+		Timeout:         3,
+		Retries:         0,
+		Interval:        90,
+		ConsecutiveUp:   2,
+		ConsecutiveDown: 2,
+		ExpectedBody:    "kicking",
+		ExpectedCodes:   "200",
 
 		FollowRedirects: true,
 		AllowInsecure:   true,
@@ -1020,11 +1042,13 @@ func TestUpdateLoadBalancerMonitor(t *testing.T) {
 			"Host":     {"example.com"},
 			"X-App-ID": {"easy"},
 		},
-		Timeout:       3,
-		Retries:       0,
-		Interval:      90,
-		ExpectedBody:  "kicking",
-		ExpectedCodes: "200",
+		Timeout:         3,
+		Retries:         0,
+		Interval:        90,
+		ConsecutiveUp:   2,
+		ConsecutiveDown: 2,
+		ExpectedBody:    "kicking",
+		ExpectedCodes:   "200",
 
 		FollowRedirects: true,
 		AllowInsecure:   true,