Handle empty dashboard metrics safely
This commit is contained in:
@@ -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"}
|
||||
|
||||
@@ -134,7 +134,9 @@ func (s *Service) Runs() []model.Run { return s.queue.Snapshot() }
|
||||
func (s *Service) BackupMetrics() []model.BackupMetric {
|
||||
s.metricsMu.RLock()
|
||||
defer s.metricsMu.RUnlock()
|
||||
return append([]model.BackupMetric(nil), s.backupMetrics...)
|
||||
metrics := make([]model.BackupMetric, len(s.backupMetrics))
|
||||
copy(metrics, s.backupMetrics)
|
||||
return metrics
|
||||
}
|
||||
func (s *Service) Logs() map[string]any {
|
||||
return map[string]any{
|
||||
|
||||
Reference in New Issue
Block a user