(t *testing.T)
| 888 | } |
| 889 | |
| 890 | func TestUnavailableWebhook(t *testing.T) { |
| 891 | ts, wr := InitWebhookTest() |
| 892 | defer ts.Close() |
| 893 | |
| 894 | terminator := make(chan bool) |
| 895 | defer close(terminator) |
| 896 | |
| 897 | ids := make([]string, 20) |
| 898 | for i := 0; i < 20; i++ { |
| 899 | ids[i] = fmt.Sprintf("%d", i) |
| 900 | } |
| 901 | |
| 902 | eventForTest := func(k string, v int) (Body, string, base.Set) { |
| 903 | testBody := Body{ |
| 904 | BodyId: ids[v], |
| 905 | "value": k, |
| 906 | } |
| 907 | var channelSet base.Set |
| 908 | if v%2 == 0 { |
| 909 | channelSet = base.SetFromArray([]string{"Even"}) |
| 910 | } else { |
| 911 | channelSet = base.SetFromArray([]string{"Odd"}) |
| 912 | } |
| 913 | return testBody, ids[v], channelSet |
| 914 | } |
| 915 | |
| 916 | // Test unreachable webhook |
| 917 | |
| 918 | em := NewEventManager(terminator) |
| 919 | ctx := base.TestCtx(t) |
| 920 | em.Start(ctx, 0, -1) |
| 921 | webhookHandler, _ := NewWebhook(ctx, "http://badhost:1000/echo", "", nil, nil) |
| 922 | em.RegisterEventHandler(ctx, webhookHandler, DocumentChange) |
| 923 | for i := 0; i < 10; i++ { |
| 924 | body, docId, channels := eventForTest(strconv.Itoa(-i), i) |
| 925 | bodyBytes := base.MustJSONMarshal(t, body) |
| 926 | err := em.RaiseDocumentChangeEvent(ctx, bodyBytes, docId, "", channels, false) |
| 927 | assert.NoError(t, err) |
| 928 | } |
| 929 | time.Sleep(50 * time.Millisecond) |
| 930 | assert.Equal(t, 0, wr.GetCount()) |
| 931 | |
| 932 | } |
| 933 | |
| 934 | // asserts that the number of items seen in the channel within the specified time limit is the same as the expected value. |
| 935 | // WARNING: This function will drain the channel of items! |
nothing calls this directly
no test coverage detected