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"}
|
||||
|
||||
Reference in New Issue
Block a user