package httputil_test import ( "net/http" "testing" "time" "git.phc.dm.unipi.it/aziis98/posti-dm/server/httputil" ) func TestSSE(t *testing.T) { var broadcastChannel chan<- string go func() { for { if broadcastChannel != nil { broadcastChannel <- "Messaggio per tutti" } time.Sleep(1 * time.Second) } }() http.Handle("/sse", httputil.HandleSSE(func(broadcast, single chan<- string) { broadcastChannel = broadcast time.Sleep(1 * time.Second) single <- "Messaggio 1 per questo client" single <- "Messaggio 2 per questo client" })) http.ListenAndServe(":8000", nil) }