From d16df03623b4d9e316515b7acd01b3ffccd291d3 Mon Sep 17 00:00:00 2001 From: nyagamunene Date: Fri, 10 Jan 2025 14:06:00 +0300 Subject: [PATCH] fix tests Signed-off-by: nyagamunene --- cli/clients.go | 20 ++++++++++++++------ cli/clients_test.go | 15 +++++++++++++-- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/cli/clients.go b/cli/clients.go index 52539d5a62..6220bb8bd1 100644 --- a/cli/clients.go +++ b/cli/clients.go @@ -198,11 +198,11 @@ var cmdClients = []cobra.Command{ }, }, { - Use: "connect ", + Use: "connect ", Short: "Connect client", Long: "Connect client to the channel\n" + "Usage:\n" + - "\tsupermq-cli clients connect $DOMAINID $USERTOKEN\n", + "\tsupermq-cli clients connect $DOMAINID $USERTOKEN\n", Run: func(cmd *cobra.Command, args []string) { if len(args) != 5 { logUsageCmd(*cmd, cmd.Use) @@ -229,22 +229,30 @@ var cmdClients = []cobra.Command{ }, }, { - Use: "disconnect ", + Use: "disconnect ", Short: "Disconnect client", Long: "Disconnect client to the channel\n" + "Usage:\n" + - "\tsupermq-cli clients disconnect $DOMAINID $USERTOKEN\n", + "\tsupermq-cli clients disconnect $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 + } + 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 } diff --git a/cli/clients_test.go b/cli/clients_test.go index ffbfe447f5..e535290859 100644 --- a/cli/clients_test.go +++ b/cli/clients_test.go @@ -28,6 +28,7 @@ var ( tokenWithoutDomain = "valid" relation = "administrator" all = "all" + conntype = `["publish","subscribe"]` ) var client = sdk.Client{ @@ -817,6 +818,7 @@ func TestConnectClientCmd(t *testing.T) { args: []string{ client.ID, channel.ID, + conntype, domainID, token, }, @@ -827,6 +829,7 @@ func TestConnectClientCmd(t *testing.T) { args: []string{ client.ID, channel.ID, + conntype, domainID, token, extraArg, @@ -838,6 +841,7 @@ func TestConnectClientCmd(t *testing.T) { args: []string{ invalidID, channel.ID, + conntype, domainID, token, }, @@ -850,6 +854,7 @@ func TestConnectClientCmd(t *testing.T) { args: []string{ client.ID, invalidID, + conntype, domainID, token, }, @@ -862,6 +867,7 @@ func TestConnectClientCmd(t *testing.T) { args: []string{ client.ID, channel.ID, + conntype, invalidID, token, }, @@ -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 { @@ -907,6 +913,7 @@ func TestDisconnectClientCmd(t *testing.T) { args: []string{ client.ID, channel.ID, + conntype, domainID, token, }, @@ -917,6 +924,7 @@ func TestDisconnectClientCmd(t *testing.T) { args: []string{ client.ID, channel.ID, + conntype, domainID, token, extraArg, @@ -928,6 +936,7 @@ func TestDisconnectClientCmd(t *testing.T) { args: []string{ invalidID, channel.ID, + conntype, domainID, token, }, @@ -940,6 +949,7 @@ func TestDisconnectClientCmd(t *testing.T) { args: []string{ client.ID, invalidID, + conntype, domainID, token, }, @@ -952,6 +962,7 @@ func TestDisconnectClientCmd(t *testing.T) { args: []string{ client.ID, channel.ID, + conntype, invalidID, token, }, @@ -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 {