Skip to content

Commit

Permalink
added message to unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdedman committed Apr 13, 2024
1 parent 98229d2 commit 1433ca4
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions internal/utils/encryption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@ var user = &models.User{
*/
func TestHashPasswordNoError(t *testing.T) {
err := utils.HashPassword(user)
assert.NoError(t, err)
assert.NoError(t, err, "No error while hashing password")
}

func TestHashPasswordNil(t *testing.T) {
err := utils.HashPassword(user)
assert.Nil(t, err)
assert.Nil(t, err, "Err should be nil")
}

/*
* Test cases for the VerifyPassword function
*/
func TestVerifyPasswordNoError(t *testing.T) {
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(user.Password), bcrypt.DefaultCost)
assert.NoError(t, err)
assert.NoError(t, err, "No error while hashing password")

err = utils.VerifyPassword(user.Password, string(hashedPassword))
assert.NoError(t, err)
assert.NoError(t, err, "No error while verifying password")
}

func TestVerifyPasswordError(t *testing.T) {
hashedPassword, err := bcrypt.GenerateFromPassword([]byte("password1"), bcrypt.DefaultCost)
assert.NoError(t, err)
assert.NoError(t, err, "No error while hashing password")

err = utils.VerifyPassword(user.Password, string(hashedPassword))
assert.Error(t, err)
assert.Error(t, err, "Error while verifying password")
}

0 comments on commit 1433ca4

Please sign in to comment.