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)
41 lines
929 B
Go
41 lines
929 B
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestHandleHubIndex_Empty(t *testing.T) {
|
|
s, _ := newTestServer(t)
|
|
req := httptest.NewRequest(http.MethodGet, "/api/hub/index", 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 {
|
|
Skills []any `json:"skills"`
|
|
}
|
|
json.Unmarshal(rr.Body.Bytes(), &resp)
|
|
if len(resp.Skills) != 0 {
|
|
t.Errorf("expected 0 skills in hub index, got %d", len(resp.Skills))
|
|
}
|
|
}
|
|
|
|
func TestHandleHubIndex_WithSkills(t *testing.T) {
|
|
s, src := newTestServer(t)
|
|
addSkill(t, src, "hub-skill")
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/api/hub/index", 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())
|
|
}
|
|
}
|