diff options
author | Christopher Speller <crspeller@gmail.com> | 2016-12-06 10:49:34 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-06 10:49:34 -0500 |
commit | 026553e4f87bfc647a5c03129752e30fc523fa07 (patch) | |
tree | d5403c760151c0fa26fc6d020f7f4326ea9d6f8a /cmd/platform/test.go | |
parent | dcf11a14d8363c79ab62aefca46834d6daa615ab (diff) | |
download | chat-026553e4f87bfc647a5c03129752e30fc523fa07.tar.gz chat-026553e4f87bfc647a5c03129752e30fc523fa07.tar.bz2 chat-026553e4f87bfc647a5c03129752e30fc523fa07.zip |
Improving command line interface (#4689)
Diffstat (limited to 'cmd/platform/test.go')
-rw-r--r-- | cmd/platform/test.go | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/cmd/platform/test.go b/cmd/platform/test.go new file mode 100644 index 000000000..d82734c75 --- /dev/null +++ b/cmd/platform/test.go @@ -0,0 +1,82 @@ +// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package main + +import ( + "bufio" + "fmt" + "os" + "os/exec" + + "github.com/mattermost/platform/api" + "github.com/mattermost/platform/utils" + "github.com/spf13/cobra" +) + +var testCmd = &cobra.Command{ + Use: "test", + Short: "Testing Commands", + Hidden: true, +} + +var runWebClientTestsCmd = &cobra.Command{ + Use: "web_client_tests", + Short: "Run the web client tests", + RunE: webClientTestsCmdF, +} + +func init() { + testCmd.AddCommand( + runWebClientTestsCmd, + ) +} + +func webClientTestsCmdF(cmd *cobra.Command, args []string) error { + initDBCommandContextCobra(cmd) + utils.InitTranslations(utils.Cfg.LocalizationSettings) + api.InitRouter() + api.InitApi() + setupClientTests() + api.StartServer() + runWebClientTests() + api.StopServer() + + return nil +} + +func setupClientTests() { + *utils.Cfg.TeamSettings.EnableOpenServer = true + *utils.Cfg.ServiceSettings.EnableCommands = false + *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false + *utils.Cfg.ServiceSettings.EnableCustomEmoji = true + utils.Cfg.ServiceSettings.EnableIncomingWebhooks = false + utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = false + utils.SetDefaultRolesBasedOnConfig() +} + +func executeTestCommand(cmd *exec.Cmd) { + cmdOutPipe, err := cmd.StdoutPipe() + if err != nil { + CommandPrintErrorln("Failed to run tests") + return + } + + cmdOutReader := bufio.NewScanner(cmdOutPipe) + go func() { + for cmdOutReader.Scan() { + fmt.Println(cmdOutReader.Text()) + } + }() + + if err := cmd.Run(); err != nil { + CommandPrintErrorln("Client Tests failed") + return + } +} + +func runWebClientTests() { + os.Chdir("webapp") + cmd := exec.Command("npm", "test") + executeTestCommand(cmd) +} |