Skip to content

Commit

Permalink
test: Added Event.String()
Browse files Browse the repository at this point in the history
Part of #1
  • Loading branch information
christopher-kleine committed Sep 12, 2023
1 parent 8bc4228 commit 546eb90
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions event_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package sse_test

import (
"testing"
"time"

"github.com/christopher-kleine/sse"
)

func TestEventString(t *testing.T) {
testTable := []struct {
input *sse.Event
expected string
}{
{input: &sse.Event{Data: "test"}, expected: "data: test\n\n"},
{input: &sse.Event{Retry: 1 * time.Second}, expected: "retry: 1000\n\n"},
{input: &sse.Event{ID: "1"}, expected: "id: 1\n\n"},
{input: &sse.Event{Event: "foo"}, expected: "event: foo\n\n"},
{input: &sse.Event{Retry: 1 * time.Second, Data: "Dummy"}, expected: "data: Dummy\nretry: 1000\n\n"},
{input: &sse.Event{Data: "foo\nbar"}, expected: "data: foo\ndata: bar\n\n"},
{input: &sse.Event{Data: "foo\nbar\n"}, expected: "data: foo\ndata: bar\n\n"},
}

for _, testCase := range testTable {
actual := testCase.input.String()
if actual != testCase.expected {
t.Errorf("%q should be %q", actual, testCase.expected)
}
}
}

0 comments on commit 546eb90

Please sign in to comment.