Files
Reims-Go/internal/app/window_launch_test.go
T

49 lines
1.3 KiB
Go

package app
import (
"fmt"
"path/filepath"
"testing"
"github.com/Nwflower/reims-go/internal/config"
)
func TestLogCaptureKeepsLastLinesOfItsSource(t *testing.T) {
a := &App{cfg: config.Default()}
c := a.captureLogs("m0")
for i := 0; i < logCaptureMax+3; i++ {
a.emitLog("m0", fmt.Sprintf("line %d", i))
}
a.emitLog("other", "not mine")
lines := a.releaseLogs("m0", c)
if len(lines) != logCaptureMax || lines[0] != "line 3" || lines[len(lines)-1] != fmt.Sprintf("line %d", logCaptureMax+2) {
t.Fatalf("captured %q", lines)
}
a.emitLog("m0", "after release")
if len(c.lines) != logCaptureMax || len(a.logCaptures) != 0 {
t.Fatal("a released capture must stop collecting")
}
}
func TestStartResultPathStaysInTempDir(t *testing.T) {
cfg := config.Default()
cfg.DataRoot = `D:\Data\reims-go`
a := &App{cfg: cfg}
tmp := cfg.TempDir()
good := filepath.Join(tmp, "cli-start-123.json")
if got := a.startResultPath(good); got != good {
t.Fatalf("own result file rejected: %q", got)
}
for _, bad := range []string{
filepath.Join(tmp, "..", "reims-go.json"),
filepath.Join(tmp, "sub", "cli-start-1.json"),
filepath.Join(tmp, "notes.json"),
`C:\Windows\cli-start-1.json`,
} {
if got := a.startResultPath(bad); got != "" {
t.Errorf("startResultPath(%q) = %q, want rejected", bad, got)
}
}
}