summaryrefslogtreecommitdiffstats
path: root/api/command_loadtest.go
diff options
context:
space:
mode:
authorAndy Lo-A-Foe <andy.loafoe@aemian.com>2016-04-06 14:23:26 +0200
committerChristopher Speller <crspeller@gmail.com>2016-04-06 08:23:26 -0400
commit1a1fd39cf8e42c143fe9057b50aad5e074b91947 (patch)
treea610b5f411f3c4a0efd713e13e6fce935ceb7afc /api/command_loadtest.go
parent1954c449931344baca04b126c86b00f95677a570 (diff)
downloadchat-1a1fd39cf8e42c143fe9057b50aad5e074b91947.tar.gz
chat-1a1fd39cf8e42c143fe9057b50aad5e074b91947.tar.bz2
chat-1a1fd39cf8e42c143fe9057b50aad5e074b91947.zip
PLT-2525: Render attachment fields similar to Slack
* Render attachment fields similar to Slack * Add /loadtest json url command This allows us to easily create test posts with more props like Slack attachments
Diffstat (limited to 'api/command_loadtest.go')
-rw-r--r--api/command_loadtest.go45
1 files changed, 44 insertions, 1 deletions
diff --git a/api/command_loadtest.go b/api/command_loadtest.go
index c76bc713f..63598c06e 100644
--- a/api/command_loadtest.go
+++ b/api/command_loadtest.go
@@ -49,6 +49,11 @@ var usage = `Mattermost load testing commands to help configure the system
Example:
/loadtest http://www.example.com/sample_file.md
+ Json - Add a post using the JSON file as payload to the current channel.
+ /loadtest json url
+
+ Example
+ /loadtest json http://www.example.com/sample_body.json
`
@@ -105,7 +110,9 @@ func (me *LoadTestProvider) DoCommand(c *Context, channelId string, message stri
if strings.HasPrefix(message, "url") {
return me.UrlCommand(c, channelId, message)
}
-
+ if strings.HasPrefix(message, "json") {
+ return me.JsonCommand(c, channelId, message)
+ }
return me.HelpCommand(c, channelId, message)
}
@@ -330,6 +337,42 @@ func (me *LoadTestProvider) UrlCommand(c *Context, channelId string, message str
return &model.CommandResponse{Text: "Loading data...", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
+func (me *LoadTestProvider) JsonCommand(c *Context, channelId string, message string) *model.CommandResponse {
+ url := strings.TrimSpace(strings.TrimPrefix(message, "json"))
+ if len(url) == 0 {
+ return &model.CommandResponse{Text: "Command must contain a url", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
+ }
+
+ // provide a shortcut to easily access tests stored in doc/developer/tests
+ if !strings.HasPrefix(url, "http") {
+ url = "https://raw.githubusercontent.com/mattermost/platform/master/tests/" + url
+
+ if path.Ext(url) == "" {
+ url += ".json"
+ }
+ }
+
+ var contents io.ReadCloser
+ if r, err := http.Get(url); err != nil {
+ return &model.CommandResponse{Text: "Unable to get file", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
+ } else if r.StatusCode > 400 {
+ return &model.CommandResponse{Text: "Unable to get file", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
+ } else {
+ contents = r.Body
+ }
+
+ post := model.PostFromJson(contents)
+ post.ChannelId = channelId
+ if post.Message == "" {
+ post.Message = message
+ }
+
+ if _, err := CreatePost(c, post, false); err != nil {
+ return &model.CommandResponse{Text: "Unable to create post", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
+ }
+ return &model.CommandResponse{Text: "Loading data...", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
+}
+
func parseRange(command string, cmd string) (utils.Range, bool) {
tokens := strings.Fields(strings.TrimPrefix(command, cmd))
var begin int