Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: nyagamunene <[email protected]>
  • Loading branch information
nyagamunene committed Jan 10, 2025
1 parent 22f44dd commit d16df03
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
20 changes: 14 additions & 6 deletions cli/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,11 @@ var cmdClients = []cobra.Command{
},
},
{
Use: "connect <client_id> <channel_id> <conn_types_json> <domain_id> <user_auth_token>",
Use: "connect <client_id> <channel_id> <conn_types_json_list> <domain_id> <user_auth_token>",
Short: "Connect client",
Long: "Connect client to the channel\n" +
"Usage:\n" +
"\tsupermq-cli clients connect <client_id> <channel_id> <conn_types_json> $DOMAINID $USERTOKEN\n",
"\tsupermq-cli clients connect <client_id> <channel_id> <conn_types_json_list> $DOMAINID $USERTOKEN\n",
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 5 {
logUsageCmd(*cmd, cmd.Use)
Expand All @@ -229,22 +229,30 @@ var cmdClients = []cobra.Command{
},
},
{
Use: "disconnect <client_id> <channel_id> <domain_id> <user_auth_token>",
Use: "disconnect <client_id> <channel_id> <conn_types_json_list> <domain_id> <user_auth_token>",
Short: "Disconnect client",
Long: "Disconnect client to the channel\n" +
"Usage:\n" +
"\tsupermq-cli clients disconnect <client_id> <channel_id> $DOMAINID $USERTOKEN\n",
"\tsupermq-cli clients disconnect <client_id> <channel_id> <conn_types_json_list> $DOMAINID $USERTOKEN\n",
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 4 {
if len(args) != 5 {
logUsageCmd(*cmd, cmd.Use)
return
}

var conn_types []string
err := json.Unmarshal([]byte(args[2]), &conn_types)
if err != nil {
logErrorCmd(*cmd, err)
return
}

Check warning on line 248 in cli/clients.go

View check run for this annotation

Codecov / codecov/patch

cli/clients.go#L246-L248

Added lines #L246 - L248 were not covered by tests

connIDs := smqsdk.Connection{
ClientIDs: []string{args[0]},
ChannelIDs: []string{args[1]},
Types: conn_types,
}
if err := sdk.Disconnect(connIDs, args[2], args[3]); err != nil {
if err := sdk.Disconnect(connIDs, args[3], args[4]); err != nil {
logErrorCmd(*cmd, err)
return
}
Expand Down
15 changes: 13 additions & 2 deletions cli/clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var (
tokenWithoutDomain = "valid"
relation = "administrator"
all = "all"
conntype = `["publish","subscribe"]`
)

var client = sdk.Client{
Expand Down Expand Up @@ -817,6 +818,7 @@ func TestConnectClientCmd(t *testing.T) {
args: []string{
client.ID,
channel.ID,
conntype,
domainID,
token,
},
Expand All @@ -827,6 +829,7 @@ func TestConnectClientCmd(t *testing.T) {
args: []string{
client.ID,
channel.ID,
conntype,
domainID,
token,
extraArg,
Expand All @@ -838,6 +841,7 @@ func TestConnectClientCmd(t *testing.T) {
args: []string{
invalidID,
channel.ID,
conntype,
domainID,
token,
},
Expand All @@ -850,6 +854,7 @@ func TestConnectClientCmd(t *testing.T) {
args: []string{
client.ID,
invalidID,
conntype,
domainID,
token,
},
Expand All @@ -862,6 +867,7 @@ func TestConnectClientCmd(t *testing.T) {
args: []string{
client.ID,
channel.ID,
conntype,
invalidID,
token,
},
Expand All @@ -873,7 +879,7 @@ func TestConnectClientCmd(t *testing.T) {

for _, tc := range cases {
t.Run(tc.desc, func(t *testing.T) {
sdkCall := sdkMock.On("Connect", mock.Anything, tc.args[2], tc.args[3]).Return(tc.sdkErr)
sdkCall := sdkMock.On("Connect", mock.Anything, tc.args[3], tc.args[4]).Return(tc.sdkErr)
out := executeCommand(t, rootCmd, append([]string{connCmd}, tc.args...)...)

switch tc.logType {
Expand Down Expand Up @@ -907,6 +913,7 @@ func TestDisconnectClientCmd(t *testing.T) {
args: []string{
client.ID,
channel.ID,
conntype,
domainID,
token,
},
Expand All @@ -917,6 +924,7 @@ func TestDisconnectClientCmd(t *testing.T) {
args: []string{
client.ID,
channel.ID,
conntype,
domainID,
token,
extraArg,
Expand All @@ -928,6 +936,7 @@ func TestDisconnectClientCmd(t *testing.T) {
args: []string{
invalidID,
channel.ID,
conntype,
domainID,
token,
},
Expand All @@ -940,6 +949,7 @@ func TestDisconnectClientCmd(t *testing.T) {
args: []string{
client.ID,
invalidID,
conntype,
domainID,
token,
},
Expand All @@ -952,6 +962,7 @@ func TestDisconnectClientCmd(t *testing.T) {
args: []string{
client.ID,
channel.ID,
conntype,
invalidID,
token,
},
Expand All @@ -963,7 +974,7 @@ func TestDisconnectClientCmd(t *testing.T) {

for _, tc := range cases {
t.Run(tc.desc, func(t *testing.T) {
sdkCall := sdkMock.On("Disconnect", mock.Anything, tc.args[2], tc.args[3]).Return(tc.sdkErr)
sdkCall := sdkMock.On("Disconnect", mock.Anything, tc.args[3], tc.args[4]).Return(tc.sdkErr)
out := executeCommand(t, rootCmd, append([]string{disconnCmd}, tc.args...)...)

switch tc.logType {
Expand Down

0 comments on commit d16df03

Please sign in to comment.