package main import ( "encoding/json" "os" "path/filepath" "reflect" "testing" ) // Whatever the panel exports must come back unchanged after import and export. func TestImportRoundTrip(t *testing.T) { game := map[string]any{ "id": "round-trip", "name": "Round Trip", "defaultDockerImage": "debian:12", "installMethod": "NONE", "defaultStartupCommand": "./start.sh -log", "requiredMemoryMb": float64(4096), "configFormatOptions": map[string]any{ "separator": "\n", "footer": "\n", "header": "[Section]\n", "assignment": "=", "space": " ", "multi": "[A]\nOptionSettings=(", "quoteStrings": true, }, "installConfig": map[string]any{"script": "#!/bin/bash\nset -e\necho hi\n"}, "defaultConfig": map[string]any{"Rate": "1.000000", "Port": float64(7777), "Empty": "", "Ratio": 0.5}, } dir := t.TempDir() path := filepath.Join(dir, "game.yaml") if err := writeGame(path, game); err != nil { t.Fatal(err) } raw, err := os.ReadFile(path) if err != nil { t.Fatal(err) } loaded, err := loadYAML(raw) if err != nil { t.Fatal(err) } // Compare as JSON, the way the panel receives it var got, want any gotJSON, _ := json.Marshal(loaded) wantJSON, _ := json.Marshal(game) json.Unmarshal(gotJSON, &got) json.Unmarshal(wantJSON, &want) if !reflect.DeepEqual(got, want) { t.Fatalf("round trip changed the template\n got: %s\nwant: %s\nyaml:\n%s", gotJSON, wantJSON, raw) } }