Migrate tests from "cmd/mattermost/commands/roles_test.go" to… (#12421)

* 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
Этот коммит содержится в:
Phillip Ahereza
2019-10-08 17:39:44 +03:00
коммит произвёл jfrerich
родитель 894b124bc6
Коммит d290534297
2 изменённых файлов: 15 добавлений и 19 удалений

Просмотреть файл

@@ -114,16 +114,17 @@ func TestCreateCommand(t *testing.T) {
t.Run(testCase.Description, func(t *testing.T) { t.Run(testCase.Description, func(t *testing.T) {
actual, _ := th.RunCommandWithOutput(t, testCase.Args...) 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 testCase.ExpectedErr == "" {
if len(cmds) == 0 || cmds[0].Trigger != "testcmd" { require.NotEmpty(t, cmds, "Failed to create command")
t.Fatal("Failed to create command") require.Equal(t, "testcmd", cmds[0].Trigger)
}
assert.Contains(t, string(actual), "PASS") assert.Contains(t, string(actual), "PASS")
} else { } else {
if len(cmds) > 1 { 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) assert.Contains(t, string(actual), testCase.ExpectedErr)
} }

Просмотреть файл

@@ -4,6 +4,8 @@
package commands package commands
import ( import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing" "testing"
) )
@@ -13,21 +15,14 @@ func TestAssignRole(t *testing.T) {
th.CheckCommand(t, "roles", "system_admin", th.BasicUser.Email) th.CheckCommand(t, "roles", "system_admin", th.BasicUser.Email)
if user, err := th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); err != nil { user, err := th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email)
t.Fatal(err) require.Nil(t, err)
} else { assert.Equal(t, "system_user system_admin", user.Roles)
if user.Roles != "system_user system_admin" {
t.Fatal("Got wrong roles:", user.Roles)
}
}
th.CheckCommand(t, "roles", "member", th.BasicUser.Email) th.CheckCommand(t, "roles", "member", th.BasicUser.Email)
if user, err := th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); err != nil { user, err = th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email)
t.Fatal(err) require.Nil(t, err)
} else { assert.Equal(t, "system_user", user.Roles)
if user.Roles != "system_user" {
t.Fatal("Got wrong roles:", user.Roles, user.Id)
}
}
} }