fix: use testify for assertions
All checks were successful
Build Docker Image / Explore-Gitea-Actions (push) Successful in 50s

This commit is contained in:
2024-10-05 12:58:34 +02:00
parent d6c1f28b36
commit 7a17820238

View File

@@ -10,6 +10,7 @@ import (
"time" "time"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/stretchr/testify/assert"
) )
func TestSignIn(t *testing.T) { func TestSignIn(t *testing.T) {
@@ -35,18 +36,15 @@ func TestSignIn(t *testing.T) {
underTest := NewServiceAuthImpl(mockDbAuth, &types.ServerSettings{}) underTest := NewServiceAuthImpl(mockDbAuth, &types.ServerSettings{})
actualUser, err := underTest.SignIn(user.Email, "password") actualUser, err := underTest.SignIn(user.Email, "password")
if err != nil { assert.Nil(t, err)
t.Errorf("Expected nil, got %v", err)
}
expectedUser := User{ expectedUser := User{
Id: user.Id, Id: user.Id,
Email: user.Email, Email: user.Email,
EmailVerified: user.EmailVerified, EmailVerified: user.EmailVerified,
} }
if *actualUser != expectedUser {
t.Errorf("Expected %v, got %v", expectedUser, actualUser) assert.Equal(t, expectedUser, *actualUser)
}
}) })
t.Run("should return ErrInvalidCretentials if password is not correct", func(t *testing.T) { t.Run("should return ErrInvalidCretentials if password is not correct", func(t *testing.T) {
@@ -71,9 +69,8 @@ func TestSignIn(t *testing.T) {
underTest := NewServiceAuthImpl(mockDbAuth, &types.ServerSettings{}) underTest := NewServiceAuthImpl(mockDbAuth, &types.ServerSettings{})
_, err := underTest.SignIn("test@test.de", "wrong password") _, err := underTest.SignIn("test@test.de", "wrong password")
if err != ErrInvaidCredentials {
t.Errorf("Expected %v, got %v", ErrInvaidCredentials, err) assert.Equal(t, ErrInvaidCredentials, err)
}
}) })
t.Run("should return ErrInvalidCretentials if user has not been found", func(t *testing.T) { t.Run("should return ErrInvalidCretentials if user has not been found", func(t *testing.T) {
t.Parallel() t.Parallel()
@@ -84,21 +81,18 @@ func TestSignIn(t *testing.T) {
underTest := NewServiceAuthImpl(mockDbAuth, &types.ServerSettings{}) underTest := NewServiceAuthImpl(mockDbAuth, &types.ServerSettings{})
_, err := underTest.SignIn("test", "test") _, err := underTest.SignIn("test", "test")
if err != ErrInvaidCredentials { assert.Equal(t, ErrInvaidCredentials, err)
t.Errorf("Expected %v, got %v", ErrInvaidCredentials, err)
}
}) })
t.Run("should forward ErrInternal on any other error", func(t *testing.T) { t.Run("should forward ErrInternal on any other error", func(t *testing.T) {
t.Parallel() t.Parallel()
mockDbAuth := mocks.NewMockDbAuth(t) mockDbAuth := mocks.NewMockDbAuth(t)
mockDbAuth.EXPECT().GetUser("test").Return(nil, errors.New("Some error")) mockDbAuth.EXPECT().GetUser("test").Return(nil, errors.New("Some undefined error"))
underTest := NewServiceAuthImpl(mockDbAuth, &types.ServerSettings{}) underTest := NewServiceAuthImpl(mockDbAuth, &types.ServerSettings{})
_, err := underTest.SignIn("test", "test") _, err := underTest.SignIn("test", "test")
if err != types.ErrInternal {
t.Errorf("Expected %v, got %v", types.ErrInternal, err) assert.Equal(t, types.ErrInternal, err)
}
}) })
} }