Добавлены новые возможности для работы с файловыми логами Docker-сервисов: - Эндпоинты для получения списка логов и хвоста лог-файла. - Очистка лог-файлов с возможностью выбора режима (truncate или delete) и запись в аудит очистки. - Обновлена документация и конфигурация для поддержки новых функций. Co-authored-by: Cursor <cursoragent@cursor.com>
69 lines
2.0 KiB
Go
69 lines
2.0 KiB
Go
package store
|
|
|
|
import "testing"
|
|
|
|
func TestMemoryRuntimeLogCleanupAudit(t *testing.T) {
|
|
m := NewMemory()
|
|
tenantA := "tenant-a"
|
|
tenantB := "tenant-b"
|
|
after := int64(0)
|
|
|
|
id, err := m.AppendRuntimeLogCleanupAudit(tenantA, "op:alice", "evobgp-all.log", RuntimeLogCleanupTruncate, 1024, &after, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if id == "" {
|
|
t.Fatal("expected audit id")
|
|
}
|
|
|
|
if _, err := m.AppendRuntimeLogCleanupAudit(tenantA, "op:alice", "postgres.log", RuntimeLogCleanupDelete, 512, nil, map[string]any{"note": "removed"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := m.AppendRuntimeLogCleanupAudit(tenantB, "op:bob", "bird2.log", RuntimeLogCleanupTruncate, 256, &after, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
items, next, hasMore, err := m.ListRuntimeLogCleanupAudit(tenantA, "", 10)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(items) != 2 || hasMore || next != "" {
|
|
t.Fatalf("tenantA list: len=%d hasMore=%v next=%q", len(items), hasMore, next)
|
|
}
|
|
if items[0].Filename == items[1].Filename {
|
|
t.Fatalf("expected desc order by created_at: %+v", items)
|
|
}
|
|
|
|
page, next, hasMore, err := m.ListRuntimeLogCleanupAudit(tenantA, "", 1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(page) != 1 || !hasMore || next == "" {
|
|
t.Fatalf("page1: len=%d hasMore=%v next=%q", len(page), hasMore, next)
|
|
}
|
|
|
|
page2, next2, hasMore2, err := m.ListRuntimeLogCleanupAudit(tenantA, next, 1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(page2) != 1 || hasMore2 || next2 != "" {
|
|
t.Fatalf("page2: len=%d hasMore=%v next=%q", len(page2), hasMore2, next2)
|
|
}
|
|
if page[0].ID == page2[0].ID {
|
|
t.Fatal("expected different audit rows across pages")
|
|
}
|
|
|
|
if _, err := m.AppendRuntimeLogCleanupAudit(tenantA, "op:x", "bad.log", "wipe", 1, nil, nil); err != ErrInvalidInput {
|
|
t.Fatalf("invalid action: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestValidRuntimeLogCleanupAction(t *testing.T) {
|
|
if !ValidRuntimeLogCleanupAction(RuntimeLogCleanupTruncate) {
|
|
t.Fatal("truncate")
|
|
}
|
|
if ValidRuntimeLogCleanupAction("rotate") {
|
|
t.Fatal("unexpected valid")
|
|
}
|
|
}
|