From d8c8a19d355fdd67a984fc696269521919bb58b5 Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Thu, 9 Aug 2018 05:26:38 -0400 Subject: avoid t.Fatal() in tests (#9189) I've been burned a few times by tests that simply fatal, requiring me to run another build to learn more about what the mismatch was. Avoid this. This is part of a long running goal of mine to make testing "better". --- cmd/mattermost/commands/roles_test.go | 4 ++-- cmd/mattermost/commands/user_test.go | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'cmd/mattermost') diff --git a/cmd/mattermost/commands/roles_test.go b/cmd/mattermost/commands/roles_test.go index 4f11ce7ed..da33a73cc 100644 --- a/cmd/mattermost/commands/roles_test.go +++ b/cmd/mattermost/commands/roles_test.go @@ -17,7 +17,7 @@ func TestAssignRole(t *testing.T) { CheckCommand(t, "roles", "system_admin", th.BasicUser.Email) if result := <-th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err != nil { - t.Fatal() + t.Fatal(result.Err) } else { user := result.Data.(*model.User) if user.Roles != "system_user system_admin" { @@ -28,7 +28,7 @@ func TestAssignRole(t *testing.T) { CheckCommand(t, "roles", "member", th.BasicUser.Email) if result := <-th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err != nil { - t.Fatal() + t.Fatal(result.Err) } else { user := result.Data.(*model.User) if user.Roles != "system_user" { diff --git a/cmd/mattermost/commands/user_test.go b/cmd/mattermost/commands/user_test.go index 69ca9ecb8..088893602 100644 --- a/cmd/mattermost/commands/user_test.go +++ b/cmd/mattermost/commands/user_test.go @@ -50,12 +50,10 @@ func TestCreateUserWithoutTeam(t *testing.T) { CheckCommand(t, "user", "create", "--email", email, "--password", "mypassword1", "--username", username) if result := <-th.App.Srv.Store.User().GetByEmail(email); result.Err != nil { - t.Fatal() + t.Fatal(result.Err) } else { user := result.Data.(*model.User) - if user.Email != email { - t.Fatal() - } + require.Equal(t, email, user.Email) } } @@ -92,7 +90,7 @@ func TestChangeUserEmail(t *testing.T) { t.Fatal("should've updated to the new email") } if result := <-th.App.Srv.Store.User().GetByEmail(newEmail); result.Err != nil { - t.Fatal() + t.Fatal(result.Err) } else { user := result.Data.(*model.User) if user.Email != newEmail { -- cgit v1.2.3-1-g7c22