Add web auth, infinite-scroll, agent admission and review fixes across agent/server/web
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -57,6 +58,59 @@ func TestSendEventsBatch(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendEventsSplitsByJSONSize(t *testing.T) {
|
||||
var (
|
||||
requests int
|
||||
total int
|
||||
)
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
http.Error(w, "read body", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if len(body) > MaxBatchBytes {
|
||||
t.Errorf("body size %d exceeds %d", len(body), MaxBatchBytes)
|
||||
http.Error(w, "too large", http.StatusRequestEntityTooLarge)
|
||||
return
|
||||
}
|
||||
var got EventBatchRequest
|
||||
if err := json.Unmarshal(body, &got); err != nil {
|
||||
t.Error(err)
|
||||
http.Error(w, "bad json", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
requests++
|
||||
total += len(got.Events)
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
_ = json.NewEncoder(w).Encode(EventBatchResponse{Accepted: len(got.Events)})
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
events := make([]scheduler.Event, MaxBatchEvents)
|
||||
for i := range events {
|
||||
events[i] = scheduler.Event{
|
||||
EventID: "event-" + time.Unix(int64(i), 0).UTC().Format("20060102150405"),
|
||||
CheckID: "check",
|
||||
ObservedAt: time.Unix(int64(i), 0).UTC(),
|
||||
Status: "ok",
|
||||
Output: strings.Repeat("x", 8192),
|
||||
}
|
||||
}
|
||||
c := New(srv.URL, "tok", "a1")
|
||||
resp, err := c.SendEvents(context.Background(), events)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if requests < 2 {
|
||||
t.Fatalf("expected split batch, got %d request", requests)
|
||||
}
|
||||
if total != MaxBatchEvents || resp.Accepted != MaxBatchEvents {
|
||||
t.Fatalf("total=%d resp=%+v", total, resp)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendEventsTooBig(t *testing.T) {
|
||||
c := New("http://x", "t", "a1")
|
||||
big := make([]scheduler.Event, MaxBatchEvents+1)
|
||||
@@ -64,6 +118,24 @@ func TestSendEventsTooBig(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Fatal("expected error")
|
||||
}
|
||||
if Retryable(err) {
|
||||
t.Fatal("oversized batch should not retry")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendEventsSingleEventTooLargeIsNotRetryable(t *testing.T) {
|
||||
c := New("http://x", "t", "a1")
|
||||
_, err := c.SendEvents(context.Background(), []scheduler.Event{{
|
||||
EventID: "x",
|
||||
CheckID: strings.Repeat("c", MaxBatchBytes),
|
||||
Status: "ok",
|
||||
}})
|
||||
if err == nil {
|
||||
t.Fatal("expected error")
|
||||
}
|
||||
if Retryable(err) {
|
||||
t.Fatal("oversized single event should not retry")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRetryableClassification(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user