Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MG-888 - Update channels SDK tests #2269

Merged
merged 6 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading