Repository: avenga/couper
Pull request #488 (2022-04-21 09:43:55)

Naming: expect => expected
Describe your changes!

---
<details>
    <summary>Reviewer checklist</summary>
    <ul>
        <li>Read PR description: a summary about the changes is required</li>
        <li>Changelog updated</li>
        <li>Documentation: docs/{Reference, Cli, ...}, Docker and cli help/usage</li>
        <li>Pulled branch, manually tested</li>
        <li>Verified requirements are met</li>
        <li>Reviewed the code</li>
        <li>Reviewed the related tests</li>
    </ul>
</details>



Patch:
diff --git a/config/health_check.go b/config/health_check.go
index a0370fa0..affde494 100644
--- a/config/health_check.go
+++ b/config/health_check.go
@@ -14,16 +14,16 @@ var defaultHealthCheck = &HealthCheck{
 	FailureThreshold: 2,
 	Interval:         time.Second,
 	Timeout:          time.Second,
-	ExpectStatus:     map[int]bool{200: true, 204: true, 301: true},
-	ExpectText:       "",
+	ExpectedStatus:   map[int]bool{200: true, 204: true, 301: true},
+	ExpectedText:     "",
 }
 
 type HealthCheck struct {
 	FailureThreshold uint
 	Interval         time.Duration
 	Timeout          time.Duration
-	ExpectStatus     map[int]bool
-	ExpectText       string
+	ExpectedStatus   map[int]bool
+	ExpectedText     string
 	Request          *http.Request
 	RequestUIDFormat string
 }
@@ -35,8 +35,8 @@ type Health struct {
 	Interval         string   `hcl:"interval,optional"`
 	Timeout          string   `hcl:"timeout,optional"`
 	Path             string   `hcl:"path,optional"`
-	ExpectStatus     int      `hcl:"expect_status,optional"`
-	ExpectText       string   `hcl:"expect_text,optional"`
+	ExpectedStatus   int      `hcl:"expected_status,optional"`
+	ExpectedText     string   `hcl:"expected_text,optional"`
 	Headers          Headers  `hcl:"headers,optional"`
 	Remain           hcl.Body `hcl:",remain"`
 }
