github.com/lingyao2333/mo-zero@v1.4.1/rest/handler/metrichandler_test.go (about) 1 package handler 2 3 import ( 4 "net/http" 5 "net/http/httptest" 6 "testing" 7 8 "github.com/lingyao2333/mo-zero/core/stat" 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestMetricHandler(t *testing.T) { 13 metrics := stat.NewMetrics("unit-test") 14 metricHandler := MetricHandler(metrics) 15 handler := metricHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 16 w.WriteHeader(http.StatusOK) 17 })) 18 19 req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody) 20 resp := httptest.NewRecorder() 21 handler.ServeHTTP(resp, req) 22 assert.Equal(t, http.StatusOK, resp.Code) 23 }