Skip to content

Commit 56193ba

Browse files
authored
Switch tests to ActualLRPInstance event stream (#10)
1 parent 4e1a6d0 commit 56193ba

File tree

2 files changed

+39
-45
lines changed

2 files changed

+39
-45
lines changed

event_stream_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var _ = Describe("EventStream", func() {
2727
BeforeEach(func() {
2828
var err error
2929
desiredLRP = DesiredLRPWithGuid(guid)
30-
eventSource, err = bbsClient.SubscribeToEvents(logger)
30+
eventSource, err = bbsClient.SubscribeToInstanceEvents(logger)
3131
Expect(err).NotTo(HaveOccurred())
3232

3333
done = make(chan struct{})
@@ -56,12 +56,12 @@ var _ = Describe("EventStream", func() {
5656
It("should receive events as the LRP goes through its lifecycle", func() {
5757
bbsClient.DesireLRP(logger, traceID, desiredLRP)
5858
Eventually(getEvents).Should(ContainElement(MatchDesiredLRPCreatedEvent(guid)))
59-
Eventually(getEvents).Should(ContainElement(MatchActualLRPCreatedEvent(guid, 0)))
60-
Eventually(getEvents).Should(ContainElement(MatchActualLRPChangedEvent(guid, 0, models.ActualLRPStateClaimed)))
61-
Eventually(getEvents).Should(ContainElement(MatchActualLRPChangedEvent(guid, 0, models.ActualLRPStateRunning)))
59+
Eventually(getEvents).Should(ContainElement(MatchActualLRPInstanceCreatedEvent(guid, 0)))
60+
Eventually(getEvents).Should(ContainElement(MatchActualLRPInstanceChangedEvent(guid, 0, models.ActualLRPStateClaimed)))
61+
Eventually(getEvents).Should(ContainElement(MatchActualLRPInstanceChangedEvent(guid, 0, models.ActualLRPStateRunning)))
6262

6363
bbsClient.RemoveDesiredLRP(logger, traceID, guid)
6464
Eventually(getEvents).Should(ContainElement(MatchDesiredLRPRemovedEvent(guid)))
65-
Eventually(getEvents).Should(ContainElement(MatchActualLRPRemovedEvent(guid, 0)))
65+
Eventually(getEvents).Should(ContainElement(MatchActualLRPInstanceRemovedEvent(guid, 0)))
6666
})
6767
})

matchers/match_bbs_event.go

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -93,105 +93,99 @@ func (matcher *DesiredLRPRemovedEventMatcher) NegatedFailureMessage(actual inter
9393

9494
//
9595

96-
func MatchActualLRPCreatedEvent(processGuid string, index int) gomega.OmegaMatcher {
97-
return &ActualLRPCreatedEventMatcher{
96+
func MatchActualLRPInstanceCreatedEvent(processGuid string, index int) gomega.OmegaMatcher {
97+
return &ActualLRPInstanceCreatedEventMatcher{
9898
ProcessGuid: processGuid,
9999
Index: index,
100100
}
101101
}
102102

103-
type ActualLRPCreatedEventMatcher struct {
103+
type ActualLRPInstanceCreatedEventMatcher struct {
104104
ProcessGuid string
105105
Index int
106106
}
107107

108-
func (matcher *ActualLRPCreatedEventMatcher) Match(actual interface{}) (success bool, err error) {
109-
event, ok := actual.(*models.ActualLRPCreatedEvent)
108+
func (matcher *ActualLRPInstanceCreatedEventMatcher) Match(actual interface{}) (success bool, err error) {
109+
event, ok := actual.(*models.ActualLRPInstanceCreatedEvent)
110110
if !ok {
111-
return false, fmt.Errorf("ActualLRPCreatedEventMatcher matcher expects a models.ActualLRPCreatedEvent. Got:\n%s", format.Object(actual, 1))
112-
}
113-
actualLRP, _, err := event.ActualLrpGroup.Resolve()
114-
if err != nil {
115-
return false, err
111+
return false, fmt.Errorf("ActualLRPInstanceCreatedEventMatcher matcher expects a models.ActualLRPInstanceCreatedEvent. Got:\n%s", format.Object(actual, 1))
116112
}
113+
actualLRP := event.ActualLrp
117114
return actualLRP.ProcessGuid == matcher.ProcessGuid && actualLRP.Index == int32(matcher.Index), nil
118115
}
119116

120-
func (matcher *ActualLRPCreatedEventMatcher) FailureMessage(actual interface{}) (message string) {
121-
return fmt.Sprintf("Expected\n%s\nto be a ActualLRPCreatedEvent with\n ProcessGuid=%s\n Index=%d", format.Object(actual, 1), matcher.ProcessGuid, matcher.Index)
117+
func (matcher *ActualLRPInstanceCreatedEventMatcher) FailureMessage(actual interface{}) (message string) {
118+
return fmt.Sprintf("Expected\n%s\nto be a ActualLRPInstanceCreatedEvent with\n ProcessGuid=%s\n Index=%d", format.Object(actual, 1), matcher.ProcessGuid, matcher.Index)
122119
}
123120

124-
func (matcher *ActualLRPCreatedEventMatcher) NegatedFailureMessage(actual interface{}) (message string) {
125-
return fmt.Sprintf("Expected\n%s\nnot to be a ActualLRPCreatedEvent with\n ProcessGuid=%s\n Index=%d", format.Object(actual, 1), matcher.ProcessGuid, matcher.Index)
121+
func (matcher *ActualLRPInstanceCreatedEventMatcher) NegatedFailureMessage(actual interface{}) (message string) {
122+
return fmt.Sprintf("Expected\n%s\nnot to be a ActualLRPInstanceCreatedEvent with\n ProcessGuid=%s\n Index=%d", format.Object(actual, 1), matcher.ProcessGuid, matcher.Index)
126123
}
127124

128125
//
129126

130-
func MatchActualLRPChangedEvent(processGuid string, index int, state string) gomega.OmegaMatcher {
131-
return &ActualLRPChangedEventMatcher{
127+
func MatchActualLRPInstanceChangedEvent(processGuid string, index int, state string) gomega.OmegaMatcher {
128+
return &ActualLRPInstanceChangedEventMatcher{
132129
ProcessGuid: processGuid,
133130
Index: index,
134131
State: state,
135132
}
136133
}
137134

138-
type ActualLRPChangedEventMatcher struct {
135+
type ActualLRPInstanceChangedEventMatcher struct {
139136
ProcessGuid string
140137
Index int
141138
State string
142139
}
143140

144-
func (matcher *ActualLRPChangedEventMatcher) Match(actual interface{}) (success bool, err error) {
145-
event, ok := actual.(*models.ActualLRPChangedEvent)
141+
func (matcher *ActualLRPInstanceChangedEventMatcher) Match(actual interface{}) (success bool, err error) {
142+
event, ok := actual.(*models.ActualLRPInstanceChangedEvent)
146143
if !ok {
147-
return false, fmt.Errorf("ActualLRPChangedEventMatcher matcher expects a models.ActualLRPChangedEvent. Got:\n%s", format.Object(actual, 1))
144+
return false, fmt.Errorf("ActualLRPInstanceChangedEventMatcher matcher expects a models.ActualLRPInstanceChangedEvent. Got:\n%s", format.Object(actual, 1))
148145
}
149146

150-
actualLRP, _, err := event.After.Resolve()
147+
actualLRP := event.ActualLRPKey
151148
if err != nil {
152149
return false, err
153150
}
154-
return actualLRP.ProcessGuid == matcher.ProcessGuid && actualLRP.Index == int32(matcher.Index) && actualLRP.State == matcher.State, nil
151+
return actualLRP.ProcessGuid == matcher.ProcessGuid && actualLRP.Index == int32(matcher.Index) && event.After.State == matcher.State, nil
155152
}
156153

157-
func (matcher *ActualLRPChangedEventMatcher) FailureMessage(actual interface{}) (message string) {
158-
return fmt.Sprintf("Expected\n%s\nto be a ActualLRPChangedEvent with\n ProcessGuid=%s\n Index=%d\n State=%s", format.Object(actual, 1), matcher.ProcessGuid, matcher.Index, matcher.State)
154+
func (matcher *ActualLRPInstanceChangedEventMatcher) FailureMessage(actual interface{}) (message string) {
155+
return fmt.Sprintf("Expected\n%s\nto be a ActualLRPInstanceChangedEvent with\n ProcessGuid=%s\n Index=%d\n State=%s", format.Object(actual, 1), matcher.ProcessGuid, matcher.Index, matcher.State)
159156
}
160157

161-
func (matcher *ActualLRPChangedEventMatcher) NegatedFailureMessage(actual interface{}) (message string) {
162-
return fmt.Sprintf("Expected\n%s\nnot to be a ActualLRPChangedEvent with\n ProcessGuid=%s\n Index=%d\n State=%s", format.Object(actual, 1), matcher.ProcessGuid, matcher.Index, matcher.State)
158+
func (matcher *ActualLRPInstanceChangedEventMatcher) NegatedFailureMessage(actual interface{}) (message string) {
159+
return fmt.Sprintf("Expected\n%s\nnot to be a ActualLRPInstanceChangedEvent with\n ProcessGuid=%s\n Index=%d\n State=%s", format.Object(actual, 1), matcher.ProcessGuid, matcher.Index, matcher.State)
163160
}
164161

165162
//
166163

167-
func MatchActualLRPRemovedEvent(processGuid string, index int) gomega.OmegaMatcher {
168-
return &ActualLRPRemovedEventMatcher{
164+
func MatchActualLRPInstanceRemovedEvent(processGuid string, index int) gomega.OmegaMatcher {
165+
return &ActualLRPInstanceRemovedEventMatcher{
169166
ProcessGuid: processGuid,
170167
Index: index,
171168
}
172169
}
173170

174-
type ActualLRPRemovedEventMatcher struct {
171+
type ActualLRPInstanceRemovedEventMatcher struct {
175172
ProcessGuid string
176173
Index int
177174
}
178175

179-
func (matcher *ActualLRPRemovedEventMatcher) Match(actual interface{}) (success bool, err error) {
180-
event, ok := actual.(*models.ActualLRPRemovedEvent)
176+
func (matcher *ActualLRPInstanceRemovedEventMatcher) Match(actual interface{}) (success bool, err error) {
177+
event, ok := actual.(*models.ActualLRPInstanceRemovedEvent)
181178
if !ok {
182-
return false, fmt.Errorf("ActualLRPRemovedEventMatcher matcher expects a models.ActualLRPRemovedEvent. Got:\n%s", format.Object(actual, 1))
183-
}
184-
actualLRP, _, err := event.ActualLrpGroup.Resolve()
185-
if err != nil {
186-
return false, err
179+
return false, fmt.Errorf("ActualLRPInstanceRemovedEventMatcher matcher expects a models.ActualLRPInstanceRemovedEvent. Got:\n%s", format.Object(actual, 1))
187180
}
181+
actualLRP := event.ActualLrp
188182
return actualLRP.ProcessGuid == matcher.ProcessGuid && actualLRP.Index == int32(matcher.Index), nil
189183
}
190184

191-
func (matcher *ActualLRPRemovedEventMatcher) FailureMessage(actual interface{}) (message string) {
192-
return fmt.Sprintf("Expected\n%s\nto be a ActualLRPRemovedEvent with\n ProcessGuid=%s\n Index=%d", format.Object(actual, 1), matcher.ProcessGuid, matcher.Index)
185+
func (matcher *ActualLRPInstanceRemovedEventMatcher) FailureMessage(actual interface{}) (message string) {
186+
return fmt.Sprintf("Expected\n%s\nto be a ActualLRPInstanceRemovedEvent with\n ProcessGuid=%s\n Index=%d", format.Object(actual, 1), matcher.ProcessGuid, matcher.Index)
193187
}
194188

195-
func (matcher *ActualLRPRemovedEventMatcher) NegatedFailureMessage(actual interface{}) (message string) {
196-
return fmt.Sprintf("Expected\n%s\nnot to be a ActualLRPRemovedEvent with\n ProcessGuid=%s\n Index=%d", format.Object(actual, 1), matcher.ProcessGuid, matcher.Index)
189+
func (matcher *ActualLRPInstanceRemovedEventMatcher) NegatedFailureMessage(actual interface{}) (message string) {
190+
return fmt.Sprintf("Expected\n%s\nnot to be a ActualLRPInstanceRemovedEvent with\n ProcessGuid=%s\n Index=%d", format.Object(actual, 1), matcher.ProcessGuid, matcher.Index)
197191
}

0 commit comments

Comments
 (0)