forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtesting.go
46 lines (35 loc) · 907 Bytes
/
testing.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 module
import (
"encoding/json"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/testing"
)
// testingReporter offers reported interface and send results to testing.Driver
type testingReporter struct {
driver testing.Driver
done <-chan struct{}
}
func (r *testingReporter) Done() <-chan struct{} {
return r.done
}
func (r *testingReporter) Event(event common.MapStr) bool {
return r.ErrorWith(nil, event)
}
func (r *testingReporter) Error(err error) bool {
return r.ErrorWith(err, nil)
}
func (r *testingReporter) ErrorWith(err error, event common.MapStr) bool {
if err != nil {
r.driver.Error("error", err)
}
if event != nil {
d, err := json.MarshalIndent(&event, "", " ")
if err != nil {
r.driver.Error("convert event", err)
return true
}
r.driver.Result(string(d))
}
return true
}
func (r testingReporter) StartFetchTimer() {}