-
Notifications
You must be signed in to change notification settings - Fork 0
/
sequential_listener_test.go
55 lines (48 loc) · 1.6 KB
/
sequential_listener_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package dominoes
import (
"errors"
"testing"
"github.com/smarty/assertions/should"
"github.com/smarty/gunit"
)
func TestSequentialListenerFixture(t *testing.T) {
gunit.Run(new(SequentialListenerFixture), t)
}
type SequentialListenerFixture struct {
*gunit.Fixture
inner1 *fakeListener
inner2 *fakeListener
inner3 *fakeListener
outer ListenCloser
}
func (this *SequentialListenerFixture) Setup() {
this.inner1 = newFakeListener()
this.inner2 = newFakeListener()
this.inner3 = newFakeListener()
this.outer = NewSequentialListener(this.inner1, this.inner2, this.inner3)
}
func (this *SequentialListenerFixture) TestListen() {
this.outer.Listen()
this.So(this.inner1.listenCount, should.Equal, 1)
this.So(this.inner2.listenCount, should.Equal, 1)
this.So(this.inner3.listenCount, should.Equal, 1)
this.So(this.inner1.listenTime, should.HappenBefore, this.inner2.listenTime)
this.So(this.inner2.listenTime, should.HappenBefore, this.inner3.listenTime)
}
func (this *SequentialListenerFixture) TestClose_NoError() {
err := this.outer.Close()
this.So(err, should.BeNil)
this.So(this.inner1.closeCount, should.Equal, 1)
this.So(this.inner2.closeCount, should.Equal, 1)
this.So(this.inner3.closeCount, should.Equal, 1)
this.So(this.inner1.closeTime, should.HappenBefore, this.inner2.closeTime)
this.So(this.inner2.closeTime, should.HappenBefore, this.inner3.closeTime)
}
func (this *SequentialListenerFixture) TestClose_LastErrorReturned() {
err1 := errors.New("1")
err3 := errors.New("3")
this.inner1.closeError = err1
this.inner3.closeError = err3
err := this.outer.Close()
this.So(err, should.Equal, err3)
}