From d2905342975bd1e04a53b75a9fb229af3fb82ad6 Mon Sep 17 00:00:00 2001 From: Phillip Ahereza Date: Tue, 8 Oct 2019 17:39:44 +0300 Subject: [PATCH] =?UTF-8?q?Migrate=20tests=20from=20"cmd/mattermost/comman?= =?UTF-8?q?ds/roles=5Ftest.go"=20to=E2=80=A6=20(#12421)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * migrated tests in roles_test.go to use testify * format file * format file and edit some test statements * change some require statements to assert * remove extra t.Fatal * test error on response * use require.NotEmpty --- cmd/mattermost/commands/command_test.go | 11 ++++++----- cmd/mattermost/commands/roles_test.go | 23 +++++++++-------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/cmd/mattermost/commands/command_test.go b/cmd/mattermost/commands/command_test.go index 205ff3f126..d6594cf585 100644 --- a/cmd/mattermost/commands/command_test.go +++ b/cmd/mattermost/commands/command_test.go @@ -114,16 +114,17 @@ func TestCreateCommand(t *testing.T) { t.Run(testCase.Description, func(t *testing.T) { actual, _ := th.RunCommandWithOutput(t, testCase.Args...) - cmds, _ := th.SystemAdminClient.ListCommands(team.Id, true) + cmds, response := th.SystemAdminClient.ListCommands(team.Id, true) + + require.Nil(t, response.Error, "Failed to list commands") if testCase.ExpectedErr == "" { - if len(cmds) == 0 || cmds[0].Trigger != "testcmd" { - t.Fatal("Failed to create command") - } + require.NotEmpty(t, cmds, "Failed to create command") + require.Equal(t, "testcmd", cmds[0].Trigger) assert.Contains(t, string(actual), "PASS") } else { if len(cmds) > 1 { - t.Fatal("Created command that shouldn't have been created") + require.Fail(t, "Created command that shouldn't have been created") } assert.Contains(t, string(actual), testCase.ExpectedErr) } diff --git a/cmd/mattermost/commands/roles_test.go b/cmd/mattermost/commands/roles_test.go index 4a010458d1..a727cb6563 100644 --- a/cmd/mattermost/commands/roles_test.go +++ b/cmd/mattermost/commands/roles_test.go @@ -4,6 +4,8 @@ package commands import ( + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "testing" ) @@ -13,21 +15,14 @@ func TestAssignRole(t *testing.T) { th.CheckCommand(t, "roles", "system_admin", th.BasicUser.Email) - if user, err := th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); err != nil { - t.Fatal(err) - } else { - if user.Roles != "system_user system_admin" { - t.Fatal("Got wrong roles:", user.Roles) - } - } + user, err := th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email) + require.Nil(t, err) + assert.Equal(t, "system_user system_admin", user.Roles) th.CheckCommand(t, "roles", "member", th.BasicUser.Email) - if user, err := th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); err != nil { - t.Fatal(err) - } else { - if user.Roles != "system_user" { - t.Fatal("Got wrong roles:", user.Roles, user.Id) - } - } + user, err = th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email) + require.Nil(t, err) + assert.Equal(t, "system_user", user.Roles) + }