-
Notifications
You must be signed in to change notification settings - Fork 336
/
observer_test.go
58 lines (44 loc) · 971 Bytes
/
observer_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
56
57
58
package rxgo
import (
"testing"
"errors"
"github.com/reactivex/rxgo/handlers"
"github.com/stretchr/testify/assert"
)
func TestCreateNewObserverWithConstructor(t *testing.T) {
ob := NewObserver()
ob.OnDone()
ob.OnError(errors.New(""))
ob.OnNext("")
ob.OnNext(errors.New(""))
}
func TestCreateNewObserverWithObserver(t *testing.T) {
nexttext := ""
donetext := ""
nextf := handlers.NextFunc(func(item interface{}) {
if text, ok := item.(string); ok {
nexttext = text
}
})
donef := handlers.DoneFunc(func() {
donetext = "Hello"
})
ob := NewObserver(donef, nextf)
ob.OnNext("Next")
ob.OnDone()
assert.Equal(t, "Next", nexttext)
assert.Equal(t, "Hello", donetext)
}
func TestHandle(t *testing.T) {
i := 0
nextf := handlers.NextFunc(func(item interface{}) {
i = i + 5
})
errorf := handlers.ErrFunc(func(error) {
i = i + 2
})
ob := NewObserver(nextf, errorf)
ob.Handle("")
ob.Handle(errors.New(""))
assert.Equal(t, 7, i)
}