1package app
2
3import (
4 "strings"
5 "testing"
6
7 "github.com/bnema/neferwl/internal/ports"
8 "github.com/bnema/zerowrap"
9)
10
11func logTestScenes() []ports.Scene {
12 return []ports.Scene{{
13 Output: "A", Seq: 7, OutputWidth: 1920, OutputHeight: 1080, Scale: 1,
14 Windows: []ports.SceneWindow{
15 {ID: 1, Rect: ports.Rect{X: 10, Y: 20, W: 300, H: 200}},
16 {ID: 2, Rect: ports.Rect{X: 5, Y: 6, W: 7, H: 8}},
17 },
18 }, {Output: "B"}}
19}
20
21// With debug off the scene log builds nothing: no rect strings, no event.
22// Measured before the level check: 3 allocations per run for two scenes.
23func TestLogScenesAllocations(t *testing.T) {
24 out := &lockedBuffer{}
25 log := zerowrap.New(zerowrap.Config{Format: "json", Level: "info", Output: out})
26 set := logTestScenes()
27 if got := testing.AllocsPerRun(100, func() { logScenes(log, set) }); got != 0 {
28 t.Fatalf("logScenes at info level: %g allocations per run, want 0", got)
29 }
30 if out.String() != "" {
31 t.Fatalf("info level logged: %s", out.String())
32 }
33}
34
35func TestLogScenesDebug(t *testing.T) {
36 out := &lockedBuffer{}
37 log := zerowrap.New(zerowrap.Config{Format: "json", Level: "debug", Output: out})
38 logScenes(log, logTestScenes())
39 got := out.String()
40 for _, want := range []string{
41 `"output":"A"`, `"seq":7`, `"out_w":1920`, `"out_h":1080`, `"scale":1`,
42 `"windows":["1:10,20 300x200","2:5,6 7x8"]`,
43 `"message":"scene"`,
44 } {
45 if !strings.Contains(got, want) {
46 t.Fatalf("debug log lacks %s: %s", want, got)
47 }
48 }
49 if n := strings.Count(got, `"message":"scene"`); n != 2 {
50 t.Fatalf("%d scene entries, want 2: %s", n, got)
51 }
52}