Skip to content

Commit

Permalink
event/event_test: add TestReceive
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagokokada committed Aug 31, 2024
1 parent 9eeb885 commit 12996a9
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions event/event_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package event

import (
"os"
"testing"
"time"

"github.com/thiagokokada/hyprland-go"
"github.com/thiagokokada/hyprland-go/internal/assert"
)

Expand All @@ -15,6 +18,30 @@ type FakeEventHandler struct {
EventHandler
}

func TestReceive(t *testing.T) {
if os.Getenv("HYPRLAND_INSTANCE_SIGNATURE") == "" {
t.Skip("HYPRLAND_INSTANCE_SIGNATURE not set, skipping test")
}

// Generate an event
go func() {
c := hyprland.MustClient()
time.Sleep(100 * time.Millisecond)
c.Dispatch("exec kitty")
}()

// We must capture this event
c := MustEventClient()
data, err := c.Receive()

assert.NoError(t, err)
assert.True(t, len(data) >= 0)
for _, d := range data {
assert.NotEqual(t, string(d.Data), "")
assert.NotEqual(t, string(d.Type), "")
}
}

func TestSubscribe(t *testing.T) {
h := &FakeEventHandler{t: t}
c := &FakeEventClient{}
Expand Down

0 comments on commit 12996a9

Please sign in to comment.