NOISSUE - Update SDK message order (#2814)

Signed-off-by: Dusan Borovcanin <borovcanindusan1@gmail.com>
This commit is contained in:
Dušan Borovčanin
2025-04-11 11:23:34 +02:00
committed by GitHub
parent 6151be72ce
commit 5fd1d9b431
6 changed files with 26 additions and 26 deletions
+1 -1
View File
@@ -269,7 +269,7 @@ supermq-cli channels connections <channel_id> <user_token>
#### Send a message over HTTP
```bash
supermq-cli messages send <channel_id> '[{"bn":"Dev1","n":"temp","v":20}, {"n":"hum","v":40}, {"bn":"Dev2", "n":"temp","v":20}, {"n":"hum","v":40}]' <client_secret>
supermq-cli messages send <domain_id> <channel_id.subtopic> <secret> '[{"bn":"Dev1","n":"temp","v":20}, {"n":"hum","v":40}, {"bn":"Dev2", "n":"temp","v":20}, {"n":"hum","v":40}]'
```
#### Read messages over HTTP
+1 -1
View File
@@ -7,7 +7,7 @@ import "github.com/spf13/cobra"
var cmdMessages = []cobra.Command{
{
Use: "send <channel_id.subtopic> <JSON_string> <domain_id> <client_secret>",
Use: "send <domain_id> <channel_id.subtopic> <secret> <JSON_string>",
Short: "Send messages",
Long: `Sends message on the channel`,
Run: func(cmd *cobra.Command, args []string) {
+3 -3
View File
@@ -15,8 +15,8 @@ import (
const channelParts = 2
func (sdk mgSDK) SendMessage(ctx context.Context, chanName, msg, domainID, key string) errors.SDKError {
chanNameParts := strings.SplitN(chanName, ".", channelParts)
func (sdk mgSDK) SendMessage(ctx context.Context, domainID, topic, secret, msg string) errors.SDKError {
chanNameParts := strings.SplitN(topic, ".", channelParts)
chanID := chanNameParts[0]
subtopicPart := ""
if len(chanNameParts) == channelParts {
@@ -25,7 +25,7 @@ func (sdk mgSDK) SendMessage(ctx context.Context, chanName, msg, domainID, key s
reqURL := fmt.Sprintf("%s/m/%s/c/%s%s", sdk.httpAdapterURL, domainID, chanID, subtopicPart)
_, _, err := sdk.processRequest(ctx, http.MethodPost, reqURL, ClientPrefix+key, []byte(msg), nil, http.StatusAccepted)
_, _, err := sdk.processRequest(ctx, http.MethodPost, reqURL, ClientPrefix+secret, []byte(msg), nil, http.StatusAccepted)
return err
}
+9 -9
View File
@@ -75,7 +75,7 @@ func TestSendMessage(t *testing.T) {
cases := []struct {
desc string
chanName string
topic string
domainID string
msg string
clientKey string
@@ -86,7 +86,7 @@ func TestSendMessage(t *testing.T) {
}{
{
desc: "publish message successfully",
chanName: channelID,
topic: channelID,
domainID: domainID,
msg: msg,
clientKey: clientKey,
@@ -97,7 +97,7 @@ func TestSendMessage(t *testing.T) {
},
{
desc: "publish message with empty client key",
chanName: channelID,
topic: channelID,
domainID: domainID,
msg: msg,
clientKey: "",
@@ -108,7 +108,7 @@ func TestSendMessage(t *testing.T) {
},
{
desc: "publish message with invalid client key",
chanName: channelID,
topic: channelID,
domainID: domainID,
msg: msg,
clientKey: "invalid",
@@ -119,7 +119,7 @@ func TestSendMessage(t *testing.T) {
},
{
desc: "publish message with invalid channel ID",
chanName: wrongID,
topic: wrongID,
domainID: domainID,
msg: msg,
clientKey: clientKey,
@@ -130,7 +130,7 @@ func TestSendMessage(t *testing.T) {
},
{
desc: "publish message with empty message body",
chanName: channelID,
topic: channelID,
domainID: domainID,
msg: "",
clientKey: clientKey,
@@ -141,7 +141,7 @@ func TestSendMessage(t *testing.T) {
},
{
desc: "publish message with channel subtopic",
chanName: channelID + ".subtopic",
topic: channelID + ".subtopic",
domainID: domainID,
msg: msg,
clientKey: clientKey,
@@ -152,7 +152,7 @@ func TestSendMessage(t *testing.T) {
},
{
desc: "publish message with invalid domain ID",
chanName: channelID,
topic: channelID,
domainID: wrongID,
msg: msg,
clientKey: clientKey,
@@ -167,7 +167,7 @@ func TestSendMessage(t *testing.T) {
authzCall := clientsGRPCClient.On("Authenticate", mock.Anything, mock.Anything).Return(tc.authRes, tc.authErr)
authnCall := channelsGRPCClient.On("Authorize", mock.Anything, mock.Anything).Return(&grpcChannelsV1.AuthzRes{Authorized: true}, nil)
svcCall := pub.On("Publish", mock.Anything, channelID, mock.Anything).Return(tc.svcErr)
err := mgsdk.SendMessage(context.Background(), tc.chanName, tc.msg, tc.domainID, tc.clientKey)
err := mgsdk.SendMessage(context.Background(), tc.domainID, tc.topic, tc.clientKey, tc.msg)
assert.Equal(t, tc.err, err)
if tc.err == nil {
ok := svcCall.Parent.AssertCalled(t, "Publish", mock.Anything, channelID, mock.Anything)
+10 -10
View File
@@ -5644,8 +5644,8 @@ func (_c *SDK_SendInvitation_Call) RunAndReturn(run func(ctx context.Context, in
}
// SendMessage provides a mock function for the type SDK
func (_mock *SDK) SendMessage(ctx context.Context, chanID string, msg string, domainID string, key string) errors.SDKError {
ret := _mock.Called(ctx, chanID, msg, domainID, key)
func (_mock *SDK) SendMessage(ctx context.Context, domainID string, topic string, secret string, msg string) errors.SDKError {
ret := _mock.Called(ctx, domainID, topic, secret, msg)
if len(ret) == 0 {
panic("no return value specified for SendMessage")
@@ -5653,7 +5653,7 @@ func (_mock *SDK) SendMessage(ctx context.Context, chanID string, msg string, do
var r0 errors.SDKError
if returnFunc, ok := ret.Get(0).(func(context.Context, string, string, string, string) errors.SDKError); ok {
r0 = returnFunc(ctx, chanID, msg, domainID, key)
r0 = returnFunc(ctx, domainID, topic, secret, msg)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(errors.SDKError)
@@ -5669,15 +5669,15 @@ type SDK_SendMessage_Call struct {
// SendMessage is a helper method to define mock.On call
// - ctx
// - chanID
// - msg
// - domainID
// - key
func (_e *SDK_Expecter) SendMessage(ctx interface{}, chanID interface{}, msg interface{}, domainID interface{}, key interface{}) *SDK_SendMessage_Call {
return &SDK_SendMessage_Call{Call: _e.mock.On("SendMessage", ctx, chanID, msg, domainID, key)}
// - topic
// - secret
// - msg
func (_e *SDK_Expecter) SendMessage(ctx interface{}, domainID interface{}, topic interface{}, secret interface{}, msg interface{}) *SDK_SendMessage_Call {
return &SDK_SendMessage_Call{Call: _e.mock.On("SendMessage", ctx, domainID, topic, secret, msg)}
}
func (_c *SDK_SendMessage_Call) Run(run func(ctx context.Context, chanID string, msg string, domainID string, key string)) *SDK_SendMessage_Call {
func (_c *SDK_SendMessage_Call) Run(run func(ctx context.Context, domainID string, topic string, secret string, msg string)) *SDK_SendMessage_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(string), args[4].(string))
})
@@ -5689,7 +5689,7 @@ func (_c *SDK_SendMessage_Call) Return(sDKError errors.SDKError) *SDK_SendMessag
return _c
}
func (_c *SDK_SendMessage_Call) RunAndReturn(run func(ctx context.Context, chanID string, msg string, domainID string, key string) errors.SDKError) *SDK_SendMessage_Call {
func (_c *SDK_SendMessage_Call) RunAndReturn(run func(ctx context.Context, domainID string, topic string, secret string, msg string) errors.SDKError) *SDK_SendMessage_Call {
_c.Call.Return(run)
return _c
}
+2 -2
View File
@@ -1015,9 +1015,9 @@ type SDK interface {
//
// example:
// msg := '[{"bn":"some-base-name:","bt":1.276020076001e+09, "bu":"A","bver":5, "n":"voltage","u":"V","v":120.1}, {"n":"current","t":-5,"v":1.2}, {"n":"current","t":-4,"v":1.3}]'
// err := sdk.SendMessage("channelID", msg, "domainID", "clientSecret")
// err := sdk.SendMessage("domainID", "topic", "clientSecret", msg)
// fmt.Println(err)
SendMessage(ctx context.Context, chanID, msg, domainID, key string) errors.SDKError
SendMessage(ctx context.Context, domainID, topic, secret string, msg string) errors.SDKError
// SetContentType sets message content type.
//