mirror of
https://github.com/prymitive/karma
synced 2026-05-05 03:16:51 +00:00
Merge pull request #708 from prymitive/test-metrics
chore(backend): add test coverage for metrics handler
This commit is contained in:
10
main.go
10
main.go
@@ -100,6 +100,12 @@ func setupRouter(router *gin.Engine) {
|
||||
router.NoRoute(notFound)
|
||||
}
|
||||
|
||||
func setupMetrics(router *gin.Engine) {
|
||||
prom := ginprometheus.NewPrometheus("gin")
|
||||
prom.MetricsPath = getViewURL("/metrics")
|
||||
prom.Use(router)
|
||||
}
|
||||
|
||||
func setupUpstreams() {
|
||||
for _, s := range config.Config.Alertmanager.Servers {
|
||||
|
||||
@@ -207,9 +213,7 @@ func main() {
|
||||
t = loadTemplate(t, "ui/build/index.html")
|
||||
router.SetHTMLTemplate(t)
|
||||
|
||||
prom := ginprometheus.NewPrometheus("gin")
|
||||
prom.MetricsPath = getViewURL("/metrics")
|
||||
prom.Use(router)
|
||||
setupMetrics(router)
|
||||
|
||||
if config.Config.Debug {
|
||||
ginpprof.Wrapper(router)
|
||||
|
||||
14
main_test.go
14
main_test.go
@@ -1,6 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/prymitive/karma/internal/config"
|
||||
@@ -26,3 +28,15 @@ func TestLogConfig(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMetrics(t *testing.T) {
|
||||
mockConfig()
|
||||
r := ginTestEngine()
|
||||
setupMetrics(r)
|
||||
req := httptest.NewRequest("GET", "/metrics", nil)
|
||||
resp := httptest.NewRecorder()
|
||||
r.ServeHTTP(resp, req)
|
||||
if resp.Code != http.StatusOK {
|
||||
t.Errorf("GET /metrics returned status %d", resp.Code)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user