From 2e5fccdd58e246454ef50e8207172d93e900d5e9 Mon Sep 17 00:00:00 2001 From: Ginny Guan Date: Thu, 12 Jan 2023 09:07:42 +0000 Subject: [PATCH] refactor!: Use bool types for command parameters in IssueGetCommandByName BREAKING CHANGE: ds-pushevent and ds-returnevent to use bool true/false instead of yes/no related: https://github.com/edgexfoundry/go-mod-core-contracts/pull/782 Signed-off-by: Ginny Guan --- clients/command.go | 6 +++--- clients/command_test.go | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/clients/command.go b/clients/command.go index ff584414..14a083ac 100644 --- a/clients/command.go +++ b/clients/command.go @@ -168,12 +168,12 @@ func (c *CommandClient) DeviceCoreCommandsByDeviceName(ctx context.Context, devi } } -func (c *CommandClient) IssueGetCommandByName(ctx context.Context, deviceName string, commandName string, dsPushEvent string, dsReturnEvent string) (*responses.EventResponse, edgexErr.EdgeX) { +func (c *CommandClient) IssueGetCommandByName(ctx context.Context, deviceName string, commandName string, dsPushEvent bool, dsReturnEvent bool) (*responses.EventResponse, edgexErr.EdgeX) { if c.commandMessages == nil { return nil, edgexErr.NewCommonEdgeX(edgexErr.KindServerError, "command request/response topics not provided", nil) } - queryParams := map[string]string{common.PushEvent: dsPushEvent, common.ReturnEvent: dsReturnEvent} + queryParams := map[string]string{common.PushEvent: strconv.FormatBool(dsPushEvent), common.ReturnEvent: strconv.FormatBool(dsReturnEvent)} return c.IssueGetCommandByNameWithQueryParams(ctx, deviceName, commandName, queryParams) } @@ -207,7 +207,7 @@ func (c *CommandClient) IssueGetCommandByNameWithQueryParams(ctx context.Context var res responses.EventResponse returnEvent, ok := queryParams[common.ReturnEvent] - if ok && returnEvent == common.ValueNo { + if ok && returnEvent == common.ValueFalse { res.ApiVersion = common.ApiVersion res.RequestId = responseEnvelope.RequestID res.StatusCode = http.StatusOK diff --git a/clients/command_test.go b/clients/command_test.go index 248d6f05..4170c5ff 100644 --- a/clients/command_test.go +++ b/clients/command_test.go @@ -9,6 +9,7 @@ import ( "context" "encoding/json" "net/http" + "strconv" "sync" "testing" "time" @@ -151,7 +152,11 @@ func TestCommandClient_IssueGetCommandByName(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - res, err := client.IssueGetCommandByName(context.Background(), testDeviceName, testCommandName, "no", "tes") + notPushEvent, err := strconv.ParseBool(common.ValueFalse) + require.NoError(t, err) + returnEvent, err := strconv.ParseBool(common.ValueTrue) + require.NoError(t, err) + res, err := client.IssueGetCommandByName(context.Background(), testDeviceName, testCommandName, notPushEvent, returnEvent) require.NoError(t, err) require.IsType(t, res, &responses.EventResponse{})