forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfake_loggregator_consumer.go
68 lines (52 loc) · 1.52 KB
/
fake_loggregator_consumer.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
59
60
61
62
63
64
65
66
67
68
package fakes
import (
"github.com/cloudfoundry/loggregator_consumer"
"github.com/cloudfoundry/loggregatorlib/logmessage"
)
type FakeLoggregatorConsumer struct {
RecentCalledWith struct {
AppGuid string
AuthToken string
}
RecentReturns struct {
Messages []*logmessage.LogMessage
Err []error
callIndex int
}
TailFunc func(appGuid, token string) (<-chan *logmessage.LogMessage, error)
IsClosed bool
OnConnectCallback func()
closeChan chan bool
}
func NewFakeLoggregatorConsumer() *FakeLoggregatorConsumer {
return &FakeLoggregatorConsumer{
closeChan: make(chan bool, 1),
}
}
func (c *FakeLoggregatorConsumer) Recent(appGuid string, authToken string) ([]*logmessage.LogMessage, error) {
c.RecentCalledWith.AppGuid = appGuid
c.RecentCalledWith.AuthToken = authToken
var err error
if c.RecentReturns.callIndex < len(c.RecentReturns.Err) {
err = c.RecentReturns.Err[c.RecentReturns.callIndex]
c.RecentReturns.callIndex++
}
return c.RecentReturns.Messages, err
}
func (c *FakeLoggregatorConsumer) Close() error {
c.IsClosed = true
c.closeChan <- true
return nil
}
func (c *FakeLoggregatorConsumer) SetOnConnectCallback(cb func()) {
c.OnConnectCallback = cb
}
func (c *FakeLoggregatorConsumer) Tail(appGuid string, authToken string) (<-chan *logmessage.LogMessage, error) {
return c.TailFunc(appGuid, authToken)
}
func (c *FakeLoggregatorConsumer) WaitForClose() {
<-c.closeChan
}
func (c *FakeLoggregatorConsumer) SetDebugPrinter(debugPrinter loggregator_consumer.DebugPrinter) {
<-c.closeChan
}