test(backend): add RPT log output to server stub
- Stub now parses -profiles= arg and writes RPT entries to profilesDir/arma3server_x64_<timestamp>.rpt - RPT includes header (exe timestamp, computer name, OS) and periodic entries (MissionEditor, World, Server: Player) on each heartbeat cycle - New test TestStart_StubWritesRPTLog verifies RPT file creation and content via the profiles directory
This commit is contained in:
@@ -773,3 +773,77 @@ func TestStart_StubAutoExit(t *testing.T) {
|
||||
t.Error("IsRunning() should be false after stub auto-exited (timeout 2s)")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStart_StubWritesRPTLog(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
serverfileDir := filepath.Join(dir, "server")
|
||||
profilesDir := filepath.Join(dir, "profiles")
|
||||
modsDir := filepath.Join(dir, "mods")
|
||||
cfgDir := filepath.Join(dir, "cfg")
|
||||
os.MkdirAll(serverfileDir, 0755)
|
||||
|
||||
stubSrc, _ := os.ReadFile("testdata/arma3server_x64")
|
||||
os.WriteFile(filepath.Join(serverfileDir, "arma3server_x64"), stubSrc, 0755)
|
||||
|
||||
sm := NewSettingsManager(dir)
|
||||
mm := NewModlistManager(filepath.Join(dir, "modlists"))
|
||||
cm := NewConfigManager(cfgDir)
|
||||
streamer := NewLogStreamer()
|
||||
|
||||
pm := NewProcessManager(serverfileDir, modsDir, cfgDir, profilesDir, sm, mm, cm, streamer)
|
||||
|
||||
s, _ := sm.Load()
|
||||
s.ServerParameters = "-t 7"
|
||||
sm.Save(s)
|
||||
|
||||
if err := pm.Start(); err != nil {
|
||||
t.Fatalf("Start() error = %v", err)
|
||||
}
|
||||
|
||||
// Wait for the stub to write RPT entries (heartbeat at ~5s)
|
||||
deadline := time.Now().Add(8 * time.Second)
|
||||
var rptPath string
|
||||
for time.Now().Before(deadline) {
|
||||
matches, _ := filepath.Glob(filepath.Join(profilesDir, "arma3server_x64_*.rpt"))
|
||||
if len(matches) > 0 {
|
||||
rptPath = matches[0]
|
||||
break
|
||||
}
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
}
|
||||
|
||||
if rptPath == "" {
|
||||
pm.Stop()
|
||||
t.Fatal("RPT file not found in profiles dir")
|
||||
}
|
||||
|
||||
// Wait for heartbeat entries to be written (heartbeat at ~5s)
|
||||
deadline2 := time.Now().Add(6 * time.Second)
|
||||
for time.Now().Before(deadline2) {
|
||||
data, _ := os.ReadFile(rptPath)
|
||||
if strings.Contains(string(data), "MissionEditor") {
|
||||
break
|
||||
}
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(rptPath)
|
||||
if err != nil {
|
||||
pm.Stop()
|
||||
t.Fatalf("ReadFile(%s) error = %v", rptPath, err)
|
||||
}
|
||||
|
||||
content := string(data)
|
||||
if !strings.Contains(content, "RPT log started") {
|
||||
t.Errorf("RPT missing header, got:\n%s", content)
|
||||
}
|
||||
if !strings.Contains(content, "MissionEditor") {
|
||||
t.Errorf("RPT missing MissionEditor entry, got:\n%s", content)
|
||||
}
|
||||
if !strings.Contains(content, "Server: Player") {
|
||||
t.Errorf("RPT missing Server: Player entry, got:\n%s", content)
|
||||
}
|
||||
|
||||
pm.Stop()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user