32 lines
550 B
Go
32 lines
550 B
Go
|
package mocks
|
||
|
|
||
|
import (
|
||
|
"snippetbox.alexedwards.net/internal/models"
|
||
|
)
|
||
|
|
||
|
type UserModel struct{}
|
||
|
|
||
|
func (m *UserModel) Insert(name, email, password string) error {
|
||
|
switch email {
|
||
|
case "dupe@example.com":
|
||
|
return models.ErrDuplicateEmail
|
||
|
default:
|
||
|
return nil
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (m *UserModel) Authenticate(email, password string) (int, error) {
|
||
|
if email == "alice@example.com" && password == "pa$$word" {
|
||
|
return 1, nil
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (m *UserModel) Exists(id int) (bool, error) {
|
||
|
switch id {
|
||
|
case 1:
|
||
|
return true, nil
|
||
|
default:
|
||
|
return false, nil
|
||
|
}
|
||
|
}
|