Skip to content

Commit

Permalink
refactor!: Use bool types for command parameters in IssueGetCommandBy…
Browse files Browse the repository at this point in the history
…Name

BREAKING CHANGE: ds-pushevent and ds-returnevent to use bool true/false instead of yes/no

related: edgexfoundry/go-mod-core-contracts#782

Signed-off-by: Ginny Guan <[email protected]>
  • Loading branch information
jinlinGuan committed Jan 12, 2023
1 parent bc4b4ae commit 2e5fccd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions clients/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion clients/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"context"
"encoding/json"
"net/http"
"strconv"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -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{})
Expand Down

0 comments on commit 2e5fccd

Please sign in to comment.