summaryrefslogtreecommitdiffstats
path: root/api/command_test.go
diff options
context:
space:
mode:
authorhmhealey <harrisonmhealey@gmail.com>2015-11-21 12:01:14 -0500
committerhmhealey <harrisonmhealey@gmail.com>2015-11-23 13:47:47 -0500
commitfd229a50234ba8a92c8d538aecf5acd1b37f9f0b (patch)
treef9bb602d7fd5235c61228ba6dfc0de01b9b871ff /api/command_test.go
parent6ab7df3335d414ecf864972c817e3b37b3b01abf (diff)
downloadchat-fd229a50234ba8a92c8d538aecf5acd1b37f9f0b.tar.gz
chat-fd229a50234ba8a92c8d538aecf5acd1b37f9f0b.tar.bz2
chat-fd229a50234ba8a92c8d538aecf5acd1b37f9f0b.zip
Added /loadtest url command to load arbitrary files as posts
Diffstat (limited to 'api/command_test.go')
-rw-r--r--api/command_test.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/api/command_test.go b/api/command_test.go
index 476748c6b..9327850f3 100644
--- a/api/command_test.go
+++ b/api/command_test.go
@@ -10,6 +10,7 @@ import (
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/store"
+ "github.com/mattermost/platform/utils"
)
func TestSuggestRootCommands(t *testing.T) {
@@ -184,3 +185,58 @@ func TestEchoCommand(t *testing.T) {
t.Fatal("Echo command failed to send")
}
}
+
+func TestLoadTestUrlCommand(t *testing.T) {
+ Setup()
+
+ // enable testing to use /loadtest but don't save it since we don't want to overwrite config.json
+ enableTesting := utils.Cfg.ServiceSettings.EnableTesting
+ defer func() {
+ utils.Cfg.ServiceSettings.EnableTesting = enableTesting
+ }()
+
+ utils.Cfg.ServiceSettings.EnableTesting = true
+
+ team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
+ team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team)
+
+ user := &model.User{TeamId: team.Id, Email: model.NewId() + "corey@test.com", Nickname: "Corey Hulen", Password: "pwd"}
+ user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
+ store.Must(Srv.Store.User().VerifyEmail(user.Id))
+
+ Client.LoginByEmail(team.Name, user.Email, "pwd")
+
+ channel := &model.Channel{DisplayName: "AA", Name: "aa" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
+ channel = Client.Must(Client.CreateChannel(channel)).Data.(*model.Channel)
+
+ command := "/loadtest url "
+ if _, err := Client.Command(channel.Id, command, false); err == nil {
+ t.Fatal("/loadtest url with no url should've failed")
+ }
+
+ command = "/loadtest url http://www.hopefullynonexistent.file/path/asdf/qwerty"
+ if _, err := Client.Command(channel.Id, command, false); err == nil {
+ t.Fatal("/loadtest url with invalid url should've failed")
+ }
+
+ command = "/loadtest url https://raw.githubusercontent.com/mattermost/platform/master/README.md"
+ if r := Client.Must(Client.Command(channel.Id, command, false)).Data.(*model.Command); r.Response != model.RESP_EXECUTED {
+ t.Fatal("/loadtest url for README.md should've executed")
+ }
+
+ command = "/loadtest url test-emoticons.md"
+ if r := Client.Must(Client.Command(channel.Id, command, false)).Data.(*model.Command); r.Response != model.RESP_EXECUTED {
+ t.Fatal("/loadtest url for test-emoticons.md should've executed")
+ }
+
+ command = "/loadtest url test-emoticons"
+ if r := Client.Must(Client.Command(channel.Id, command, false)).Data.(*model.Command); r.Response != model.RESP_EXECUTED {
+ t.Fatal("/loadtest url for test-emoticons should've executed")
+ }
+
+ posts := Client.Must(Client.GetPosts(channel.Id, 0, 5, "")).Data.(*model.PostList)
+ // note that this may make more than 3 posts if files are too long to fit in an individual post
+ if len(posts.Order) < 3 {
+ t.Fatal("/loadtest url made too few posts, perhaps there needs to be a delay before GetPosts in the test?")
+ }
+}