Files
skillshare/internal/server/handler_backup_test.go
T
Willie a8fb965b8b test: add unit tests for sync, install, and server packages
Boost unit test coverage across three core packages:
- internal/sync: 11.6% → 54.6% (discovery, status, checksum, manifest, pull, merge/prune)
- internal/install: 40.7% → 60.0% (meta, ignore, copy, updatable, local install, options, gitignore, source)
- internal/server: 15.1% → 40.0% (health, overview, skills, targets, config, log, trash, sync, collect, check, backup, diff, audit, hub)
2026-02-23 04:18:01 +08:00

31 lines
744 B
Go

package server
import (
"encoding/json"
"net/http"
"net/http/httptest"
"path/filepath"
"testing"
)
func TestHandleListBackups_Empty(t *testing.T) {
s, _ := newTestServer(t)
// Isolate backup directory via XDG_DATA_HOME to avoid reading real system backups
t.Setenv("XDG_DATA_HOME", filepath.Join(t.TempDir(), "data"))
req := httptest.NewRequest(http.MethodGet, "/api/backups", nil)
rr := httptest.NewRecorder()
s.handler.ServeHTTP(rr, req)
if rr.Code != http.StatusOK {
t.Fatalf("expected 200, got %d: %s", rr.Code, rr.Body.String())
}
var resp struct {
Backups []any `json:"backups"`
}
json.Unmarshal(rr.Body.Bytes(), &resp)
if len(resp.Backups) != 0 {
t.Errorf("expected 0 backups, got %d", len(resp.Backups))
}
}