docs: rewrite PLAN.md and update CODEBASE.md, README.md
- Full rewrite of PLAN.md to reflect current architecture (27 REST + 3 WS endpoints, embedded frontend, automation, scheduler, health check, GoReleaser CI) - Added health.go, mods.go, scheduler.go, robfig/cron dep to CODEBASE.md - Added Gitea Actions CI/CD section to CODEBASE.md - Added conventional commits to code style section - Added missing API routes and embed/ to README.md
This commit is contained in:
@@ -0,0 +1,147 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"arma3-web-server/internal/models"
|
||||
)
|
||||
|
||||
func TestModlistManager_CreateAndGet(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
mm := NewModlistManager(dir)
|
||||
|
||||
ml, err := mm.Create("My Modlist")
|
||||
if err != nil {
|
||||
t.Fatalf("Create() error = %v", err)
|
||||
}
|
||||
if ml.Name != "My Modlist" {
|
||||
t.Errorf("Name = %q, want %q", ml.Name, "My Modlist")
|
||||
}
|
||||
if ml.ID == "" {
|
||||
t.Error("ID should not be empty")
|
||||
}
|
||||
if len(ml.Mods) != 0 {
|
||||
t.Errorf("Mods should be empty, got %d", len(ml.Mods))
|
||||
}
|
||||
|
||||
got, err := mm.Get(ml.ID)
|
||||
if err != nil {
|
||||
t.Fatalf("Get() error = %v", err)
|
||||
}
|
||||
if got.Name != "My Modlist" {
|
||||
t.Errorf("Get().Name = %q, want %q", got.Name, "My Modlist")
|
||||
}
|
||||
}
|
||||
|
||||
func TestModlistManager_List(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
mm := NewModlistManager(dir)
|
||||
|
||||
mm.Create("List A")
|
||||
mm.Create("List B")
|
||||
|
||||
items, err := mm.List()
|
||||
if err != nil {
|
||||
t.Fatalf("List() error = %v", err)
|
||||
}
|
||||
if len(items) != 2 {
|
||||
t.Errorf("List() returned %d items, want 2", len(items))
|
||||
}
|
||||
|
||||
names := map[string]bool{}
|
||||
for _, item := range items {
|
||||
names[item.Name] = true
|
||||
}
|
||||
if !names["List A"] || !names["List B"] {
|
||||
t.Errorf("List() missing expected names: %v", names)
|
||||
}
|
||||
}
|
||||
|
||||
func TestModlistManager_Update(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
mm := NewModlistManager(dir)
|
||||
|
||||
ml, _ := mm.Create("Original")
|
||||
mods := []models.ModEntry{
|
||||
{ID: "123", Name: "CBA_A3", Enabled: true},
|
||||
{ID: "456", Name: "ACE", Enabled: false},
|
||||
}
|
||||
|
||||
updated, err := mm.Update(ml.ID, "Updated", mods)
|
||||
if err != nil {
|
||||
t.Fatalf("Update() error = %v", err)
|
||||
}
|
||||
if updated.Name != "Updated" {
|
||||
t.Errorf("Name = %q, want %q", updated.Name, "Updated")
|
||||
}
|
||||
if len(updated.Mods) != 2 {
|
||||
t.Errorf("Mods = %d, want 2", len(updated.Mods))
|
||||
}
|
||||
|
||||
got, _ := mm.Get(ml.ID)
|
||||
if got.Name != "Updated" {
|
||||
t.Errorf("Get().Name = %q, want %q", got.Name, "Updated")
|
||||
}
|
||||
if got.Mods[0].ID != "123" {
|
||||
t.Errorf("Get().Mods[0].ID = %q, want %q", got.Mods[0].ID, "123")
|
||||
}
|
||||
}
|
||||
|
||||
func TestModlistManager_Delete(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
mm := NewModlistManager(dir)
|
||||
|
||||
ml, _ := mm.Create("To Delete")
|
||||
if err := mm.Delete(ml.ID); err != nil {
|
||||
t.Fatalf("Delete() error = %v", err)
|
||||
}
|
||||
|
||||
_, err := mm.Get(ml.ID)
|
||||
if err == nil {
|
||||
t.Error("Get() should fail after Delete()")
|
||||
}
|
||||
}
|
||||
|
||||
func TestModlistManager_Duplicate(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
mm := NewModlistManager(dir)
|
||||
|
||||
orig, _ := mm.Create("Original")
|
||||
mm.Update(orig.ID, "Original", []models.ModEntry{
|
||||
{ID: "123", Name: "CBA_A3", Enabled: true},
|
||||
})
|
||||
|
||||
dup, err := mm.Duplicate(orig.ID, "Copy")
|
||||
if err != nil {
|
||||
t.Fatalf("Duplicate() error = %v", err)
|
||||
}
|
||||
if dup.Name != "Copy" {
|
||||
t.Errorf("Name = %q, want %q", dup.Name, "Copy")
|
||||
}
|
||||
if dup.ID == orig.ID {
|
||||
t.Error("Duplicate should have different ID")
|
||||
}
|
||||
if len(dup.Mods) != 1 {
|
||||
t.Errorf("Mods = %d, want 1", len(dup.Mods))
|
||||
}
|
||||
}
|
||||
|
||||
func TestModlistManager_GetNotFound(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
mm := NewModlistManager(dir)
|
||||
|
||||
_, err := mm.Get("nonexistent-uuid")
|
||||
if err == nil {
|
||||
t.Error("Get() should fail for nonexistent modlist")
|
||||
}
|
||||
}
|
||||
|
||||
func TestModlistManager_DeleteNotFound(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
mm := NewModlistManager(dir)
|
||||
|
||||
err := mm.Delete("nonexistent-uuid")
|
||||
if err == nil {
|
||||
t.Error("Delete() should fail for nonexistent modlist")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user