(t *testing.T)
| 81 | } |
| 82 | |
| 83 | func TestDocumentChangeEvent(t *testing.T) { |
| 84 | ctx := base.TestCtx(t) |
| 85 | terminator := make(chan bool) |
| 86 | defer close(terminator) |
| 87 | |
| 88 | em := NewEventManager(terminator) |
| 89 | em.Start(ctx, 0, -1) |
| 90 | |
| 91 | // Setup test data |
| 92 | ids := make([]string, 20) |
| 93 | for i := 0; i < 20; i++ { |
| 94 | ids[i] = fmt.Sprintf("%d", i) |
| 95 | } |
| 96 | eventForTest := func(i int) (Body, string, base.Set) { |
| 97 | testBody := Body{ |
| 98 | BodyId: ids[i], |
| 99 | "value": i, |
| 100 | } |
| 101 | var channelSet base.Set |
| 102 | if i%2 == 0 { |
| 103 | channelSet = base.SetFromArray([]string{"Even"}) |
| 104 | } else { |
| 105 | channelSet = base.SetFromArray([]string{"Odd"}) |
| 106 | } |
| 107 | return testBody, ids[i], channelSet |
| 108 | } |
| 109 | resultChannel := make(chan interface{}, 10) |
| 110 | // Setup test handler |
| 111 | testHandler := &TestingHandler{HandledEvent: DocumentChange} |
| 112 | testHandler.SetChannel(resultChannel) |
| 113 | em.RegisterEventHandler(ctx, testHandler, DocumentChange) |
| 114 | // Raise events |
| 115 | for i := 0; i < 10; i++ { |
| 116 | body, docid, channels := eventForTest(i) |
| 117 | bodyBytes := base.MustJSONMarshal(t, body) |
| 118 | err := em.RaiseDocumentChangeEvent(ctx, bodyBytes, docid, "", channels, false) |
| 119 | assert.NoError(t, err) |
| 120 | } |
| 121 | |
| 122 | assertChannelLengthWithTimeout(t, resultChannel, 10, 10*time.Second) |
| 123 | |
| 124 | } |
| 125 | |
| 126 | func TestDBStateChangeEvent(t *testing.T) { |
| 127 | ctx := base.TestCtx(t) |
nothing calls this directly
no test coverage detected