Skip to content

Commit

Permalink
return 520 if parameters are not found
Browse files Browse the repository at this point in the history
  • Loading branch information
piccione99 committed Apr 10, 2024
1 parent 8d8e91f commit 11d5980
Showing 4 changed files with 54,764 additions and 28,341 deletions.
7 changes: 6 additions & 1 deletion internal/wrphandlers/mocktr181/handler.go
Original file line number Diff line number Diff line change
@@ -154,6 +154,7 @@ func (h Handler) HandleWrp(msg wrp.Message) error {

func (h Handler) get(names []string) (int64, []byte, error) {
result := Tr181Payload{}
statusCode := int64(http.StatusOK)

for _, name := range names {
for _, mockParameter := range h.parameters {
@@ -173,7 +174,11 @@ func (h Handler) get(names []string) (int64, []byte, error) {
return http.StatusInternalServerError, payload, errors.Join(ErrInvalidResponsePayload, err)
}

return http.StatusOK, payload, nil
if len(result.Parameters) == 0 {
statusCode = int64(520)
}

return statusCode, payload, nil
}

func (h Handler) set(parameters []Parameter) int64 {
19 changes: 19 additions & 0 deletions internal/wrphandlers/mocktr181/handler_test.go
Original file line number Diff line number Diff line change
@@ -44,6 +44,25 @@ func TestHandler_HandleWrp(t *testing.T) {
a.True(h.Enabled())
return nil
},
}, {
description: "get with no mataching parameter",
egressCallCount: 1,
expectedErr: nil,
msg: wrp.Message{
Type: wrp.SimpleEventMessageType,
Source: "dns:tr1d1um.example.com/service/ignored",
Destination: "event:event_1/ignored",
Payload: []byte("{\"command\":\"GET\",\"names\":[\"NoSuchParameter\"]}"),
},
validate: func(a *assert.Assertions, msg wrp.Message, h *Handler) error {
a.Equal(int64(520), *msg.Status)
var result Tr181Payload
err := json.Unmarshal(msg.Payload, &result)
a.NoError(err)
a.Equal(0, len(result.Parameters))
a.True(h.Enabled())
return nil
},
}, {
description: "set, success",
egressCallCount: 1,
Loading

0 comments on commit 11d5980

Please sign in to comment.