@@ -66,10 +66,10 @@ func NewHealthCheck(baseURL string, options *Health, settings *Settings) (*Healt
 		if options.FailureThreshold != 0 {
 			healthCheck.FailureThreshold = options.FailureThreshold
 		}
-		if options.ExpectStatus != 0 {
-			healthCheck.ExpectStatus = map[int]bool{options.ExpectStatus: true}
+		if options.ExpectedStatus != 0 {
+			healthCheck.ExpectedStatus = map[int]bool{options.ExpectedStatus: true}
 		}
-		healthCheck.ExpectText = options.ExpectText
+		healthCheck.ExpectedText = options.ExpectedText
 
 		request, err := http.NewRequest(http.MethodGet, baseURL, nil)
 		if err != nil {
diff --git a/docs/REFERENCE.md b/docs/REFERENCE.md
index 34721002..47db6696 100644
--- a/docs/REFERENCE.md
+++ b/docs/REFERENCE.md
@@ -546,8 +546,8 @@ via `headers` attribute.
 
 | Attributes          | Type                  | Default             | Description                                        | Characteristics       | Example                            |
 |:--------------------|:----------------------|:--------------------|:---------------------------------------------------|:----------------------|:-----------------------------------|
-| `expect_status`     | number                | `200`, `204`, `301` | wanted response status code                        |                       | `expect_status =  418`             |
-| `expect_text`       | string                | –                   | text response body must contain                    |                       | `expect_text = alive`              |
+| `expected_status`     | number                | `200`, `204`, `301` | wanted response status code                        |                       | `expected_status =  418`             |
+| `expected_text`       | string                | –                   | text response body must contain                    |                       | `expected_text = alive`              |
 | `failure_threshold` | number                | `2`                 | failed checks needed to consider backend unhealthy |                       | `failure_threshold = 3`            |
 | `headers`           | object                | –                   | request headers                                    |                       | `headers = {User-Agent: "health"}` |
 | `interval`          | [duration](#duration) | `"2s"`              | time interval for recheck                          |                       | `timeout = "5s"`                   |
diff --git a/handler/transport/probe.go b/handler/transport/probe.go
index 8dd66204..2311ee75 100644
--- a/handler/transport/probe.go
+++ b/handler/transport/probe.go
@@ -100,14 +100,14 @@ func (p *Probe) probe() {
 		}
 
 		var errorMessage string
-		if err != nil || !p.opts.ExpectStatus[res.StatusCode] || !contains(res.Body, p.opts.ExpectText) {
+		if err != nil || !p.opts.ExpectedStatus[res.StatusCode] || !contains(res.Body, p.opts.ExpectedText) {
 			if p.failure++; p.failure < p.opts.FailureThreshold {
 				p.state = StateFailing
 			} else {
 				p.state = StateDown
 			}
 			if err == nil {
-				if !p.opts.ExpectStatus[res.StatusCode] {
+				if !p.opts.ExpectedStatus[res.StatusCode] {
 					errorMessage = "unexpected statusCode: " + strconv.Itoa(p.status)
 				} else {
 					errorMessage = "unexpected text"


Test patch:
diff --git a/config/configload/load_test.go b/config/configload/load_test.go
index 947a2c93..01cb8b63 100644
--- a/config/configload/load_test.go
+++ b/config/configload/load_test.go
@@ -98,16 +98,16 @@ func TestHealthCheck(t *testing.T) {
 		},
 		{
 			"Bad expect status",
-			`expect_status = [200, 204]`,
-			"couper.hcl:13,25-26: Unsuitable value type; Unsuitable value: number required",
+			`expected_status = [200, 204]`,
+			"couper.hcl:13,27-28: Unsuitable value type; Unsuitable value: number required",
 		},
 		{
 			"OK",
 			`failure_threshold = 3
 			 timeout = "3s"
 			 interval = "5s"
-			 expect_text = 123
-			 expect_status = 200`,
+			 expected_text = 123
+			 expected_status = 200`,
 			"",
 		},
 	}
diff --git a/handler/transport/backend_test.go b/handler/transport/backend_test.go
index a34869ca..8b25be45 100644
--- a/handler/transport/backend_test.go
+++ b/handler/transport/backend_test.go
@@ -362,8 +362,8 @@ func TestBackend_HealthCheck(t *testing.T) {
 		FailureThreshold uint
 		Interval         time.Duration
 		Timeout          time.Duration
-		ExpectStatus     map[int]bool
-		ExpectText       string
+		ExpectedStatus   map[int]bool
+		ExpectedText     string
 		URL              *url.URL
 		RequestUIDFormat string
 	}
@@ -374,7 +374,7 @@ func TestBackend_HealthCheck(t *testing.T) {
 		expectation expectation
 	}
 
-	defaultExpectStatus := map[int]bool{200: true, 204: true, 301: true}
+	defaultExpectedStatus := map[int]bool{200: true, 204: true, 301: true}
 
 	for _, tc := range []testCase{
 		{
@@ -384,8 +384,8 @@ func TestBackend_HealthCheck(t *testing.T) {
 				FailureThreshold: 2,
 				Interval:         time.Second,
 				Timeout:          time.Second,
-				ExpectStatus:     defaultExpectStatus,
-				ExpectText:       "",
+				ExpectedStatus:   defaultExpectedStatus,
+				ExpectedText:     "",
 				RequestUIDFormat: "common",
 			},
 		},
@@ -396,15 +396,15 @@ func TestBackend_HealthCheck(t *testing.T) {
 				Interval:         "1h",
 				Timeout:          "9m",
 				Path:             "/gsund??",
-				ExpectStatus:     418,
-				ExpectText:       "roger roger",
+				ExpectedStatus:   418,
+				ExpectedText:     "roger roger",
 			},
 			expectation: expectation{
 				FailureThreshold: 42,
 				Interval:         time.Hour,
 				Timeout:          9 * time.Minute,
-				ExpectStatus:     map[int]bool{418: true},
-				ExpectText:       "roger roger",
+				ExpectedStatus:   map[int]bool{418: true},
+				ExpectedText:     "roger roger",
 				URL: &url.URL{
 					Scheme:   "http",
 					Host:     "origin:8080",
@@ -421,8 +421,8 @@ func TestBackend_HealthCheck(t *testing.T) {
 				FailureThreshold: 2,
 				Interval:         time.Second,
 				Timeout:          time.Second,
-				ExpectStatus:     defaultExpectStatus,
-				ExpectText:       "",
+				ExpectedStatus:   defaultExpectedStatus,
+				ExpectedText:     "",
 				RequestUIDFormat: "common",
 			},
 		},
@@ -435,8 +435,8 @@ func TestBackend_HealthCheck(t *testing.T) {
 				FailureThreshold: 2,
 				Interval:         10 * time.Second,
 				Timeout:          10 * time.Second,
-				ExpectStatus:     defaultExpectStatus,
-				ExpectText:       "",
+				ExpectedStatus:   defaultExpectedStatus,
+				ExpectedText:     "",
 				RequestUIDFormat: "common",
 			},
 		},
@@ -450,8 +450,8 @@ func TestBackend_HealthCheck(t *testing.T) {
 				FailureThreshold: 2,
 				Interval:         5 * time.Second,
 				Timeout:          5 * time.Second,
-				ExpectStatus:     defaultExpectStatus,
-				ExpectText:       "",
+				ExpectedStatus:   defaultExpectedStatus,
+				ExpectedText:     "",
 				RequestUIDFormat: "common",
 			},
 		},
@@ -464,8 +464,8 @@ func TestBackend_HealthCheck(t *testing.T) {
 				FailureThreshold: 2,
 				Interval:         time.Second,
 				Timeout:          time.Second,
-				ExpectStatus:     defaultExpectStatus,
-				ExpectText:       "",
+				ExpectedStatus:   defaultExpectedStatus,
+				ExpectedText:     "",
 				RequestUIDFormat: "common",
 			},
 		},
diff --git a/server/http_integration_test.go b/server/http_integration_test.go
index 193043bb..354ebe9f 100644
--- a/server/http_integration_test.go
+++ b/server/http_integration_test.go
@@ -2660,13 +2660,13 @@ func TestHTTPServer_BackendProbes(t *testing.T) {
 			healthyJSON,
 		},
 		{
-			"healthy backend w/ expect_status",
-			"/healthy/expect_status",
+			"healthy backend w/ expected_status",
+			"/healthy/expected_status",
 			healthyJSON,
 		},
 		{
-			"healthy backend w/ expect_text",
-			"/healthy/expect_text",
+			"healthy backend w/ expected_text",
+			"/healthy/expected_text",
 			healthyJSON,
 		},
 		{
@@ -2700,13 +2700,13 @@ func TestHTTPServer_BackendProbes(t *testing.T) {
 			`{"error":"unexpected statusCode: 404","healthy":false,"state":"unhealthy"}`,
 		},
 		{
-			"unhealthy backend w/ expect_status: unexpected status code",
-			"/unhealthy/bad_expect_status",
+			"unhealthy backend w/ expected_status: unexpected status code",
+			"/unhealthy/bad_expected_status",
 			`{"error":"unexpected statusCode: 200","healthy":false,"state":"unhealthy"}`,
 		},
 		{
-			"unhealthy backend w/ expect_text: unexpected text",
-			"/unhealthy/bad_expect_text",
+			"unhealthy backend w/ expected_text: unexpected text",
+			"/unhealthy/bad_expected_text",
 			`{"error":"unexpected text","healthy":false,"state":"unhealthy"}`,
 		},
 		{
diff --git a/server/testdata/integration/config/14_couper.hcl b/server/testdata/integration/config/14_couper.hcl
index e32f7a59..7b976b6c 100644
--- a/server/testdata/integration/config/14_couper.hcl
+++ b/server/testdata/integration/config/14_couper.hcl
@@ -9,14 +9,14 @@ server {
       json_body = backends.healthy.health
     }
   }
-  endpoint "/healthy/expect_status" {
+  endpoint "/healthy/expected_status" {
     response {
-      json_body = backends.healthy_expect_status.health
+      json_body = backends.healthy_expected_status.health
     }
   }
-  endpoint "/healthy/expect_text" {
+  endpoint "/healthy/expected_text" {
     response {
-      json_body = backends.healthy_expect_text.health
+      json_body = backends.healthy_expected_text.health
     }
   }
   endpoint "/healthy/path" {
@@ -49,14 +49,14 @@ server {
       json_body = backends.unhealthy_bad_status.health
     }
   }
-  endpoint "/unhealthy/bad_expect_status" {
+  endpoint "/unhealthy/bad_expected_status" {
     response {
-      json_body = backends.unhealthy_bad_expect_status.health
+      json_body = backends.unhealthy_bad_expected_status.health
     }
   }
-  endpoint "/unhealthy/bad_expect_text" {
+  endpoint "/unhealthy/bad_expected_text" {
     response {
-      json_body = backends.unhealthy_bad_expect_text.health
+      json_body = backends.unhealthy_bad_expected_text.health
     }
   }
   endpoint "/unhealthy/bad_path" {
@@ -84,11 +84,11 @@ server {
     request "default" {
       backend = "healthy"
     }
-    request "healthy_expect_status" {
-      backend = "healthy_expect_status"
+    request "healthy_expected_status" {
+      backend = "healthy_expected_status"
     }
-    request "healthy_expect_text" {
-      backend = "healthy_expect_text"
+    request "healthy_expected_text" {
+      backend = "healthy_expected_text"
     }
     request "healthy_path" {
       backend = "healthy_path"
@@ -108,11 +108,11 @@ server {
     request "unhealthy_bad_status" {
       backend = "unhealthy_bad_status"
     }
-    request "unhealthy_bad_expect_status" {
-      backend = "unhealthy_bad_expect_status"
+    request "unhealthy_bad_expected_status" {
+      backend = "unhealthy_bad_expected_status"
     }
-    request "unhealthy_bad_expect_text" {
-      backend = "unhealthy_bad_expect_text"
+    request "unhealthy_bad_expected_text" {
+      backend = "unhealthy_bad_expected_text"
     }
     request "unhealthy_bad_path" {
       backend = "unhealthy_bad_path"
@@ -134,23 +134,23 @@ definitions {
     origin = "${env.COUPER_TEST_BACKEND_ADDR}/health"
     beta_health {}
   }
-  backend "healthy_expect_status" {
+  backend "healthy_expected_status" {
     origin = "${env.COUPER_TEST_BACKEND_ADDR}/not-there"
     beta_health {
-      expect_status = 404
+      expected_status = 404
     }
   }
-  backend "healthy_expect_text" {
+  backend "healthy_expected_text" {
     origin = "${env.COUPER_TEST_BACKEND_ADDR}/health"
     beta_health {
-      expect_text = "👍"
+      expected_text = "👍"
     }
   }
   backend "healthy_path" {
     origin = env.COUPER_TEST_BACKEND_ADDR
     beta_health {
       path = "/anything?foo=bar"
-      expect_text = "\"RawQuery\":\"foo=bar\""
+      expected_text = "\"RawQuery\":\"foo=bar\""
     }
   }
 
@@ -159,7 +159,7 @@ definitions {
     beta_health {
       path = "/anything"
       headers = {User-Agent: "Couper-Health-Check"}
-      expect_text = "\"UserAgent\":\"Couper-Health-Check\""
+      expected_text = "\"UserAgent\":\"Couper-Health-Check\""
     }
   }
 
@@ -167,7 +167,7 @@ definitions {
     origin = env.COUPER_TEST_BACKEND_ADDR
     beta_health {
       path = "/anything"
-      expect_text = "\"UserAgent\":\"Couper / 0 health-check\""
+      expected_text = "\"UserAgent\":\"Couper / 0 health-check\""
     }
   }
 
@@ -175,7 +175,7 @@ definitions {
     origin = env.COUPER_TEST_BACKEND_ADDR
     beta_health {
       path = "/redirect?url=/health?redirected"
-      expect_status = 302
+      expected_status = 302
     }
   }
   backend "unhealthy_timeout" {
@@ -186,16 +186,16 @@ definitions {
     origin = "${env.COUPER_TEST_BACKEND_ADDR}"
     beta_health {}
   }
-  backend "unhealthy_bad_expect_status" {
+  backend "unhealthy_bad_expected_status" {
     origin = "${env.COUPER_TEST_BACKEND_ADDR}/health"
     beta_health {
-      expect_status = 500
+      expected_status = 500
     }
   }
-  backend "unhealthy_bad_expect_text" {
+  backend "unhealthy_bad_expected_text" {
     origin = "${env.COUPER_TEST_BACKEND_ADDR}/health"
     beta_health {
-      expect_text = "down?"
+      expected_text = "down?"
     }
   }
   backend "unhealthy_bad_path" {
@@ -208,14 +208,14 @@ definitions {
     origin = "${env.COUPER_TEST_BACKEND_ADDR}/anything"
     beta_health {
       headers = {User-Agent = "FAIL"}
-      expect_text = "Go-http-client"
+      expected_text = "Go-http-client"
     }
   }
   backend "unhealthy_no_follow_redirect" {
     origin = env.COUPER_TEST_BACKEND_ADDR
     beta_health {
       path = "/redirect?url=/health?redirected"
-      expect_text = "👍"
+      expected_text = "👍"
     }
   }
   backend "failing" {