summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/metrics_test.go
diff options
context:
space:
mode:
authorDave Henderson <dhenderson@gmail.com>2022-01-22 19:08:57 -0500
committerDave Henderson <dhenderson@gmail.com>2022-01-25 15:07:17 -0500
commiteb891d46831252c5329218bfbb606727685fea72 (patch)
tree66e4cfaaaa311afc702c5489588e50ad93976fbc /modules/caddyhttp/metrics_test.go
parent44e5e9e43f3583f04613bbbb1996e9b5a13a60ac (diff)
metrics: Enforce smaller set of method labels
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'modules/caddyhttp/metrics_test.go')
-rw-r--r--modules/caddyhttp/metrics_test.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/modules/caddyhttp/metrics_test.go b/modules/caddyhttp/metrics_test.go
index 6311935..78e380b 100644
--- a/modules/caddyhttp/metrics_test.go
+++ b/modules/caddyhttp/metrics_test.go
@@ -5,6 +5,7 @@ import (
"errors"
"net/http"
"net/http/httptest"
+ "strings"
"testing"
"github.com/prometheus/client_golang/prometheus/testutil"
@@ -82,3 +83,25 @@ type middlewareHandlerFunc func(http.ResponseWriter, *http.Request, Handler) err
func (f middlewareHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request, h Handler) error {
return f(w, r, h)
}
+
+func TestSanitizeMethod(t *testing.T) {
+ tests := []struct {
+ method string
+ expected string
+ }{
+ {method: "get", expected: "GET"},
+ {method: "POST", expected: "POST"},
+ {method: "OPTIONS", expected: "OPTIONS"},
+ {method: "connect", expected: "CONNECT"},
+ {method: "trace", expected: "TRACE"},
+ {method: "UNKNOWN", expected: "other"},
+ {method: strings.Repeat("ohno", 9999), expected: "other"},
+ }
+
+ for _, d := range tests {
+ actual := sanitizeMethod(d.method)
+ if actual != d.expected {
+ t.Errorf("Not same: expected %#v, but got %#v", d.expected, actual)
+ }
+ }
+}