package events
import (
"testing"
"time"
)
// WatchRepos names the repository each index round is for, dots and all,
// so a view shared by every visitor can keep to the repositories one
// visitor may list; a cancelled watcher hears nothing more.
func TestWatchReposNamesTheRepository(t *testing.T) {
s := testServer(t)
got := make(chan string, 4)
cancel := s.WatchRepos(func(repo string) { got <- repo })
for _, name := range []string{"alpha", "a.b"} {
if err := s.Indexed(name); err != nil {
t.Fatal(err)
}
select {
case have := <-got:
if have != name {
t.Errorf("FAIL: a round of %q was announced as %q", name, have)
}
case <-time.After(3 * time.Second):
t.Fatalf("FAIL: no announcement for %q", name)
}
}
cancel()
if err := s.Indexed("alpha"); err != nil {
t.Fatal(err)
}
select {
case have := <-got:
t.Errorf("FAIL: a cancelled watcher heard %q", have)
case <-time.After(300 * time.Millisecond):
}
if !t.Failed() {
t.Log("ok")
}
}