Skip to content

Commit

Permalink
MG-888 - Update channels SDK tests (#2269)
Browse files Browse the repository at this point in the history
Signed-off-by: 1998-felix <[email protected]>
  • Loading branch information
felixgateru authored Jul 5, 2024
1 parent 083e655 commit b8a1fe1
Show file tree
Hide file tree
Showing 5 changed files with 2,340 additions and 519 deletions.
14 changes: 12 additions & 2 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/pkg/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 @@ -122,13 +126,16 @@ func (sdk mgSDK) ChannelPermissions(id, token string) (Channel, errors.SDKError)
}

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

data, err := json.Marshal(c)
if err != nil {
return Channel{}, errors.NewSDKError(err)
}

url := fmt.Sprintf("%s/%s/%s", sdk.thingsURL, channelsEndpoint, c.ID)

_, body, sdkerr := sdk.processRequest(http.MethodPut, url, token, data, nil, http.StatusOK)
if sdkerr != nil {
return Channel{}, sdkerr
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 b8a1fe1

Please sign in to comment.