github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/zhttp/sse_test.go (about) 1 package zhttp 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/sohaha/zlsgo" 8 ) 9 10 func TestSSE(t *testing.T) { 11 tt := zlsgo.NewTest(t) 12 13 time.Sleep(time.Second) 14 15 s := SSE("http://127.0.0.1:18181/sse", NoRedirect(true)) 16 i := 0 17 c, err := s.OnMessage(func(ev *SSEEvent) { 18 t.Logf("id:%s msg:%s [%s] %s\n", ev.ID, string(ev.Data), ev.Event, ev.Undefined) 19 i++ 20 }) 21 22 if err != nil { 23 t.Error(err) 24 return 25 } 26 <-c 27 tt.Equal(2, i) 28 }