Publish ITWorx Pulse source
Public source validation / validate (push) Failing after 3m8s

This commit is contained in:
ITWorx Pulse release export
2026-09-03 02:09:19 +02:00
commit bd774932d5
614 changed files with 77116 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
package systemstatusapi
import (
"context"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/itworx/pulse/internal/systemstatus"
)
func TestHandlerServesStatusAndRedactedDiagnostics(t *testing.T) {
snapshot := systemstatus.Snapshot{Version: "test", OverallState: systemstatus.StateUnknown}
handler := Handler{
Snapshot: func(context.Context) (systemstatus.Snapshot, error) { return snapshot, nil },
Diagnostics: func(context.Context) (Diagnostics, error) {
return Diagnostics{Status: snapshot, Config: ConfigSummary{DatabaseConfigured: true}, Metrics: "pulse_up 1\n"}, nil
},
}
response := httptest.NewRecorder()
handler.ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/api/v1/system/status", nil))
if response.Code != http.StatusOK || !strings.Contains(response.Body.String(), `"overallState":"unknown"`) {
t.Fatalf("status response = %d %s", response.Code, response.Body.String())
}
response = httptest.NewRecorder()
handler.ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/api/v1/system/diagnostics", nil))
if response.Code != http.StatusOK || strings.Contains(response.Body.String(), "password") {
t.Fatalf("diagnostics response = %d %s", response.Code, response.Body.String())
}
}
func TestHandlerRejectsUnsupportedMethodAndPath(t *testing.T) {
handler := Handler{Snapshot: func(context.Context) (systemstatus.Snapshot, error) { return systemstatus.Snapshot{}, nil }}
response := httptest.NewRecorder()
handler.ServeHTTP(response, httptest.NewRequest(http.MethodPost, "/api/v1/system/status", nil))
if response.Code != http.StatusMethodNotAllowed {
t.Fatalf("method status = %d", response.Code)
}
response = httptest.NewRecorder()
handler.ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/api/v1/system/unknown", nil))
if response.Code != http.StatusNotFound {
t.Fatalf("path status = %d", response.Code)
}
}