-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbdd_event_handling_test.go
More file actions
185 lines (145 loc) · 5.1 KB
/
bdd_event_handling_test.go
File metadata and controls
185 lines (145 loc) · 5.1 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package jsonschema
import (
"fmt"
"time"
"github.com/GoCodeAlone/modular"
)
// CloudEvents emission and handling step methods
func (ctx *JSONSchemaBDDTestContext) aSchemaCompiledEventShouldBeEmitted() error {
time.Sleep(100 * time.Millisecond) // Give time for async event emission
events := ctx.eventObserver.GetEvents()
for _, event := range events {
if event.Type() == EventTypeSchemaCompiled {
return nil
}
}
eventTypes := make([]string, len(events))
for i, event := range events {
eventTypes[i] = event.Type()
}
return fmt.Errorf("schema compiled event not found. Captured events: %v", eventTypes)
}
func (ctx *JSONSchemaBDDTestContext) theEventShouldContainTheSourceInformation() error {
time.Sleep(100 * time.Millisecond) // Give time for async event emission
events := ctx.eventObserver.GetEvents()
for _, event := range events {
if event.Type() == EventTypeSchemaCompiled {
var eventData map[string]interface{}
if err := event.DataAs(&eventData); err != nil {
continue
}
if source, ok := eventData["source"]; ok && source != "" {
return nil
}
}
}
return fmt.Errorf("schema compiled event with source information not found")
}
func (ctx *JSONSchemaBDDTestContext) aSchemaErrorEventShouldBeEmitted() error {
time.Sleep(100 * time.Millisecond) // Give time for async event emission
events := ctx.eventObserver.GetEvents()
for _, event := range events {
if event.Type() == EventTypeSchemaError {
return nil
}
}
eventTypes := make([]string, len(events))
for i, event := range events {
eventTypes[i] = event.Type()
}
return fmt.Errorf("schema error event not found. Captured events: %v", eventTypes)
}
func (ctx *JSONSchemaBDDTestContext) aValidateBytesEventShouldBeEmitted() error {
time.Sleep(100 * time.Millisecond) // Give time for async event emission
events := ctx.eventObserver.GetEvents()
for _, event := range events {
if event.Type() == EventTypeValidateBytes {
return nil
}
}
eventTypes := make([]string, len(events))
for i, event := range events {
eventTypes[i] = event.Type()
}
return fmt.Errorf("validate bytes event not found. Captured events: %v", eventTypes)
}
func (ctx *JSONSchemaBDDTestContext) aValidationSuccessEventShouldBeEmitted() error {
time.Sleep(100 * time.Millisecond) // Give time for async event emission
events := ctx.eventObserver.GetEvents()
for _, event := range events {
if event.Type() == EventTypeValidationSuccess {
return nil
}
}
eventTypes := make([]string, len(events))
for i, event := range events {
eventTypes[i] = event.Type()
}
return fmt.Errorf("validation success event not found. Captured events: %v", eventTypes)
}
func (ctx *JSONSchemaBDDTestContext) aValidationFailedEventShouldBeEmitted() error {
time.Sleep(100 * time.Millisecond) // Give time for async event emission
events := ctx.eventObserver.GetEvents()
for _, event := range events {
if event.Type() == EventTypeValidationFailed {
return nil
}
}
eventTypes := make([]string, len(events))
for i, event := range events {
eventTypes[i] = event.Type()
}
return fmt.Errorf("validation failed event not found. Captured events: %v", eventTypes)
}
func (ctx *JSONSchemaBDDTestContext) aValidateReaderEventShouldBeEmitted() error {
time.Sleep(100 * time.Millisecond) // Give time for async event emission
events := ctx.eventObserver.GetEvents()
for _, event := range events {
if event.Type() == EventTypeValidateReader {
return nil
}
}
eventTypes := make([]string, len(events))
for i, event := range events {
eventTypes[i] = event.Type()
}
return fmt.Errorf("validate reader event not found. Captured events: %v", eventTypes)
}
func (ctx *JSONSchemaBDDTestContext) aValidateInterfaceEventShouldBeEmitted() error {
time.Sleep(100 * time.Millisecond) // Give time for async event emission
events := ctx.eventObserver.GetEvents()
for _, event := range events {
if event.Type() == EventTypeValidateInterface {
return nil
}
}
eventTypes := make([]string, len(events))
for i, event := range events {
eventTypes[i] = event.Type()
}
return fmt.Errorf("validate interface event not found. Captured events: %v", eventTypes)
}
// Event validation step - ensures all registered events are emitted during testing
func (ctx *JSONSchemaBDDTestContext) allRegisteredEventsShouldBeEmittedDuringTesting() error {
// Get all registered event types from the module
registeredEvents := ctx.module.GetRegisteredEventTypes()
// Create event validation observer
validator := modular.NewEventValidationObserver("event-validator", registeredEvents)
_ = validator // Use validator to avoid unused variable error
// Check which events were emitted during testing
emittedEvents := make(map[string]bool)
for _, event := range ctx.eventObserver.GetEvents() {
emittedEvents[event.Type()] = true
}
// Check for missing events
var missingEvents []string
for _, eventType := range registeredEvents {
if !emittedEvents[eventType] {
missingEvents = append(missingEvents, eventType)
}
}
if len(missingEvents) > 0 {
return fmt.Errorf("the following registered events were not emitted during testing: %v", missingEvents)
}
return nil
}