1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-11-30 08:06:52 +02:00
woodpecker/engine/bus_test.go

51 lines
955 B
Go
Raw Normal View History

2015-09-30 03:21:17 +02:00
package engine
2015-04-29 00:30:51 +02:00
import (
"testing"
2015-09-30 03:21:17 +02:00
. "github.com/franela/goblin"
2015-04-29 00:30:51 +02:00
)
2015-09-30 03:21:17 +02:00
func TestBus(t *testing.T) {
2015-04-29 00:30:51 +02:00
g := Goblin(t)
2015-09-30 03:21:17 +02:00
g.Describe("Event bus", func() {
2015-04-29 00:30:51 +02:00
g.It("Should unsubscribe", func() {
2015-09-30 03:21:17 +02:00
c1 := make(chan *Event)
c2 := make(chan *Event)
b := newEventbus()
b.subscribe(c1)
b.subscribe(c2)
2015-04-29 00:30:51 +02:00
g.Assert(len(b.subs)).Equal(2)
})
g.It("Should subscribe", func() {
2015-09-30 03:21:17 +02:00
c1 := make(chan *Event)
c2 := make(chan *Event)
b := newEventbus()
b.subscribe(c1)
b.subscribe(c2)
2015-04-29 00:30:51 +02:00
g.Assert(len(b.subs)).Equal(2)
2015-09-30 03:21:17 +02:00
b.unsubscribe(c1)
b.unsubscribe(c2)
2015-04-29 00:30:51 +02:00
g.Assert(len(b.subs)).Equal(0)
})
g.It("Should send", func() {
2015-08-20 19:57:46 +02:00
em := map[string]bool{"foo": true, "bar": true}
2015-09-30 03:21:17 +02:00
e1 := &Event{Name: "foo"}
e2 := &Event{Name: "bar"}
c := make(chan *Event)
b := newEventbus()
b.subscribe(c)
b.send(e1)
b.send(e2)
2015-04-29 00:30:51 +02:00
r1 := <-c
r2 := <-c
2015-08-20 19:57:46 +02:00
g.Assert(em[r1.Name]).Equal(true)
g.Assert(em[r2.Name]).Equal(true)
2015-04-29 00:30:51 +02:00
})
})
}