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
+44
View File
@@ -0,0 +1,44 @@
package eventapi
import (
"context"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/itworx/pulse/internal/auth"
)
type fakeStore struct{ limit int }
func (s *fakeStore) List(_ context.Context, limit int) ([]Event, error) {
s.limit = limit
return []Event{{ID: "event-1", Type: "discovery.completed", Severity: "info", Summary: "Inventaris bijgewerkt", Attributes: []byte(`{}`)}}, nil
}
func TestHandlerListsBoundedEvents(t *testing.T) {
store := &fakeStore{}
req := httptest.NewRequest(http.MethodGet, "/api/v1/events?limit=25", nil)
req = req.WithContext(auth.WithPrincipal(req.Context(), auth.Principal{Subject: "viewer", Role: auth.RoleViewer}))
res := httptest.NewRecorder()
Handler{Store: store}.ServeHTTP(res, req)
if res.Code != http.StatusOK || store.limit != 25 || !strings.Contains(res.Body.String(), `"id":"event-1"`) {
t.Fatalf("status=%d limit=%d body=%s", res.Code, store.limit, res.Body.String())
}
}
func TestHandlerRejectsInvalidLimitAndAnonymous(t *testing.T) {
res := httptest.NewRecorder()
Handler{Store: &fakeStore{}}.ServeHTTP(res, httptest.NewRequest(http.MethodGet, "/api/v1/events", nil))
if res.Code != http.StatusUnauthorized {
t.Fatalf("anonymous status=%d", res.Code)
}
req := httptest.NewRequest(http.MethodGet, "/api/v1/events?limit=101", nil)
req = req.WithContext(auth.WithPrincipal(req.Context(), auth.Principal{Subject: "viewer", Role: auth.RoleViewer}))
res = httptest.NewRecorder()
Handler{Store: &fakeStore{}}.ServeHTTP(res, req)
if res.Code != http.StatusBadRequest {
t.Fatalf("limit status=%d", res.Code)
}
}