mirror of
https://github.com/CPunch/gopenfusion.git
synced 2025-10-13 04:40:10 +00:00
use proper errors for db.Err
- switch to using errors.Is where applicable
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
"log"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
@@ -44,8 +44,8 @@ func (db *DBHandler) NewAccount(Login, Password string) (*Account, error) {
|
||||
}
|
||||
|
||||
var (
|
||||
ErrLoginInvalidID = fmt.Errorf("invalid Login ID")
|
||||
ErrLoginInvalidPassword = fmt.Errorf("invalid ID && Password combo")
|
||||
ErrLoginInvalidID = errors.New("invalid Login ID")
|
||||
ErrLoginInvalidPassword = errors.New("invalid ID && Password combo")
|
||||
)
|
||||
|
||||
func (db *DBHandler) TryLogin(Login, Password string) (*Account, error) {
|
||||
|
@@ -2,6 +2,7 @@ package db_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
@@ -50,7 +51,7 @@ func TestDBAccount(t *testing.T) {
|
||||
t.Error("account username is not test")
|
||||
}
|
||||
|
||||
if _, err = testDB.TryLogin("test", "wrongpassword"); err != db.ErrLoginInvalidPassword {
|
||||
if _, err = testDB.TryLogin("test", "wrongpassword"); !errors.Is(err, db.ErrLoginInvalidPassword) {
|
||||
t.Error("expected ErrLoginInvalidPassword")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user