Skip to content

Commit c5a4b8e

Browse files
committed
feat: Publish key change event after key deletion (#5200)
Signed-off-by: FelixTing <[email protected]>
1 parent 684c0cd commit c5a4b8e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

internal/core/keeper/controller/http/kv.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"github.com/edgexfoundry/go-mod-bootstrap/v4/di"
2020
"github.com/edgexfoundry/go-mod-core-contracts/v4/dtos/requests"
2121
"github.com/edgexfoundry/go-mod-core-contracts/v4/dtos/responses"
22+
"github.com/edgexfoundry/go-mod-core-contracts/v4/models"
23+
2224
"github.com/labstack/echo/v4"
2325
)
2426

@@ -127,6 +129,9 @@ func (rc *KVController) DeleteKeys(c echo.Context) error {
127129
return utils.WriteErrorResponse(w, ctx, lc, err, "")
128130
}
129131

132+
// publish the key change event
133+
go application.PublishKeyChange(models.KVS{Key: key}, key, ctx, rc.dic)
134+
130135
response := responses.NewKeysResponse("", "", http.StatusOK, resp)
131136
utils.WriteHttpHeader(w, ctx, http.StatusOK)
132137
return pkg.EncodeAndWriteResponse(response, w, lc)

internal/core/keeper/controller/http/kv_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (C) 2024 IOTech Ltd
2+
// Copyright (C) 2024-2025 IOTech Ltd
33
//
44
// SPDX-License-Identifier: Apache-2.0
55

@@ -350,6 +350,8 @@ func TestDeleteKeys(t *testing.T) {
350350
prefixExistsKey := "prefix-key"
351351
keyResp := []models.KeyOnly{models.KeyOnly(key)}
352352

353+
msgClientMock := &messageClientMocks.MessageClient{}
354+
msgClientMock.On("Publish", mock.Anything, mock.Anything).Return(nil)
353355
dic := mockDic()
354356
dbClientMock := &mocks.DBClient{}
355357
dbClientMock.On("DeleteKeeperKeys", key, true).Return(keyResp, nil)
@@ -361,6 +363,9 @@ func TestDeleteKeys(t *testing.T) {
361363
container.DBClientInterfaceName: func(get di.Get) interface{} {
362364
return dbClientMock
363365
},
366+
bootstrapContainer.MessagingClientName: func(get di.Get) interface{} {
367+
return msgClientMock
368+
},
364369
})
365370

366371
controller := NewKVController(dic)

0 commit comments

Comments
 (0)