Fix unnecessary type conversions (#12927)

Этот коммит содержится в:
Ben Schumacher
2019-10-28 10:57:21 +01:00
коммит произвёл GitHub
родитель 3701a393e5
Коммит 8a72ed2833
11 изменённых файлов: 65 добавлений и 66 удалений

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

@@ -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)
})
}