MM-21343: Recognize multi-line slash commands without requiring trailing space after trigger word (#13646)
* change how we are parsing the args.command * change comment * atttempt to write unit test * remove quotes * use unicode.IsSpace * MM-21343 fix panic * use table * test cases * bad request, add test for missing '/' * mispelled err * Update app/command.go Co-Authored-By: Jesse Hallam <jesse.hallam@gmail.com> * Update app/command.go Co-Authored-By: Jesse Hallam <jesse.hallam@gmail.com> * use a map * use subtest and add test case of empty command * go fmt * do not use t.fatal * Update app/command.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * fix missing unicode import Co-authored-by: wiggin77 <wiggin77@warpmail.net> Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com> Co-authored-by: mattermod <mattermod@users.noreply.github.com> Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com>
Этот коммит содержится в:
@@ -75,6 +75,49 @@ func TestCreateCommandPost(t *testing.T) {
|
||||
require.Equal(t, err.Id, "api.context.invalid_param.app_error")
|
||||
}
|
||||
|
||||
func TestExecuteCommand(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
t.Run("valid tests with different whitespace characters", func(t *testing.T) {
|
||||
TestCases := map[string]string{
|
||||
"/code happy path": " happy path",
|
||||
"/code\nnewline path": " newline path",
|
||||
"/code\n/nDouble newline path": " /nDouble newline path",
|
||||
"/code double space": " double space",
|
||||
"/code\ttab": " tab",
|
||||
}
|
||||
|
||||
for TestCase, result := range TestCases {
|
||||
args := &model.CommandArgs{
|
||||
Command: TestCase,
|
||||
T: func(s string, args ...interface{}) string { return s },
|
||||
}
|
||||
resp, _ := th.App.ExecuteCommand(args)
|
||||
|
||||
assert.Equal(t, resp.Text, result)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("missing slash character", func(t *testing.T) {
|
||||
argsMissingSlashCharacter := &model.CommandArgs{
|
||||
Command: "missing leading slash character",
|
||||
T: func(s string, args ...interface{}) string { return s },
|
||||
}
|
||||
_, err := th.App.ExecuteCommand(argsMissingSlashCharacter)
|
||||
require.Equal(t, "api.command.execute_command.format.app_error", err.Id)
|
||||
})
|
||||
|
||||
t.Run("empty", func(t *testing.T) {
|
||||
argsMissingSlashCharacter := &model.CommandArgs{
|
||||
Command: "",
|
||||
T: func(s string, args ...interface{}) string { return s },
|
||||
}
|
||||
_, err := th.App.ExecuteCommand(argsMissingSlashCharacter)
|
||||
require.Equal(t, "api.command.execute_command.format.app_error", err.Id)
|
||||
})
|
||||
}
|
||||
|
||||
func TestHandleCommandResponsePost(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
Ссылка в новой задаче
Block a user