Skip to content

Commit

Permalink
fix: Use WrapHandler func from go-mod-bootstrap
Browse files Browse the repository at this point in the history
- Use WrapHandler func from go-mod-bootstrap
- Update comments and use new echo API routes in command_test.go

Signed-off-by: Lindsey Cheng <beckysocute@gmail.com>
  • Loading branch information
lindseysimple committed Aug 3, 2023
1 parent 93fdda3 commit ca6e439
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 66 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/OneOfOne/xxhash v1.2.8
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.1.0-dev.14
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.1.0-dev.16
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.1.0-dev.3
github.com/edgexfoundry/go-mod-messaging/v3 v3.1.0-dev.12
github.com/google/uuid v1.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/eclipse/paho.mqtt.golang v1.4.3 h1:2kwcUGn8seMUfWndX0hGbvH8r7crgcJguQNCyp70xik=
github.com/eclipse/paho.mqtt.golang v1.4.3/go.mod h1:CSYvoAlsMkhYOXh/oKyxa8EcBci6dVkLCbo5tTC1RIE=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.1.0-dev.14 h1:yDDt0qwMDjhEDbV7rEX1AVVDu8QdSG8zt3/DLaXHk4A=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.1.0-dev.14/go.mod h1:Qe0cE8xdcddeTKVhKt079SnA6obquNSiIFLfAfBKdDE=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.1.0-dev.16 h1:j3/SRjDhwTx127Csdh8CNLNV8IvTi6gxCjv83emQukc=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.1.0-dev.16/go.mod h1:3d3IF3Z0gaVHYLHvOAvJWDuynG2XFMkTYbjKytoM7ig=
github.com/edgexfoundry/go-mod-configuration/v3 v3.1.0-dev.4 h1:RmZVvR9sa3CdRNIiBNtuYG1gkP3Y98jOf69kL2SabGI=
github.com/edgexfoundry/go-mod-configuration/v3 v3.1.0-dev.4/go.mod h1:hVlzVoVpbgOZKppX+vwYsp7Kf0eBfRmBZP2FsyMwe9I=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.1.0-dev.3 h1:NJa87GfnUZw/GvX2aeeZ4ZQoSzwkRotuLQej2ay6XUc=
Expand Down
10 changes: 5 additions & 5 deletions internal/controller/http/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func TestRestController_GetCommand(t *testing.T) {
}
for _, testCase := range tests {
t.Run(testCase.name, func(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, common.ApiDeviceNameCommandNameRoute, http.NoBody)
req := httptest.NewRequest(http.MethodGet, common.ApiDeviceNameCommandNameEchoRoute, http.NoBody)

// Act
recorder := httptest.NewRecorder()
Expand Down Expand Up @@ -282,7 +282,7 @@ func TestRestController_GetCommand_ServiceLocked(t *testing.T) {
controller := NewRestController(e, dic, testService)
assert.NotNil(t, controller)

req := httptest.NewRequest(http.MethodGet, common.ApiDeviceNameCommandNameRoute, http.NoBody)
req := httptest.NewRequest(http.MethodGet, common.ApiDeviceNameCommandNameEchoRoute, http.NoBody)

// Act
recorder := httptest.NewRecorder()
Expand Down Expand Up @@ -313,7 +313,7 @@ func TestRestController_GetCommand_ReturnEvent(t *testing.T) {
controller := NewRestController(e, dic, testService)
assert.NotNil(t, controller)

req := httptest.NewRequest(http.MethodGet, common.ApiDeviceNameCommandNameRoute, http.NoBody)
req := httptest.NewRequest(http.MethodGet, common.ApiDeviceNameCommandNameEchoRoute, http.NoBody)

query := req.URL.Query()
query.Add("ds-returnevent", common.ValueFalse)
Expand Down Expand Up @@ -377,7 +377,7 @@ func TestRestController_SetCommand(t *testing.T) {
require.NoError(t, err)

reader := strings.NewReader(string(jsonData))
req := httptest.NewRequest(http.MethodPut, common.ApiDeviceNameCommandNameRoute, reader)
req := httptest.NewRequest(http.MethodPut, common.ApiDeviceNameCommandNameEchoRoute, reader)

var wg sync.WaitGroup
if testCase.commandName != writeOnlyCommand && testCase.commandName != writeOnlyResource {
Expand Down Expand Up @@ -448,7 +448,7 @@ func TestRestController_SetCommand_ServiceLocked(t *testing.T) {
require.NoError(t, err)

reader := strings.NewReader(string(jsonData))
req := httptest.NewRequest(http.MethodPut, common.ApiDeviceNameCommandNameRoute, reader)
req := httptest.NewRequest(http.MethodPut, common.ApiDeviceNameCommandNameEchoRoute, reader)

// Act
recorder := httptest.NewRecorder()
Expand Down
8 changes: 4 additions & 4 deletions internal/controller/http/restrouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ func (c *RestController) sendResponse(
data, err := json.Marshal(response)
if err != nil {
c.lc.Error(fmt.Sprintf("Unable to marshal %s response", api), "error", err.Error(), common.CorrelationHeader, correlationID)
// set Response.Committed to true in order to rewrite the status code
// set Response.Committed to false in order to rewrite the status code
writer.Committed = false
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}

_, err = writer.Write(data)
if err != nil {
c.lc.Error(fmt.Sprintf("Unable to write %s response", api), "error", err.Error(), common.CorrelationHeader, correlationID)
// set Response.Committed to true in order to rewrite the status code
// set Response.Committed to false in order to rewrite the status code
writer.Committed = false
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
Expand All @@ -131,7 +131,7 @@ func (c *RestController) sendEventResponse(
data, encoding, err := response.Encode()
if err != nil {
c.lc.Errorf("Unable to marshal EventResponse: %s; %s: %s", err.Error(), common.CorrelationHeader, correlationID)
// set Response.Committed to true in order to rewrite the status code
// set Response.Committed to false in order to rewrite the status code
writer.Committed = false
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
Expand All @@ -143,7 +143,7 @@ func (c *RestController) sendEventResponse(
_, err = writer.Write(data)
if err != nil {
c.lc.Errorf("Unable to write DeviceCommand response: %s; %s: %s", err.Error(), common.CorrelationHeader, correlationID)
// set Response.Committed to true in order to rewrite the status code
// set Response.Committed to false in order to rewrite the status code
writer.Committed = false
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/edgexfoundry/go-mod-bootstrap/v3/bootstrap/controller"
"github.com/edgexfoundry/go-mod-bootstrap/v3/bootstrap/handlers"
"github.com/edgexfoundry/go-mod-bootstrap/v3/bootstrap/startup"
"github.com/edgexfoundry/go-mod-bootstrap/v3/bootstrap/utils"

"github.com/edgexfoundry/device-sdk-go/v3/internal/autodiscovery"
"github.com/edgexfoundry/device-sdk-go/v3/internal/autoevent"
Expand All @@ -33,7 +34,6 @@ import (
restController "github.com/edgexfoundry/device-sdk-go/v3/internal/controller/http"
"github.com/edgexfoundry/device-sdk-go/v3/pkg/interfaces"
sdkModels "github.com/edgexfoundry/device-sdk-go/v3/pkg/models"
"github.com/edgexfoundry/device-sdk-go/v3/pkg/utils"

bootstrapConfig "github.com/edgexfoundry/go-mod-bootstrap/v3/bootstrap/config"
bootstrapContainer "github.com/edgexfoundry/go-mod-bootstrap/v3/bootstrap/container"
Expand Down
20 changes: 0 additions & 20 deletions pkg/utils/handler.go

This file was deleted.

33 changes: 0 additions & 33 deletions pkg/utils/handler_test.go

This file was deleted.

0 comments on commit ca6e439

Please sign in to comment.