Update CLI channel list and search commands to show if a channel is private (#11480)

Этот коммит содержится в:
Claudio Costa
2019-07-02 22:27:00 +02:00
коммит произвёл Joram Wilander
родитель b138d4b8c4
Коммит c95d295dce
2 изменённых файлов: 57 добавлений и 13 удалений

Просмотреть файл

@@ -79,7 +79,8 @@ var ListChannelsCmd = &cobra.Command{
Use: "list [teams]",
Short: "List all channels on specified teams.",
Long: `List all channels on specified teams.
Archived channels are appended with ' (archived)'.`,
Archived channels are appended with ' (archived)'.
Private channels are appended with ' (private)'.`,
Example: " channel list myteam",
Args: cobra.MinimumNArgs(1),
RunE: listChannelsCmdF,
@@ -448,11 +449,14 @@ func listChannelsCmdF(command *cobra.Command, args []string) error {
CommandPrintErrorln("Unable to list channels for '" + args[i] + "'")
} else {
for _, channel := range channels {
output := channel.Name
if channel.DeleteAt > 0 {
CommandPrettyPrintln(channel.Name + " (archived)")
} else {
CommandPrettyPrintln(channel.Name)
output += " (archived)"
}
if channel.Type == model.CHANNEL_PRIVATE {
output += " (private)"
}
CommandPrintErrorln(output)
}
}
}
@@ -591,10 +595,14 @@ func searchChannelCmdF(command *cobra.Command, args []string) error {
}
}
output := fmt.Sprintf(`Channel Name: %s, Display Name: %s, Channel ID: %s`, channel.Name, channel.DisplayName, channel.Id)
if channel.DeleteAt > 0 {
CommandPrettyPrintln(fmt.Sprintf(`Channel Name :%s, Display Name :%s, Channel ID :%s (archived)`, channel.Name, channel.DisplayName, channel.Id))
} else {
CommandPrettyPrintln(fmt.Sprintf(`Channel Name :%s, Display Name :%s, Channel ID :%s`, channel.Name, channel.DisplayName, channel.Id))
output += " (archived)"
}
if channel.Type == model.CHANNEL_PRIVATE {
output += " (private)"
}
CommandPrettyPrintln(output)
return nil
}

Просмотреть файл

@@ -82,6 +82,7 @@ func TestListChannels(t *testing.T) {
channel := th.CreatePublicChannel()
th.Client.Must(th.Client.DeleteChannel(channel.Id))
privateChannel := th.CreatePrivateChannel()
output := th.CheckCommand(t, "channel", "list", th.BasicTeam.Name)
@@ -92,6 +93,18 @@ func TestListChannels(t *testing.T) {
if !strings.Contains(string(output), channel.Name+" (archived)") {
t.Fatal("should have archived channel")
}
if !strings.Contains(string(output), privateChannel.Name+" (private)") {
t.Fatal("should have private channel")
}
th.Client.Must(th.Client.DeleteChannel(privateChannel.Id))
output = th.CheckCommand(t, "channel", "list", th.BasicTeam.Name)
if !strings.Contains(string(output), privateChannel.Name+" (archived) (private)") {
t.Fatal("should have a channel both archived and private")
}
}
func TestRestoreChannel(t *testing.T) {
@@ -139,7 +152,10 @@ func Test_searchChannelCmdF(t *testing.T) {
channel := th.CreatePublicChannel()
channel2 := th.CreatePublicChannel()
channel3 := th.CreatePrivateChannel()
channel4 := th.CreatePrivateChannel()
th.Client.DeleteChannel(channel2.Id)
th.Client.DeleteChannel(channel4.Id)
tests := []struct {
Name string
@@ -149,7 +165,7 @@ func Test_searchChannelCmdF(t *testing.T) {
{
"Success find Channel in any team",
[]string{"channel", "search", channel.Name},
fmt.Sprintf("Channel Name :%s, Display Name :%s, Channel ID :%s", channel.Name, channel.DisplayName, channel.Id),
fmt.Sprintf("Channel Name: %s, Display Name: %s, Channel ID: %s", channel.Name, channel.DisplayName, channel.Id),
},
{
"Failed find Channel in any team",
@@ -159,7 +175,7 @@ func Test_searchChannelCmdF(t *testing.T) {
{
"Success find Channel with param team ID",
[]string{"channel", "search", "--team", channel.TeamId, channel.Name},
fmt.Sprintf("Channel Name :%s, Display Name :%s, Channel ID :%s", channel.Name, channel.DisplayName, channel.Id),
fmt.Sprintf("Channel Name: %s, Display Name: %s, Channel ID: %s", channel.Name, channel.DisplayName, channel.Id),
},
{
"Failed find Channel with param team ID",
@@ -169,12 +185,32 @@ func Test_searchChannelCmdF(t *testing.T) {
{
"Success find archived Channel in any team",
[]string{"channel", "search", channel2.Name},
fmt.Sprintf("Channel Name :%s, Display Name :%s, Channel ID :%s (archived)", channel2.Name, channel2.DisplayName, channel2.Id),
fmt.Sprintf("Channel Name: %s, Display Name: %s, Channel ID: %s (archived)", channel2.Name, channel2.DisplayName, channel2.Id),
},
{
"Success find archived Channel with param team ID",
[]string{"channel", "search", "--team", channel2.TeamId, channel2.Name},
fmt.Sprintf("Channel Name :%s, Display Name :%s, Channel ID :%s (archived)", channel2.Name, channel2.DisplayName, channel2.Id),
fmt.Sprintf("Channel Name: %s, Display Name: %s, Channel ID: %s (archived)", channel2.Name, channel2.DisplayName, channel2.Id),
},
{
"Success find private Channel in any team",
[]string{"channel", "search", channel3.Name},
fmt.Sprintf("Channel Name: %s, Display Name: %s, Channel ID: %s (private)", channel3.Name, channel3.DisplayName, channel3.Id),
},
{
"Success find private Channel with param team ID",
[]string{"channel", "search", "--team", channel3.TeamId, channel3.Name},
fmt.Sprintf("Channel Name: %s, Display Name: %s, Channel ID: %s (private)", channel3.Name, channel3.DisplayName, channel3.Id),
},
{
"Success find both archived and private Channel in any team",
[]string{"channel", "search", channel4.Name},
fmt.Sprintf("Channel Name: %s, Display Name: %s, Channel ID: %s (archived) (private)", channel4.Name, channel4.DisplayName, channel4.Id),
},
{
"Success find both archived and private Channel with param team ID",
[]string{"channel", "search", "--team", channel4.TeamId, channel4.Name},
fmt.Sprintf("Channel Name: %s, Display Name: %s, Channel ID: %s (archived) (private)", channel4.Name, channel4.DisplayName, channel4.Id),
},
{
"Failed find team",
@@ -184,12 +220,12 @@ func Test_searchChannelCmdF(t *testing.T) {
{
"Success find Channel with param team ID",
[]string{"channel", "search", channel.Name, "--team", channel.TeamId},
fmt.Sprintf("Channel Name :%s, Display Name :%s, Channel ID :%s", channel.Name, channel.DisplayName, channel.Id),
fmt.Sprintf("Channel Name: %s, Display Name: %s, Channel ID: %s", channel.Name, channel.DisplayName, channel.Id),
},
{
"Success find Channel with param team ID",
[]string{"channel", "search", channel.Name, "--team=" + channel.TeamId},
fmt.Sprintf("Channel Name :%s, Display Name :%s, Channel ID :%s", channel.Name, channel.DisplayName, channel.Id),
fmt.Sprintf("Channel Name: %s, Display Name: %s, Channel ID: %s", channel.Name, channel.DisplayName, channel.Id),
},
}