forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_logs_repository.go
46 lines (37 loc) · 1.18 KB
/
fake_logs_repository.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
package api
import (
"github.com/cloudfoundry/loggregatorlib/logmessage"
"time"
)
type FakeLogsRepository struct {
AppLoggedGuid string
RecentLogs []*logmessage.Message
TailLogMessages []*logmessage.Message
TailLogStopCalled bool
TailLogErr error
}
func (l *FakeLogsRepository) RecentLogsFor(appGuid string, onConnect func(), logChan chan *logmessage.Message) (err error) {
stopLoggingChan := make(chan bool)
defer close(stopLoggingChan)
l.logsFor(appGuid, l.RecentLogs, onConnect, logChan, stopLoggingChan)
return
}
func (l *FakeLogsRepository) TailLogsFor(appGuid string, onConnect func(), logChan chan *logmessage.Message, stopLoggingChan chan bool, printInterval time.Duration) (err error) {
err = l.TailLogErr
if err != nil {
return
}
l.logsFor(appGuid, l.TailLogMessages, onConnect, logChan, stopLoggingChan)
return
}
func (l *FakeLogsRepository) logsFor(appGuid string, logMessages []*logmessage.Message, onConnect func(), logChan chan *logmessage.Message, stopLoggingChan chan bool) {
l.AppLoggedGuid = appGuid
onConnect()
for _, logMsg := range logMessages {
logChan <- logMsg
}
go func() {
l.TailLogStopCalled = <-stopLoggingChan
}()
return
}