Skip to content

Commit

Permalink
feat: update channels tests
Browse files Browse the repository at this point in the history
Signed-off-by: 1998-felix <felix.gateru@gmail.com>
  • Loading branch information
felixgateru committed Jun 7, 2024
1 parent 5281774 commit 355fea3
Show file tree
Hide file tree
Showing 3 changed files with 2,230 additions and 667 deletions.
10 changes: 10 additions & 0 deletions pkg/sdk/go/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"time"

"github.com/absmach/magistrala/internal/apiutil"
"github.com/absmach/magistrala/pkg/errors"
)

Expand Down Expand Up @@ -90,6 +91,9 @@ func (sdk mgSDK) ChannelsByThing(thingID string, pm PageMetadata, token string)
}

func (sdk mgSDK) Channel(id, token string) (Channel, errors.SDKError) {
if id == "" {
return Channel{}, errors.NewSDKError(apiutil.ErrMissingID)
}
url := fmt.Sprintf("%s/%s/%s", sdk.thingsURL, channelsEndpoint, id)

_, body, err := sdk.processRequest(http.MethodGet, url, token, nil, nil, http.StatusOK)
Expand Down Expand Up @@ -127,6 +131,9 @@ func (sdk mgSDK) UpdateChannel(c Channel, token string) (Channel, errors.SDKErro
return Channel{}, errors.NewSDKError(err)
}

if c.ID == "" {
return Channel{}, errors.NewSDKError(apiutil.ErrMissingID)
}
url := fmt.Sprintf("%s/%s/%s", sdk.thingsURL, channelsEndpoint, c.ID)

_, body, sdkerr := sdk.processRequest(http.MethodPut, url, token, data, nil, http.StatusOK)
Expand Down Expand Up @@ -275,6 +282,9 @@ func (sdk mgSDK) DisableChannel(id, token string) (Channel, errors.SDKError) {
}

func (sdk mgSDK) DeleteChannel(id, token string) errors.SDKError {
if id == "" {
return errors.NewSDKError(apiutil.ErrMissingID)
}
url := fmt.Sprintf("%s/%s/%s", sdk.thingsURL, channelsEndpoint, id)
_, _, sdkerr := sdk.processRequest(http.MethodDelete, url, token, nil, nil, http.StatusNoContent)
return sdkerr
Expand Down
Loading

0 comments on commit 355fea3

Please sign in to comment.