Handle empty dashboard metrics safely

This commit is contained in:
Mikei386
2026-07-13 20:44:46 +02:00
parent b1fba3ed16
commit ea97d7dbc9
9 changed files with 30 additions and 8 deletions
+12
View File
@@ -2,6 +2,7 @@ package service
import (
"context"
"encoding/json"
"os"
"path/filepath"
"testing"
@@ -11,6 +12,17 @@ import (
"git.casaderoll.de/michael/urbm/internal/store"
)
func TestEmptyBackupMetricsEncodeAsJSONArray(t *testing.T) {
s := &Service{}
encoded, err := json.Marshal(s.BackupMetrics())
if err != nil {
t.Fatal(err)
}
if string(encoded) != "[]" {
t.Fatalf("empty backup metrics JSON = %s", encoded)
}
}
func TestRepositoryLockHonorsContextCancellation(t *testing.T) {
s := &Service{repositoryLocks: map[string]chan struct{}{}}
repo := model.Repository{Type: model.RepositoryLocal, Location: "/repo"}