Skip to content

Commit

Permalink
feat(EventClient): add DeleteById to interface
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Titus <[email protected]>
  • Loading branch information
jrtitus committed Dec 2, 2023
1 parent 27f1934 commit 49f8627
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
10 changes: 10 additions & 0 deletions clients/http/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,13 @@ func (ec *eventClient) DeleteByAge(ctx context.Context, age int) (dtoCommon.Base
}
return res, nil
}

func (ec *eventClient) DeleteById(ctx context.Context, id string) (dtoCommon.BaseResponse, errors.EdgeX) {
path := path.Join(common.ApiEventRoute, common.Id, id)
res := dtoCommon.BaseResponse{}
err := utils.DeleteRequest(ctx, &res, ec.baseUrl, path, ec.authInjector)
if err != nil {
return res, errors.NewCommonEdgeXWrapper(err)
}
return res, nil
}
12 changes: 12 additions & 0 deletions clients/http/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,15 @@ func TestDeleteEventsByAge(t *testing.T) {
require.NoError(t, err)
assert.IsType(t, dtoCommon.BaseResponse{}, res)
}

func TestDeleteEventById(t *testing.T) {
id := "1234-5678-90fa-keid"
path := path.Join(common.ApiEventRoute, common.Id, id)
ts := newTestServer(http.MethodDelete, path, dtoCommon.BaseResponse{})
defer ts.Close()

client := NewEventClient(ts.URL, NewNullAuthenticationInjector(), false)
res, err := client.DeleteById(context.Background(), id)
require.NoError(t, err)
assert.IsType(t, dtoCommon.BaseResponse{}, res)
}
2 changes: 2 additions & 0 deletions clients/interfaces/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ type EventClient interface {
EventsByTimeRange(ctx context.Context, start, end, offset, limit int) (responses.MultiEventsResponse, errors.EdgeX)
// DeleteByAge deletes events that are older than the given age. Age is supposed in milliseconds from created timestamp.
DeleteByAge(ctx context.Context, age int) (common.BaseResponse, errors.EdgeX)
// DeleteById deletes an event by its id
DeleteById(ctx context.Context, id string) (common.BaseResponse, errors.EdgeX)
}
26 changes: 26 additions & 0 deletions clients/interfaces/mocks/EventClient.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 49f8627

Please sign in to comment.