1234567891011121314151617181920212223 |
- package handler
- import (
- "net/http"
- "net/http/httptest"
- "testing"
- "github.com/stretchr/testify/assert"
- "github.com/tal-tech/go-zero/core/stat"
- )
- func TestMetricHandler(t *testing.T) {
- metrics := stat.NewMetrics("unit-test")
- metricHandler := MetricHandler(metrics)
- handler := metricHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- w.WriteHeader(http.StatusOK)
- }))
- req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
- resp := httptest.NewRecorder()
- handler.ServeHTTP(resp, req)
- assert.Equal(t, http.StatusOK, resp.Code)
- }
|