fix(tests): support multiple built-in game templates 2
CI / validate (push) Failing after 8m5s

This commit is contained in:
2026-08-17 22:03:55 +02:00
parent 395fc668b1
commit d2240cbcc8
6 changed files with 63 additions and 11 deletions
+16 -2
View File
@@ -115,6 +115,7 @@ func authorizationFixture(t *testing.T) (context.Context, *sql.DB, *sqlite.Repos
if err != nil {
t.Fatal(err)
}
snapshot := snapshotByID(t, snapshots, "palworld-official")
if err := repository.Sync(ctx, snapshots); err != nil {
t.Fatal(err)
}
@@ -142,7 +143,7 @@ func authorizationFixture(t *testing.T) (context.Context, *sql.DB, *sqlite.Repos
if err != nil {
t.Fatal(err)
}
preview, err := instance.BuildPreview(snapshots[0], instance.PreviewRequest{DisplayName: "Family Palworld", Slug: "family-palworld", HostPorts: map[string]int{"game": 38211}, MountPaths: map[string]string{"saved": "/srv/game-servers/family-palworld/saved"}, DataOrigin: "new", BackupRetention: 7})
preview, err := instance.BuildPreview(snapshot, instance.PreviewRequest{DisplayName: "Family Palworld", Slug: "family-palworld", HostPorts: map[string]int{"game": 38211}, MountPaths: map[string]string{"saved": "/srv/game-servers/family-palworld/saved"}, DataOrigin: "new", BackupRetention: 7})
if err != nil {
t.Fatal(err)
}
@@ -150,5 +151,18 @@ func authorizationFixture(t *testing.T) (context.Context, *sql.DB, *sqlite.Repos
if err := repository.CreateDraft(ctx, instance.Draft{ID: instanceID, Preview: preview}); err != nil {
t.Fatal(err)
}
return ctx, db, repository, authService, admin, user, instanceID, snapshots[0]
return ctx, db, repository, authService, admin, user, instanceID, snapshot
}
func snapshotByID(t *testing.T, snapshots []catalog.Snapshot, id string) catalog.Snapshot {
t.Helper()
for _, snapshot := range snapshots {
if snapshot.Template.ID == id {
return snapshot
}
}
t.Fatalf("template %q not found", id)
return catalog.Snapshot{}
}
@@ -0,0 +1,20 @@
package instance_test
import (
"testing"
"git.zaynet.fr/DoGaMa/DoGaMa-serv/internal/catalog"
)
func snapshotByID(t *testing.T, snapshots []catalog.Snapshot, id string) catalog.Snapshot {
t.Helper()
for _, snapshot := range snapshots {
if snapshot.Template.ID == id {
return snapshot
}
}
t.Fatalf("template %q not found", id)
return catalog.Snapshot{}
}
@@ -45,12 +45,13 @@ func TestPalworldServerNameIsWrittenBeforeStart(t *testing.T) {
if err != nil {
t.Fatal(err)
}
values, err := instance.ValidateConfiguration(snapshots[0].Template.Configuration.Fields, map[string]string{"server_name": "Mon serveur", "server_description": "x", "max_players": "8", "rest_api_enabled": "true", "rest_api_port": "8212"}, map[string]string{"admin_password": "secret"})
snapshot := snapshotByID(t, snapshots, "palworld-official")
values, err := instance.ValidateConfiguration(snapshot.Template.Configuration.Fields, map[string]string{"server_name": "Mon serveur", "server_description": "x", "max_players": "8", "rest_api_enabled": "true", "rest_api_port": "8212"}, map[string]string{"admin_password": "secret"})
if err != nil {
t.Fatal(err)
}
values["admin_password"] = "secret" // marker only; resolver does not retain it.
resolved, err := instance.ResolveConfiguration(snapshots[0].Template, values)
resolved, err := instance.ResolveConfiguration(snapshot.Template, values)
if err != nil {
t.Fatal(err)
}
+6 -3
View File
@@ -132,10 +132,11 @@ func TestLifecycleInstallStartStopAndSafeContainerDeletion(t *testing.T) {
if err != nil {
t.Fatal(err)
}
snapshot := snapshotByID(t, snapshots, "palworld-official")
if err := repository.Sync(ctx, snapshots); err != nil {
t.Fatal(err)
}
preview, err := instance.BuildPreview(snapshots[0], instance.PreviewRequest{
preview, err := instance.BuildPreview(snapshot, instance.PreviewRequest{
DisplayName: "Family Palworld", Slug: "family-palworld", HostPorts: map[string]int{"game": 38211},
MountPaths: map[string]string{"saved": filepath.Join(t.TempDir(), "saved")}, DataOrigin: "new", BackupRetention: 7,
})
@@ -199,10 +200,11 @@ func TestManualStartPersistsAgentDiagnosticAndStableCode(t *testing.T) {
if err != nil {
t.Fatal(err)
}
snapshot := snapshotByID(t, snapshots, "palworld-official")
if err := repository.Sync(ctx, snapshots); err != nil {
t.Fatal(err)
}
preview, err := instance.BuildPreview(snapshots[0], instance.PreviewRequest{DisplayName: "Failure", Slug: "failure", HostPorts: map[string]int{"game": 38212}, MountPaths: map[string]string{"saved": filepath.Join(t.TempDir(), "saved")}, DataOrigin: "new", BackupRetention: 7})
preview, err := instance.BuildPreview(snapshot, instance.PreviewRequest{DisplayName: "Failure", Slug: "failure", HostPorts: map[string]int{"game": 38212}, MountPaths: map[string]string{"saved": filepath.Join(t.TempDir(), "saved")}, DataOrigin: "new", BackupRetention: 7})
if err != nil {
t.Fatal(err)
}
@@ -246,10 +248,11 @@ func TestInstallPlanRejectedPersistsDiagnostic(t *testing.T) {
if err != nil {
t.Fatal(err)
}
snapshot := snapshotByID(t, snapshots, "palworld-official")
if err := repository.Sync(ctx, snapshots); err != nil {
t.Fatal(err)
}
preview, err := instance.BuildPreview(snapshots[0], instance.PreviewRequest{DisplayName: "Rejected", Slug: "rejected", HostPorts: map[string]int{"game": 38213}, MountPaths: map[string]string{"saved": filepath.Join(t.TempDir(), "saved")}, DataOrigin: "new", BackupRetention: 7})
preview, err := instance.BuildPreview(snapshot, instance.PreviewRequest{DisplayName: "Rejected", Slug: "rejected", HostPorts: map[string]int{"game": 38213}, MountPaths: map[string]string{"saved": filepath.Join(t.TempDir(), "saved")}, DataOrigin: "new", BackupRetention: 7})
if err != nil {
t.Fatal(err)
}
+2 -2
View File
@@ -57,7 +57,7 @@ func TestCatalogSyncIsImmutableAndDraftPinsSnapshot(t *testing.T) {
var foundPalworld bool
for _, summary := range summaries {
if summary.TemplateID == palworld.Template.ID {
if summary.ID == palworld.Template.ID {
foundPalworld = true
if summary.Digest != palworld.Digest {
t.Fatalf(
@@ -323,7 +323,7 @@ func TestSyncActivatesCurrentBundledSnapshotWithoutDiscardingHistory(t *testing.
var activePalworldFound bool
for _, summary := range summaries {
if summary.TemplateID != palworld.Template.ID {
if summary.ID != palworld.Template.ID {
continue
}
+16 -2
View File
@@ -1030,6 +1030,19 @@ func assertStatus(t *testing.T, response *httptest.ResponseRecorder, expected in
}
}
func snapshotByID(t *testing.T, snapshots []catalog.Snapshot, id string) catalog.Snapshot {
t.Helper()
for _, snapshot := range snapshots {
if snapshot.Template.ID == id {
return snapshot
}
}
t.Fatalf("template %q not found", id)
return catalog.Snapshot{}
}
func TestCatalogPagesAndAdminScan(t *testing.T) {
ctx := context.Background()
db, err := sqlite.Open(ctx, filepath.Join(t.TempDir(), "dogama.db"))
@@ -1042,6 +1055,7 @@ func TestCatalogPagesAndAdminScan(t *testing.T) {
if err != nil {
t.Fatal(err)
}
palworld := snapshotByID(t, snapshots, "palworld-official")
if err := repository.Replace(ctx, snapshots); err != nil {
t.Fatal(err)
}
@@ -1070,14 +1084,14 @@ func TestCatalogPagesAndAdminScan(t *testing.T) {
adminCookies := []*http.Cookie{{Name: sessionCookie, Value: admin.Token}, {Name: csrfCookie, Value: admin.CSRFToken}}
page := request(t, handler, http.MethodGet, "/catalog", adminCookies)
assertStatus(t, page, http.StatusOK)
for _, expected := range []string{"Palworld", snapshots[0].Template.Game.Artwork.Image, "/catalog/palworld-official", "Scan"} {
for _, expected := range []string{"Palworld", palworld.Template.Game.Artwork.Image, "/catalog/palworld-official", "Scan"} {
if !strings.Contains(page.Body.String(), expected) {
t.Fatalf("catalog missing %q", expected)
}
}
detail := request(t, handler, http.MethodGet, "/catalog/palworld-official", adminCookies)
assertStatus(t, detail, http.StatusOK)
for _, expected := range []string{snapshots[0].Template.Game.Description, "Minimum", "Recommended", "Deploy"} {
for _, expected := range []string{palworld.Template.Game.Description, "Minimum", "Recommended", "Deploy"} {
if !strings.Contains(detail.Body.String(), expected) {
t.Fatalf("detail missing %q", expected)
}