diff options
| author | Danilo M. <danix@danix.xyz> | 2026-09-15 18:04:59 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-09-15 18:04:59 +0200 |
| commit | 6ad6f122eb2ec9cd8a55c042dffe38db41ed1959 (patch) | |
| tree | 5cc008927b01b23944c5c3e3d8495e7874aa6cbe /internal/notify/service_test.go | |
| parent | ddf793905cd8739d27003296a5042a7dd905f1d3 (diff) | |
| download | notifyd-6ad6f122eb2ec9cd8a55c042dffe38db41ed1959.tar.gz notifyd-6ad6f122eb2ec9cd8a55c042dffe38db41ed1959.zip | |
test(notify): cover image-data materialisation
TestNotifyMaterialisesImageData drives a 2x2 RGBA image-data hint
through Notify and asserts the PNG is written under the image directory
for the returned id, decodes to the right bounds, and is carried on the
re-published Popup.Image. The encode-error path now logs instead of
dropping the failure silently, matching the WriteImage branch.
Diffstat (limited to 'internal/notify/service_test.go')
| -rw-r--r-- | internal/notify/service_test.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/internal/notify/service_test.go b/internal/notify/service_test.go index 611c8fa..3d7c2cc 100644 --- a/internal/notify/service_test.go +++ b/internal/notify/service_test.go @@ -13,8 +13,10 @@ package notify import ( "encoding/json" + "image/png" "os" "path/filepath" + "strconv" "testing" "time" @@ -96,6 +98,41 @@ func TestNotifyPublishesImagePath(t *testing.T) { } } +func TestNotifyMaterialisesImageData(t *testing.T) { + var live []Popup + s := &Service{dir: t.TempDir(), timers: map[uint32]*time.Timer{}} + s.store = NewStore(s.emitClosed, func(l, _ []Popup) { live = l }, s.removeImage) + // A 2x2 RGBA image, row stride exactly width*channels. + data := []byte{ + 255, 0, 0, 255, 0, 255, 0, 255, + 0, 0, 255, 255, 255, 255, 255, 255, + } + hints := map[string]dbus.Variant{"image-data": dbus.MakeVariant([]interface{}{ + int32(2), int32(2), int32(8), true, int32(8), int32(4), data, + })} + id, dbusErr := s.Notify("t", 0, "", "s", "b", nil, hints, -1) + if dbusErr != nil { + t.Fatal(dbusErr) + } + path := filepath.Join(ImagesDir(s.dir), strconv.FormatUint(uint64(id), 10)+".png") + f, err := os.Open(path) + if err != nil { + t.Fatalf("image not written: %v", err) + } + defer f.Close() + img, err := png.Decode(f) + if err != nil { + t.Fatalf("image does not decode: %v", err) + } + if b := img.Bounds(); b.Dx() != 2 || b.Dy() != 2 { + t.Fatalf("decoded %v, want 2x2", b) + } + // The first publish precedes SetImage, so the last one must carry the path. + if len(live) != 1 || live[0].Image != path { + t.Fatalf("published %+v, want image %q", live, path) + } +} + func TestNotifyReturnsAnIDAndPublishes(t *testing.T) { conn := busOrSkip(t) dir := t.TempDir() |
