Skip to content

Commit

Permalink
Merge pull request #26 from thiagokokada/add-test-subscribe-test
Browse files Browse the repository at this point in the history
event/event_test: add TestSubscribe
  • Loading branch information
thiagokokada authored Sep 1, 2024
2 parents a47466e + 1690f69 commit 0021720
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions event/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package event

import (
"context"
"errors"
"os"
"testing"
"time"
Expand Down Expand Up @@ -44,6 +45,27 @@ func TestReceive(t *testing.T) {
}
}

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

c := MustClient()
defer c.Close()
ctx, cancel := context.WithTimeout(
context.Background(),
100*time.Millisecond,
)
defer cancel()

// Make sure that we can exit a Subscribe loop by cancelling the
// context
err := c.Subscribe(ctx, &DefaultEventHandler{}, AllEvents...)

assert.Error(t, err)
assert.True(t, errors.Is(err, context.DeadlineExceeded))
}

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

0 comments on commit 0021720

Please sign in to comment.