metrichandler_test.go 574 B

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