Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

event/event_test: add TestSubscribe #26

Merged
merged 1 commit into from
Sep 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading