(t *testing.T)
| 210 | } |
| 211 | |
| 212 | func TestCustomHandler(t *testing.T) { |
| 213 | ctx := base.TestCtx(t) |
| 214 | terminator := make(chan bool) |
| 215 | defer close(terminator) |
| 216 | |
| 217 | em := NewEventManager(terminator) |
| 218 | em.Start(ctx, 0, -1) |
| 219 | |
| 220 | ids := make([]string, 20) |
| 221 | for i := 0; i < 20; i++ { |
| 222 | ids[i] = fmt.Sprintf("%d", i) |
| 223 | } |
| 224 | |
| 225 | eventForTest := func(i int) (Body, string, base.Set) { |
| 226 | testBody := Body{ |
| 227 | BodyId: ids[i], |
| 228 | "value": i, |
| 229 | } |
| 230 | var channelSet base.Set |
| 231 | if i%2 == 0 { |
| 232 | channelSet = base.SetFromArray([]string{"Even"}) |
| 233 | } else { |
| 234 | channelSet = base.SetFromArray([]string{"Odd"}) |
| 235 | } |
| 236 | return testBody, ids[i], channelSet |
| 237 | } |
| 238 | |
| 239 | resultChannel := make(chan interface{}, 20) |
| 240 | |
| 241 | testHandler := &TestingHandler{HandledEvent: DocumentChange} |
| 242 | testHandler.SetChannel(resultChannel) |
| 243 | em.RegisterEventHandler(ctx, testHandler, DocumentChange) |
| 244 | |
| 245 | for i := 0; i < 10; i++ { |
| 246 | body, docid, channels := eventForTest(i) |
| 247 | bodyBytes := base.MustJSONMarshal(t, body) |
| 248 | err := em.RaiseDocumentChangeEvent(ctx, bodyBytes, docid, "", channels, false) |
| 249 | assert.NoError(t, err) |
| 250 | } |
| 251 | |
| 252 | assertChannelLengthWithTimeout(t, resultChannel, 10, 10*time.Second) |
| 253 | |
| 254 | } |
| 255 | |
| 256 | func TestUnhandledEvent(t *testing.T) { |
| 257 | ctx := base.TestCtx(t) |
nothing calls this directly
no test coverage detected