-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathapp_test.go
More file actions
100 lines (73 loc) · 1.98 KB
/
app_test.go
File metadata and controls
100 lines (73 loc) · 1.98 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package kage_test
import (
"testing"
"github.com/msales/kage"
"github.com/msales/kage/store"
"github.com/msales/kage/testutil/mocks"
"github.com/stretchr/testify/assert"
)
func TestNewApplication(t *testing.T) {
app := kage.NewApplication()
assert.IsType(t, &kage.Application{}, app)
}
func TestApplication_Close(t *testing.T) {
store := new(mocks.MockStore)
store.On("Close").Return()
monitor := new(mocks.MockMonitor)
monitor.On("Close").Return()
app := &kage.Application{
Store: store,
Monitor: monitor,
}
app.Close()
store.AssertExpectations(t)
monitor.AssertExpectations(t)
}
func TestApplication_IsHealthy(t *testing.T) {
reporters := &kage.Reporters{}
monitor := new(mocks.MockMonitor)
monitor.On("IsHealthy").Return(true).Once()
monitor.On("IsHealthy").Return(false).Once()
app := &kage.Application{
Reporters: reporters,
Monitor: monitor,
}
assert.True(t, app.IsHealthy())
assert.False(t, app.IsHealthy())
monitor.AssertExpectations(t)
}
func TestApplication_IsHealthyNoServices(t *testing.T) {
app := &kage.Application{}
assert.False(t, app.IsHealthy())
}
func TestApplication_Report(t *testing.T) {
bo := store.BrokerOffsets{}
bm := store.BrokerMetadata{}
co := store.ConsumerOffsets{}
store := new(mocks.MockStore)
store.On("BrokerOffsets").Return(bo)
store.On("BrokerMetadata").Return(bm)
store.On("ConsumerOffsets").Return(co)
reporters := &kage.Reporters{}
reporter := new(mocks.MockReporter)
reporter.On("ReportBrokerOffsets", &bo).Return()
reporter.On("ReportBrokerMetadata", &bm).Return()
reporter.On("ReportConsumerOffsets", &co).Return()
reporters.Add("test", reporter)
app := &kage.Application{
Store: store,
Reporters: reporters,
}
app.Report()
store.AssertExpectations(t)
reporter.AssertExpectations(t)
}
func TestApplication_Collect(t *testing.T) {
monitor := new(mocks.MockMonitor)
monitor.On("Collect").Once()
app := &kage.Application{
Monitor: monitor,
}
app.Collect()
monitor.AssertExpectations(t)
}