Skip to content

Commit

Permalink
shadow: fix error message type (#130)
Browse files Browse the repository at this point in the history
Error code is int on Thing Shadow.
(It's string on Jobs.)
  • Loading branch information
at-wat authored Jul 22, 2020
1 parent 3a70d4d commit 20efa85
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
16 changes: 8 additions & 8 deletions shadow/shadow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,12 @@ func TestGet(t *testing.T) {
},
"Error": {
response: &ErrorResponse{
Code: "Failed",
Code: 400,
Message: "Reason",
},
responseTopic: "get/rejected",
err: &ErrorResponse{
Code: "Failed",
Code: 400,
Message: "Reason",
},
},
Expand Down Expand Up @@ -460,12 +460,12 @@ func TestDesire(t *testing.T) {
"Error": {
input: map[string]interface{}{"key": "value"},
response: &ErrorResponse{
Code: "Failed",
Code: 400,
Message: "Reason",
},
responseTopic: "update/rejected",
err: &ErrorResponse{
Code: "Failed",
Code: 400,
Message: "Reason",
},
},
Expand Down Expand Up @@ -554,12 +554,12 @@ func TestReport(t *testing.T) {
"Error": {
input: map[string]interface{}{"key": "value"},
response: &ErrorResponse{
Code: "Failed",
Code: 400,
Message: "Reason",
},
responseTopic: "update/rejected",
err: &ErrorResponse{
Code: "Failed",
Code: 400,
Message: "Reason",
},
},
Expand Down Expand Up @@ -631,12 +631,12 @@ func TestDelete(t *testing.T) {
},
"Error": {
response: &ErrorResponse{
Code: "Failed",
Code: 400,
Message: "Reason",
},
responseTopic: "delete/rejected",
err: &ErrorResponse{
Code: "Failed",
Code: 400,
Message: "Reason",
},
},
Expand Down
4 changes: 2 additions & 2 deletions shadow/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ type simpleRequest struct {

// ErrorResponse represents error response from AWS IoT.
type ErrorResponse struct {
Code string `json:"code"`
Code int `json:"code"`
Message string `json:"message"`
Timestamp int64 `json:"timestamp"`
ClientToken string `json:"clientToken"`
}

// Error implements error interface.
func (e *ErrorResponse) Error() string {
return fmt.Sprintf("%s (%s): %s", e.Code, e.ClientToken, e.Message)
return fmt.Sprintf("%d (%s): %s", e.Code, e.ClientToken, e.Message)
}

// ThingState represents Thing Shadow State.
Expand Down
15 changes: 15 additions & 0 deletions shadow/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package shadow
import (
"encoding/json"
"reflect"
"strings"
"testing"
)

Expand Down Expand Up @@ -73,3 +74,17 @@ func TestThingDocument_update(t *testing.T) {
)
}
}

func TestErrorResponse(t *testing.T) {
err := &ErrorResponse{
Code: 100,
Message: "error message",
}
errStr := err.Error()
if !strings.Contains(errStr, "100") {
t.Error("Error string should contain error code")
}
if !strings.Contains(errStr, "error message") {
t.Error("Error string should contain error message")
}
}

0 comments on commit 20efa85

Please sign in to comment.