Files
Erupe/server/channelserver/repo_scenario_test.go
Houmgaor ecfe58ffb4 feat: add SQLite support, setup wizard enhancements, and live dashboard
Add zero-dependency SQLite mode so users can run Erupe without
PostgreSQL. A transparent db.DB wrapper auto-translates PostgreSQL
SQL ($N placeholders, now(), ::casts, ILIKE, public. prefix,
TRUNCATE) for SQLite at runtime — all 28 repo files use the wrapper
with no per-query changes needed.

Setup wizard gains two new steps: quest file detection with download
link, and gameplay presets (solo/small/community/rebalanced). The API
server gets a /dashboard endpoint with auto-refreshing stats.

CI release workflow now builds and pushes Docker images to GHCR
alongside binary artifacts on tag push.

Key changes:
- common/db: DB/Tx wrapper with 6 SQL translation rules
- server/migrations/sqlite: full SQLite schema (0001-0005)
- config: Database.Driver field ("postgres" or "sqlite")
- main.go: SQLite connection with WAL mode, single writer
- server/setup: quest check + preset selection steps
- server/api: /dashboard with live stats
- .github/workflows: Docker in release, deduplicate docker.yml
2026-03-05 18:00:30 +01:00

62 lines
1.5 KiB
Go

package channelserver
import (
dbutil "erupe-ce/common/db"
"testing"
"github.com/jmoiron/sqlx"
)
func setupScenarioRepo(t *testing.T) (*ScenarioRepository, *sqlx.DB) {
t.Helper()
db := SetupTestDB(t)
repo := NewScenarioRepository(dbutil.Wrap(db))
t.Cleanup(func() { TeardownTestDB(t, db) })
return repo, db
}
func TestRepoScenarioGetCountersEmpty(t *testing.T) {
repo, _ := setupScenarioRepo(t)
counters, err := repo.GetCounters()
if err != nil {
t.Fatalf("GetCounters failed: %v", err)
}
if len(counters) != 0 {
t.Errorf("Expected 0 counters, got: %d", len(counters))
}
}
func TestRepoScenarioGetCounters(t *testing.T) {
repo, db := setupScenarioRepo(t)
if _, err := db.Exec("INSERT INTO scenario_counter (id, scenario_id, category_id) VALUES (1, 100, 0)"); err != nil {
t.Fatalf("Setup failed: %v", err)
}
if _, err := db.Exec("INSERT INTO scenario_counter (id, scenario_id, category_id) VALUES (2, 200, 1)"); err != nil {
t.Fatalf("Setup failed: %v", err)
}
counters, err := repo.GetCounters()
if err != nil {
t.Fatalf("GetCounters failed: %v", err)
}
if len(counters) != 2 {
t.Fatalf("Expected 2 counters, got: %d", len(counters))
}
// Check both values exist (order may vary)
found100, found200 := false, false
for _, c := range counters {
if c.MainID == 100 {
found100 = true
}
if c.MainID == 200 {
found200 = true
}
}
if !found100 || !found200 {
t.Errorf("Expected scenario_ids 100 and 200, got: %+v", counters)
}
}