forked from mtusi2026/mtusi2026lab4
39 lines
956 B
Go
39 lines
956 B
Go
package fiber
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/valyala/fasthttp"
|
|
)
|
|
|
|
// TestMetricsBoundUnknownMethods keeps arbitrary client methods out of metric labels.
|
|
func TestMetricsBoundUnknownMethods(t *testing.T) {
|
|
ctrl := testController(t, nil)
|
|
raw := &fasthttp.RequestCtx{}
|
|
raw.Request.Header.SetMethod("CUSTOM_RANDOM_METHOD")
|
|
raw.Response.SetStatusCode(http.StatusTemporaryRedirect)
|
|
ctx := ctrl.server.AcquireCtx(raw)
|
|
defer ctrl.server.ReleaseCtx(ctx)
|
|
ctrl.metrics.observe(ctx, time.Millisecond)
|
|
families, err := ctrl.metrics.registry.Gather()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
found := false
|
|
for _, family := range families {
|
|
for _, metric := range family.Metric {
|
|
for _, label := range metric.Label {
|
|
if label.GetValue() == "CUSTOM_RANDOM_METHOD" {
|
|
t.Fatal("unbounded method label")
|
|
}
|
|
found = found || label.GetValue() == "other"
|
|
}
|
|
}
|
|
}
|
|
if !found {
|
|
t.Fatal("unknown method was not grouped")
|
|
}
|
|
}
|