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)
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestHandleSync_MergeMode(t *testing.T) {
|
|
tgtPath := filepath.Join(t.TempDir(), "claude-skills")
|
|
s, src := newTestServerWithTargets(t, map[string]string{"claude": tgtPath})
|
|
addSkill(t, src, "alpha")
|
|
|
|
body := `{"dryRun":false}`
|
|
req := httptest.NewRequest(http.MethodPost, "/api/sync", strings.NewReader(body))
|
|
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 {
|
|
Results []map[string]any `json:"results"`
|
|
}
|
|
json.Unmarshal(rr.Body.Bytes(), &resp)
|
|
if len(resp.Results) != 1 {
|
|
t.Fatalf("expected 1 sync result, got %d", len(resp.Results))
|
|
}
|
|
if resp.Results[0]["target"] != "claude" {
|
|
t.Errorf("expected target 'claude', got %v", resp.Results[0]["target"])
|
|
}
|
|
}
|
|
|
|
func TestHandleSync_NoTargets(t *testing.T) {
|
|
s, _ := newTestServer(t) // no targets configured
|
|
|
|
body := `{}`
|
|
req := httptest.NewRequest(http.MethodPost, "/api/sync", strings.NewReader(body))
|
|
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 {
|
|
Results []any `json:"results"`
|
|
}
|
|
json.Unmarshal(rr.Body.Bytes(), &resp)
|
|
if len(resp.Results) != 0 {
|
|
t.Errorf("expected 0 results for no targets, got %d", len(resp.Results))
|
|
}
|
|
}
|