2015-04-28 22:30:51 +00:00
|
|
|
package builtin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2015-05-22 18:37:40 +00:00
|
|
|
. "github.com/drone/drone/Godeps/_workspace/src/github.com/franela/goblin"
|
2015-05-17 18:10:43 +00:00
|
|
|
"github.com/drone/drone/pkg/bus"
|
2015-04-28 22:30:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBuild(t *testing.T) {
|
|
|
|
g := Goblin(t)
|
|
|
|
g.Describe("Bus", func() {
|
|
|
|
|
|
|
|
g.It("Should unsubscribe", func() {
|
2015-05-17 18:10:43 +00:00
|
|
|
c1 := make(chan *bus.Event)
|
|
|
|
c2 := make(chan *bus.Event)
|
2015-04-28 22:30:51 +00:00
|
|
|
b := New()
|
|
|
|
b.Subscribe(c1)
|
|
|
|
b.Subscribe(c2)
|
|
|
|
g.Assert(len(b.subs)).Equal(2)
|
|
|
|
})
|
|
|
|
|
|
|
|
g.It("Should subscribe", func() {
|
2015-05-17 18:10:43 +00:00
|
|
|
c1 := make(chan *bus.Event)
|
|
|
|
c2 := make(chan *bus.Event)
|
2015-04-28 22:30:51 +00:00
|
|
|
b := New()
|
|
|
|
b.Subscribe(c1)
|
|
|
|
b.Subscribe(c2)
|
|
|
|
g.Assert(len(b.subs)).Equal(2)
|
|
|
|
b.Unsubscribe(c1)
|
|
|
|
b.Unsubscribe(c2)
|
|
|
|
g.Assert(len(b.subs)).Equal(0)
|
|
|
|
})
|
|
|
|
|
|
|
|
g.It("Should send", func() {
|
2015-08-20 17:57:46 +00:00
|
|
|
em := map[string]bool{"foo": true, "bar": true}
|
2015-05-17 18:10:43 +00:00
|
|
|
e1 := &bus.Event{Name: "foo"}
|
|
|
|
e2 := &bus.Event{Name: "bar"}
|
|
|
|
c := make(chan *bus.Event)
|
2015-04-28 22:30:51 +00:00
|
|
|
b := New()
|
|
|
|
b.Subscribe(c)
|
|
|
|
b.Send(e1)
|
|
|
|
b.Send(e2)
|
|
|
|
r1 := <-c
|
|
|
|
r2 := <-c
|
2015-08-20 17:57:46 +00:00
|
|
|
g.Assert(em[r1.Name]).Equal(true)
|
|
|
|
g.Assert(em[r2.Name]).Equal(true)
|
2015-04-28 22:30:51 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|