mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
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)
77 lines
1.9 KiB
Go
77 lines
1.9 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestHandleListTrash_Empty(t *testing.T) {
|
|
s, _ := newTestServer(t)
|
|
req := httptest.NewRequest(http.MethodGet, "/api/trash", 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 {
|
|
Items []any `json:"items"`
|
|
TotalSize int64 `json:"totalSize"`
|
|
}
|
|
json.Unmarshal(rr.Body.Bytes(), &resp)
|
|
if len(resp.Items) != 0 {
|
|
t.Errorf("expected 0 trash items, got %d", len(resp.Items))
|
|
}
|
|
if resp.TotalSize != 0 {
|
|
t.Errorf("expected totalSize 0, got %d", resp.TotalSize)
|
|
}
|
|
}
|
|
|
|
func TestHandleRestoreTrash_NotFound(t *testing.T) {
|
|
s, _ := newTestServer(t)
|
|
req := httptest.NewRequest(http.MethodPost, "/api/trash/nonexistent/restore", nil)
|
|
rr := httptest.NewRecorder()
|
|
s.handler.ServeHTTP(rr, req)
|
|
|
|
if rr.Code != http.StatusNotFound {
|
|
t.Errorf("expected 404, got %d: %s", rr.Code, rr.Body.String())
|
|
}
|
|
}
|
|
|
|
func TestHandleDeleteTrash_NotFound(t *testing.T) {
|
|
s, _ := newTestServer(t)
|
|
req := httptest.NewRequest(http.MethodDelete, "/api/trash/nonexistent", nil)
|
|
rr := httptest.NewRecorder()
|
|
s.handler.ServeHTTP(rr, req)
|
|
|
|
if rr.Code != http.StatusNotFound {
|
|
t.Errorf("expected 404, got %d: %s", rr.Code, rr.Body.String())
|
|
}
|
|
}
|
|
|
|
func TestHandleEmptyTrash(t *testing.T) {
|
|
s, _ := newTestServer(t)
|
|
req := httptest.NewRequest(http.MethodPost, "/api/trash/empty", 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 {
|
|
Success bool `json:"success"`
|
|
Removed int `json:"removed"`
|
|
}
|
|
json.Unmarshal(rr.Body.Bytes(), &resp)
|
|
if !resp.Success {
|
|
t.Error("expected success true")
|
|
}
|
|
if resp.Removed != 0 {
|
|
t.Errorf("expected 0 removed, got %d", resp.Removed)
|
|
}
|
|
}
|