Fix unnecessary type conversions (#12927)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3701a393e5
Коммит
8a72ed2833
@@ -86,17 +86,17 @@ func TestListChannels(t *testing.T) {
|
||||
|
||||
output := th.CheckCommand(t, "channel", "list", th.BasicTeam.Name)
|
||||
|
||||
require.True(t, strings.Contains(string(output), "town-square"), "should have channels")
|
||||
require.True(t, strings.Contains(output, "town-square"), "should have channels")
|
||||
|
||||
require.True(t, strings.Contains(string(output), channel.Name+" (archived)"), "should have archived channel")
|
||||
require.True(t, strings.Contains(output, channel.Name+" (archived)"), "should have archived channel")
|
||||
|
||||
require.True(t, strings.Contains(string(output), privateChannel.Name+" (private)"), "should have private channel")
|
||||
require.True(t, strings.Contains(output, privateChannel.Name+" (private)"), "should have private channel")
|
||||
|
||||
th.Client.Must(th.Client.DeleteChannel(privateChannel.Id))
|
||||
|
||||
output = th.CheckCommand(t, "channel", "list", th.BasicTeam.Name)
|
||||
|
||||
require.True(t, strings.Contains(string(output), privateChannel.Name+" (archived) (private)"), "should have a channel both archived and private")
|
||||
require.True(t, strings.Contains(output, privateChannel.Name+" (archived) (private)"), "should have a channel both archived and private")
|
||||
}
|
||||
|
||||
func TestRestoreChannel(t *testing.T) {
|
||||
|
||||
@@ -121,10 +121,10 @@ func TestCreateCommand(t *testing.T) {
|
||||
if testCase.ExpectedErr == "" {
|
||||
assert.NotZero(t, len(cmds), "Failed to create command")
|
||||
assert.Equal(t, cmds[0].Trigger, "testcmd", "Failed to create command")
|
||||
assert.Contains(t, string(actual), "PASS")
|
||||
assert.Contains(t, actual, "PASS")
|
||||
} else {
|
||||
assert.LessOrEqual(t, len(cmds), 1, "Created command that shouldn't have been created")
|
||||
assert.Contains(t, string(actual), testCase.ExpectedErr)
|
||||
assert.Contains(t, actual, testCase.ExpectedErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -159,11 +159,11 @@ func TestShowCommand(t *testing.T) {
|
||||
assert.Equal(t, len(commands), 1)
|
||||
|
||||
output := th.CheckCommand(t, "command", "show", command.Id)
|
||||
assert.Contains(t, string(output), command.Id)
|
||||
assert.Contains(t, string(output), command.TeamId)
|
||||
assert.Contains(t, string(output), trigger)
|
||||
assert.Contains(t, string(output), displayName)
|
||||
assert.Contains(t, string(output), user.Username)
|
||||
assert.Contains(t, output, command.Id)
|
||||
assert.Contains(t, output, command.TeamId)
|
||||
assert.Contains(t, output, trigger)
|
||||
assert.Contains(t, output, displayName)
|
||||
assert.Contains(t, output, user.Username)
|
||||
})
|
||||
|
||||
t.Run("not existing command", func(t *testing.T) {
|
||||
@@ -253,14 +253,14 @@ func TestModifyCommand(t *testing.T) {
|
||||
t.Run("command not specified", func(t *testing.T) {
|
||||
args := []string{"command", "", command.Id, "--trigger-word", "sometrigger"}
|
||||
output, _ := th.RunCommandWithOutput(t, args...)
|
||||
assert.Contains(t, string(output), "Error: unknown flag: --trigger-word")
|
||||
assert.Contains(t, output, "Error: unknown flag: --trigger-word")
|
||||
})
|
||||
|
||||
t.Run("modify command unchanged", func(t *testing.T) {
|
||||
args := []string{"command", "modify", command.Id}
|
||||
output, _ := th.RunCommandWithOutput(t, args...)
|
||||
cmd, _ := th.App.GetCommand(command.Id)
|
||||
assert.Contains(t, string(output), "PASS")
|
||||
assert.Contains(t, output, "PASS")
|
||||
assert.Equal(t, cmd.DisplayName, command.DisplayName)
|
||||
assert.Equal(t, cmd.Method, command.Method)
|
||||
assert.Equal(t, cmd.TeamId, command.TeamId)
|
||||
@@ -277,7 +277,7 @@ func TestModifyCommand(t *testing.T) {
|
||||
t.Run("misspelled flag", func(t *testing.T) {
|
||||
args := []string{"command", "", command.Id, "--trigger-wor", "sometrigger"}
|
||||
output, _ := th.RunCommandWithOutput(t, args...)
|
||||
assert.Contains(t, string(output), "Error: unknown flag:")
|
||||
assert.Contains(t, output, "Error: unknown flag:")
|
||||
})
|
||||
|
||||
t.Run("multiple flags nil error", func(t *testing.T) {
|
||||
@@ -287,7 +287,7 @@ func TestModifyCommand(t *testing.T) {
|
||||
args := []string{"command", "modify", command.Id, "--trigger-word", testName, "--url", testURL, "--description", testDescription}
|
||||
output, _ := th.RunCommandWithOutput(t, args...)
|
||||
cmd, _ := th.App.GetCommand(command.Id)
|
||||
assert.Contains(t, string(output), "PASS")
|
||||
assert.Contains(t, output, "PASS")
|
||||
assert.Equal(t, cmd.Trigger, testName)
|
||||
assert.Equal(t, cmd.URL, testURL)
|
||||
assert.Equal(t, cmd.Description, testDescription)
|
||||
@@ -298,7 +298,7 @@ func TestModifyCommand(t *testing.T) {
|
||||
args := []string{"command", "modify", command.Id, "--title", testVal}
|
||||
output, _ := th.RunCommandWithOutput(t, args...)
|
||||
cmd, _ := th.App.GetCommand(command.Id)
|
||||
assert.Contains(t, string(output), "PASS")
|
||||
assert.Contains(t, output, "PASS")
|
||||
assert.Equal(t, cmd.DisplayName, testVal)
|
||||
})
|
||||
|
||||
@@ -307,7 +307,7 @@ func TestModifyCommand(t *testing.T) {
|
||||
args := []string{"command", "modify", command.Id, "--description", testVal}
|
||||
output, _ := th.RunCommandWithOutput(t, args...)
|
||||
cmd, _ := th.App.GetCommand(command.Id)
|
||||
assert.Contains(t, string(output), "PASS")
|
||||
assert.Contains(t, output, "PASS")
|
||||
assert.Equal(t, cmd.Description, testVal)
|
||||
})
|
||||
|
||||
@@ -316,7 +316,7 @@ func TestModifyCommand(t *testing.T) {
|
||||
args := []string{"command", "modify", command.Id, "--trigger-word", testVal}
|
||||
output, _ := th.RunCommandWithOutput(t, args...)
|
||||
cmd, _ := th.App.GetCommand(command.Id)
|
||||
assert.Contains(t, string(output), "PASS")
|
||||
assert.Contains(t, output, "PASS")
|
||||
assert.Equal(t, cmd.Trigger, testVal)
|
||||
})
|
||||
|
||||
@@ -324,14 +324,14 @@ func TestModifyCommand(t *testing.T) {
|
||||
testVal := "bad trigger"
|
||||
args := []string{"command", "modify", command.Id, "--trigger-word", testVal}
|
||||
output, _ := th.RunCommandWithOutput(t, args...)
|
||||
assert.Contains(t, string(output), "Error: a trigger word must not contain spaces")
|
||||
assert.Contains(t, output, "Error: a trigger word must not contain spaces")
|
||||
})
|
||||
|
||||
t.Run("trigger with leading /", func(t *testing.T) {
|
||||
testVal := "/bad-trigger"
|
||||
args := []string{"command", "modify", command.Id, "--trigger-word", testVal}
|
||||
output, _ := th.RunCommandWithOutput(t, args...)
|
||||
assert.Contains(t, string(output), "Error: a trigger word cannot begin with a /")
|
||||
assert.Contains(t, output, "Error: a trigger word cannot begin with a /")
|
||||
})
|
||||
|
||||
t.Run("blank trigger", func(t *testing.T) {
|
||||
@@ -341,7 +341,7 @@ func TestModifyCommand(t *testing.T) {
|
||||
cmd_modified, _ := th.App.GetCommand(command.Id)
|
||||
|
||||
// assert trigger remains unchanged
|
||||
assert.Contains(t, string(output), "PASS")
|
||||
assert.Contains(t, output, "PASS")
|
||||
assert.Equal(t, cmd_unmodified.Trigger, cmd_modified.Trigger)
|
||||
})
|
||||
|
||||
@@ -351,7 +351,7 @@ func TestModifyCommand(t *testing.T) {
|
||||
args := []string{"command", "modify", command.Id, "--url", testVal}
|
||||
output, _ := th.RunCommandWithOutput(t, args...)
|
||||
cmd, _ := th.App.GetCommand(command.Id)
|
||||
assert.Contains(t, string(output), "PASS")
|
||||
assert.Contains(t, output, "PASS")
|
||||
assert.Equal(t, cmd.URL, testVal)
|
||||
})
|
||||
|
||||
@@ -362,7 +362,7 @@ func TestModifyCommand(t *testing.T) {
|
||||
cmd_modified, _ := th.App.GetCommand(command.Id)
|
||||
|
||||
//assert URL remains unchanged
|
||||
assert.Contains(t, string(output), "PASS")
|
||||
assert.Contains(t, output, "PASS")
|
||||
assert.Equal(t, cmd_unmodified.URL, cmd_modified.URL)
|
||||
})
|
||||
|
||||
@@ -371,7 +371,7 @@ func TestModifyCommand(t *testing.T) {
|
||||
args := []string{"command", "modify", command.Id, "--icon", testVal}
|
||||
output, _ := th.RunCommandWithOutput(t, args...)
|
||||
cmd, _ := th.App.GetCommand(command.Id)
|
||||
assert.Contains(t, string(output), "PASS")
|
||||
assert.Contains(t, output, "PASS")
|
||||
assert.Equal(t, cmd.IconURL, testVal)
|
||||
})
|
||||
|
||||
@@ -380,7 +380,7 @@ func TestModifyCommand(t *testing.T) {
|
||||
args := []string{"command", "modify", command.Id, "--creator", testVal.Username}
|
||||
output, _ := th.RunCommandWithOutput(t, args...)
|
||||
cmd, _ := th.App.GetCommand(command.Id)
|
||||
assert.Contains(t, string(output), "PASS")
|
||||
assert.Contains(t, output, "PASS")
|
||||
assert.Equal(t, cmd.CreatorId, testVal.Id)
|
||||
})
|
||||
|
||||
@@ -388,14 +388,14 @@ func TestModifyCommand(t *testing.T) {
|
||||
testVal := "fakeuser"
|
||||
args := []string{"command", "modify", command.Id, "--creator", testVal}
|
||||
output, _ := th.RunCommandWithOutput(t, args...)
|
||||
assert.Contains(t, string(output), "unable to find user")
|
||||
assert.Contains(t, output, "unable to find user")
|
||||
})
|
||||
|
||||
t.Run("creator not admin user", func(t *testing.T) {
|
||||
testVal := user.Username
|
||||
args := []string{"command", "modify", command.Id, "--creator", testVal}
|
||||
output, _ := th.RunCommandWithOutput(t, args...)
|
||||
assert.Contains(t, string(output), "the creator must be a user who has permissions to manage slash commands")
|
||||
assert.Contains(t, output, "the creator must be a user who has permissions to manage slash commands")
|
||||
})
|
||||
|
||||
t.Run("response username nil error", func(t *testing.T) {
|
||||
@@ -403,7 +403,7 @@ func TestModifyCommand(t *testing.T) {
|
||||
args := []string{"command", "modify", command.Id, "--response-username", testVal}
|
||||
output, _ := th.RunCommandWithOutput(t, args...)
|
||||
cmd, _ := th.App.GetCommand(command.Id)
|
||||
assert.Contains(t, string(output), "PASS")
|
||||
assert.Contains(t, output, "PASS")
|
||||
assert.Equal(t, cmd.Username, testVal)
|
||||
})
|
||||
|
||||
@@ -414,13 +414,13 @@ func TestModifyCommand(t *testing.T) {
|
||||
// set post and check
|
||||
output_set, _ := th.RunCommandWithOutput(t, args_set...)
|
||||
cmd_set, _ := th.App.GetCommand(command.Id)
|
||||
assert.Contains(t, string(output_set), "PASS")
|
||||
assert.Contains(t, output_set, "PASS")
|
||||
assert.Equal(t, cmd_set.Method, "P")
|
||||
|
||||
// unset post and check
|
||||
output_unset, _ := th.RunCommandWithOutput(t, args_unset...)
|
||||
cmd_unset, _ := th.App.GetCommand(command.Id)
|
||||
assert.Contains(t, string(output_unset), "PASS")
|
||||
assert.Contains(t, output_unset, "PASS")
|
||||
assert.Equal(t, cmd_unset.Method, "G")
|
||||
})
|
||||
|
||||
@@ -431,13 +431,13 @@ func TestModifyCommand(t *testing.T) {
|
||||
// set autocomplete and check
|
||||
output_set, _ := th.RunCommandWithOutput(t, args_set...)
|
||||
cmd_set, _ := th.App.GetCommand(command.Id)
|
||||
assert.Contains(t, string(output_set), "PASS")
|
||||
assert.Contains(t, output_set, "PASS")
|
||||
assert.Equal(t, cmd_set.AutoComplete, true)
|
||||
|
||||
// unset autocomplete and check
|
||||
output_unset, _ := th.RunCommandWithOutput(t, args_unset...)
|
||||
cmd_unset, _ := th.App.GetCommand(command.Id)
|
||||
assert.Contains(t, string(output_unset), "PASS")
|
||||
assert.Contains(t, output_unset, "PASS")
|
||||
assert.Equal(t, cmd_unset.AutoComplete, false)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -111,10 +111,10 @@ func TestConfigGet(t *testing.T) {
|
||||
t.Run("check output", func(t *testing.T) {
|
||||
output := th.CheckCommand(t, "config", "get", "MessageExportSettings")
|
||||
|
||||
assert.Contains(t, string(output), "EnableExport")
|
||||
assert.Contains(t, string(output), "ExportFormat")
|
||||
assert.Contains(t, string(output), "DailyRunTime")
|
||||
assert.Contains(t, string(output), "ExportFromTimestamp")
|
||||
assert.Contains(t, output, "EnableExport")
|
||||
assert.Contains(t, output, "ExportFormat")
|
||||
assert.Contains(t, output, "DailyRunTime")
|
||||
assert.Contains(t, output, "ExportFromTimestamp")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -138,33 +138,33 @@ func TestConfigSet(t *testing.T) {
|
||||
t.Run("Error when the wrong value is set", func(t *testing.T) {
|
||||
assert.Error(t, th.RunCommand(t, "config", "set", "EmailSettings.ConnectionSecurity", "invalid-key"))
|
||||
output := th.CheckCommand(t, "config", "get", "EmailSettings.ConnectionSecurity")
|
||||
assert.NotContains(t, string(output), "invalid-key")
|
||||
assert.NotContains(t, output, "invalid-key")
|
||||
})
|
||||
|
||||
t.Run("Error when the parameter of an unknown plugin is set", func(t *testing.T) {
|
||||
output, err := th.RunCommandWithOutput(t, "config", "set", "PluginSettings.Plugins.someplugin", "true")
|
||||
assert.Error(t, err)
|
||||
assert.NotContains(t, string(output), "panic")
|
||||
assert.NotContains(t, output, "panic")
|
||||
})
|
||||
|
||||
t.Run("Error when the wrong locale is set", func(t *testing.T) {
|
||||
th.CheckCommand(t, "config", "set", "LocalizationSettings.DefaultServerLocale", "es")
|
||||
assert.Error(t, th.RunCommand(t, "config", "set", "LocalizationSettings.DefaultServerLocale", "invalid-key"))
|
||||
output := th.CheckCommand(t, "config", "get", "LocalizationSettings.DefaultServerLocale")
|
||||
assert.NotContains(t, string(output), "invalid-key")
|
||||
assert.NotContains(t, string(output), "\"en\"")
|
||||
assert.NotContains(t, output, "invalid-key")
|
||||
assert.NotContains(t, output, "\"en\"")
|
||||
})
|
||||
|
||||
t.Run("Success when a valid value is set", func(t *testing.T) {
|
||||
assert.NoError(t, th.RunCommand(t, "config", "set", "EmailSettings.ConnectionSecurity", "TLS"))
|
||||
output := th.CheckCommand(t, "config", "get", "EmailSettings.ConnectionSecurity")
|
||||
assert.Contains(t, string(output), "TLS")
|
||||
assert.Contains(t, output, "TLS")
|
||||
})
|
||||
|
||||
t.Run("Success when a valid locale is set", func(t *testing.T) {
|
||||
assert.NoError(t, th.RunCommand(t, "config", "set", "LocalizationSettings.DefaultServerLocale", "es"))
|
||||
output := th.CheckCommand(t, "config", "get", "LocalizationSettings.DefaultServerLocale")
|
||||
assert.Contains(t, string(output), "\"es\"")
|
||||
assert.Contains(t, output, "\"es\"")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -339,9 +339,9 @@ func TestConfigShow(t *testing.T) {
|
||||
|
||||
t.Run("successfully dumping config", func(t *testing.T) {
|
||||
output := th.CheckCommand(t, "config", "show")
|
||||
assert.Contains(t, string(output), "SqlSettings")
|
||||
assert.Contains(t, string(output), "MessageExportSettings")
|
||||
assert.Contains(t, string(output), "AnnouncementSettings")
|
||||
assert.Contains(t, output, "SqlSettings")
|
||||
assert.Contains(t, output, "MessageExportSettings")
|
||||
assert.Contains(t, output, "AnnouncementSettings")
|
||||
})
|
||||
|
||||
t.Run("successfully dumping config as json", func(t *testing.T) {
|
||||
|
||||
@@ -114,7 +114,7 @@ func TestChannelGroupStatus(t *testing.T) {
|
||||
|
||||
// get status, should be Disabled
|
||||
output := th.CheckCommand(t, "group", "channel", "status", th.BasicTeam.Name+":"+channel.Name)
|
||||
require.Contains(t, string(output), "Disabled")
|
||||
require.Contains(t, output, "Disabled")
|
||||
|
||||
// add group and enable
|
||||
id := model.NewId()
|
||||
@@ -143,7 +143,7 @@ func TestChannelGroupStatus(t *testing.T) {
|
||||
|
||||
// get status, should be enabled
|
||||
output = th.CheckCommand(t, "group", "channel", "status", th.BasicTeam.Name+":"+channel.Name)
|
||||
require.Contains(t, string(output), "Enabled")
|
||||
require.Contains(t, output, "Enabled")
|
||||
|
||||
// try to get status of nonexistent channel, should fail
|
||||
require.Error(t, th.RunCommand(t, "group", "channel", "status", th.BasicTeam.Name+":"+channel.Name+"asdf"))
|
||||
@@ -204,8 +204,8 @@ func TestChannelGroupList(t *testing.T) {
|
||||
|
||||
// list groups
|
||||
output := th.CheckCommand(t, "group", "channel", "list", th.BasicTeam.Name+":"+channel.Name)
|
||||
require.Contains(t, string(output), g1.DisplayName)
|
||||
require.Contains(t, string(output), g2.DisplayName)
|
||||
require.Contains(t, output, g1.DisplayName)
|
||||
require.Contains(t, output, g2.DisplayName)
|
||||
|
||||
// try to get list of nonexistent channel, should fail
|
||||
require.Error(t, th.RunCommand(t, "group", "channel", "list", th.BasicTeam.Name+":"+channel.Name+"asdf"))
|
||||
@@ -301,7 +301,7 @@ func TestTeamGroupStatus(t *testing.T) {
|
||||
|
||||
// get status, should be Disabled
|
||||
output := th.CheckCommand(t, "group", "team", "status", th.BasicTeam.Name)
|
||||
require.Contains(t, string(output), "Disabled")
|
||||
require.Contains(t, output, "Disabled")
|
||||
|
||||
// add group and enable
|
||||
id := model.NewId()
|
||||
@@ -330,7 +330,7 @@ func TestTeamGroupStatus(t *testing.T) {
|
||||
|
||||
// get status, should be enabled
|
||||
output = th.CheckCommand(t, "group", "team", "status", th.BasicTeam.Name)
|
||||
require.Contains(t, string(output), "Enabled")
|
||||
require.Contains(t, output, "Enabled")
|
||||
|
||||
// try to get status of nonexistent channel, should fail
|
||||
require.Error(t, th.RunCommand(t, "group", "team", "status", th.BasicTeam.Name+"asdf"))
|
||||
@@ -388,8 +388,8 @@ func TestTeamGroupList(t *testing.T) {
|
||||
|
||||
// list groups
|
||||
output := th.CheckCommand(t, "group", "team", "list", th.BasicTeam.Name)
|
||||
require.Contains(t, string(output), g1.DisplayName)
|
||||
require.Contains(t, string(output), g2.DisplayName)
|
||||
require.Contains(t, output, g1.DisplayName)
|
||||
require.Contains(t, output, g2.DisplayName)
|
||||
|
||||
// try to get list of nonexistent team, should fail
|
||||
require.Error(t, th.RunCommand(t, "group", "team", "list", th.BasicTeam.Name+"asdf"))
|
||||
|
||||
Ссылка в новой задаче
Block a user