Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
treethought committed Nov 1, 2024
1 parent 97f0f91 commit 6ace237
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions api/client/event/event_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,24 @@ func TestEventStream(t *testing.T) {
}
}
}

func TestEventStreamRequestError(t *testing.T) {
topics := []string{"head"}
eventsChannel := make(chan *Event, 1)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// use valid url that will result in failed request with nil body
stream, err := NewEventStream(ctx, http.DefaultClient, "http://badhost:1234", topics)
require.NoError(t, err)

// error will happen when request is made, should be received over events channel
go stream.Subscribe(eventsChannel)

select {
case event := <-eventsChannel:
if event.EventType != EventConnectionError {
t.Errorf("Expected event type %q, got %q", EventConnectionError, event.EventType)
}
}
}

0 comments on commit 6ace237

Please sign in to comment.