forked from cloudfoundry/go-cfclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
appevents_test.go
84 lines (76 loc) · 2.8 KB
/
appevents_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
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
package cfclient
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestListAppEvents(t *testing.T) {
Convey("List App Events", t, func() {
mocks := []MockRoute{
{"GET", "/v2/events", listAppsCreatedEventPayload, "", 200, "q=type:audit.app.create", nil},
{"GET", "/v2/events2", listAppsCreatedEventPayload2, "", 200, "", nil},
}
setupMultiple(mocks, t)
defer teardown()
c := &Config{
ApiAddress: server.URL,
Token: "foobar",
}
client, err := NewClient(c)
So(err, ShouldBeNil)
appEvents, err := client.ListAppEvents("blub")
So(err.Error(), ShouldEqual, "Unsupported app event type blub")
appEvents, err = client.ListAppEvents(AppCreate)
So(err, ShouldBeNil)
So(len(appEvents), ShouldEqual, 3)
So(appEvents[0].MetaData.Request.State, ShouldEqual, "STOPPED")
So(appEvents[1].EventType, ShouldEqual, AppCrash)
So(appEvents[1].MetaData.Request.State, ShouldEqual, "")
So(appEvents[1].MetaData.ExitReason, ShouldEqual, "CRASHED")
So(appEvents[2].MetaData.Request.State, ShouldEqual, "STARTED")
})
}
func TestListAppEventsByQuery(t *testing.T) {
Convey("List App Events By Query", t, func() {
mocks := []MockRoute{
{"GET", "/v2/events", listAppsCreatedEventPayload, "", 200, "q=type:audit.app.create&q=actee:3ca436ff-67a8-468a-8c7d-27ec68a6cfe5", nil},
{"GET", "/v2/events2", listAppsCreatedEventPayload2, "", 200, "", nil},
}
setupMultiple(mocks, t)
defer teardown()
c := &Config{
ApiAddress: server.URL,
Token: "foobar",
}
client, err := NewClient(c)
So(err, ShouldBeNil)
appEvents, err := client.ListAppEventsByQuery("blub", []AppEventQuery{})
So(err.Error(), ShouldEqual, "Unsupported app event type blub")
appEventQuery := AppEventQuery{
Filter: "nofilter",
Operator: ":",
Value: "retlifon",
}
appEvents, err = client.ListAppEventsByQuery(AppCreate, []AppEventQuery{appEventQuery})
So(err.Error(), ShouldEqual, "Unsupported query filter type nofilter")
appEventQuery = AppEventQuery{
Filter: FilterTimestamp,
Operator: "not",
Value: "retlifon",
}
appEvents, err = client.ListAppEventsByQuery(AppCreate, []AppEventQuery{appEventQuery})
So(err.Error(), ShouldEqual, "Unsupported query operator type not")
appEventQuery = AppEventQuery{
Filter: FilterActee,
Operator: ":",
Value: "3ca436ff-67a8-468a-8c7d-27ec68a6cfe5",
}
appEvents, err = client.ListAppEventsByQuery(AppCreate, []AppEventQuery{appEventQuery})
So(err, ShouldBeNil)
So(len(appEvents), ShouldEqual, 3)
So(appEvents[0].MetaData.Request.State, ShouldEqual, "STOPPED")
So(appEvents[1].EventType, ShouldEqual, AppCrash)
So(appEvents[1].MetaData.Request.State, ShouldEqual, "")
So(appEvents[1].MetaData.ExitReason, ShouldEqual, "CRASHED")
So(appEvents[2].MetaData.Request.State, ShouldEqual, "STARTED")
})
}