Skip to content

Commit

Permalink
Merge pull request #1169 from kaleido-io/coverage
Browse files Browse the repository at this point in the history
Fix coverage gap in webhooks test
  • Loading branch information
peterbroadhurst authored Feb 2, 2023
2 parents c42ad70 + 62bbbef commit efa9552
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions internal/events/webhooks/webhooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,71 @@ func TestRequestReplyEmptyData(t *testing.T) {
mcb.AssertExpectations(t)
}

func TestRequestReplyOneData(t *testing.T) {
wh, cancel := newTestWebHooks(t)
defer cancel()

msgID := fftypes.NewUUID()
dataID := fftypes.NewUUID()

r := mux.NewRouter()
r.HandleFunc("/myapi", func(res http.ResponseWriter, req *http.Request) {
var body fftypes.JSONObject
err := json.NewDecoder(req.Body).Decode(&body)
assert.NoError(t, err)
res.WriteHeader(200)
}).Methods(http.MethodPost)
server := httptest.NewServer(r)
defer server.Close()

yes := true
sub := &core.Subscription{
SubscriptionRef: core.SubscriptionRef{
Namespace: "ns1",
},
Options: core.SubscriptionOptions{
SubscriptionCoreOptions: core.SubscriptionCoreOptions{
WithData: &yes,
},
},
}
to := sub.Options.TransportOptions()
to["url"] = fmt.Sprintf("http://%s/myapi", server.Listener.Addr())
to["reply"] = true
event := &core.EventDelivery{
EnrichedEvent: core.EnrichedEvent{
Event: core.Event{
ID: fftypes.NewUUID(),
},
Message: &core.Message{
Header: core.MessageHeader{
ID: msgID,
Type: core.MessageTypeBroadcast,
},
Data: core.DataRefs{
{ID: dataID},
},
},
},
Subscription: core.SubscriptionRef{
ID: sub.ID,
},
}

mcb := wh.callbacks["ns1"].(*eventsmocks.Callbacks)
mcb.On("DeliveryResponse", mock.Anything, mock.MatchedBy(func(response *core.EventDeliveryResponse) bool {
assert.Equal(t, *msgID, *response.Reply.Message.Header.CID)
assert.Nil(t, response.Reply.Message.Header.Group)
assert.Equal(t, core.MessageTypeBroadcast, response.Reply.Message.Header.Type)
return true
})).Return(nil)

err := wh.DeliveryRequest(mock.Anything, sub, event, core.DataArray{{ID: dataID, Value: fftypes.JSONAnyPtr("foo")}})
assert.NoError(t, err)

mcb.AssertExpectations(t)
}

func TestRequestReplyBadJSON(t *testing.T) {
wh, cancel := newTestWebHooks(t)
defer cancel()
Expand Down

0 comments on commit efa9552

Please sign in to comment.