mirror of
https://github.com/prymitive/karma
synced 2026-05-07 03:26:52 +00:00
committed by
Łukasz Mierzwa
parent
875d13d044
commit
434eb677fd
@@ -114,6 +114,7 @@ func setupRouter(router *chi.Mux, historyPoller *historyPoller) {
|
||||
allowAuthBypass := []string{
|
||||
getViewURL("/health"),
|
||||
getViewURL("/metrics"),
|
||||
getViewURL("/version"),
|
||||
}
|
||||
if config.Config.Authentication.Header.Name != "" {
|
||||
config.Config.Authentication.Enabled = true
|
||||
@@ -131,6 +132,7 @@ func setupRouter(router *chi.Mux, historyPoller *historyPoller) {
|
||||
router.Get(getViewURL(""), redirectIndex)
|
||||
}
|
||||
router.Get(getViewURL("/"), index)
|
||||
router.Get(getViewURL("/version"), versionHandler)
|
||||
router.Get(getViewURL("/health"), pong)
|
||||
router.Get(getViewURL("/robots.txt"), robots)
|
||||
router.Get(getViewURL("/metrics"), http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -39,6 +40,20 @@ func badRequestJSON(w http.ResponseWriter, error string) {
|
||||
_, _ = w.Write(out)
|
||||
}
|
||||
|
||||
type KarmaVersion struct {
|
||||
Version string `json:"version"`
|
||||
Golang string `json:"golang"`
|
||||
}
|
||||
|
||||
func versionHandler(w http.ResponseWriter, r *http.Request) {
|
||||
ver := KarmaVersion{
|
||||
Version: version,
|
||||
Golang: runtime.Version(),
|
||||
}
|
||||
data, _ := json.MarshalIndent(ver, "", " ")
|
||||
_, _ = w.Write(data)
|
||||
}
|
||||
|
||||
func pong(w http.ResponseWriter, r *http.Request) {
|
||||
_, _ = w.Write([]byte("Pong\n"))
|
||||
}
|
||||
|
||||
@@ -89,6 +89,18 @@ func TestRobots(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestVersion(t *testing.T) {
|
||||
mockConfig()
|
||||
r := testRouter()
|
||||
setupRouter(r, nil)
|
||||
req := httptest.NewRequest("GET", "/version", nil)
|
||||
resp := httptest.NewRecorder()
|
||||
r.ServeHTTP(resp, req)
|
||||
if resp.Code != http.StatusOK {
|
||||
t.Errorf("GET /version returned status %d", resp.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealthPrefix(t *testing.T) {
|
||||
os.Setenv("LISTEN_PREFIX", "/prefix")
|
||||
defer os.Unsetenv("LISTEN_PREFIX")
|
||||
|
||||
Reference in New Issue
Block a user