🚚 Renamed NewEmail to ParseEmail
This commit is contained in:
parent
7cb23125c8
commit
2cc1fa02e7
|
@ -3,6 +3,8 @@ package domain
|
|||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
type Email struct {
|
||||
|
@ -13,9 +15,12 @@ type Email struct {
|
|||
var ErrEmailInvalid error = Error{
|
||||
Code: ErrorCodeInvalidRequest,
|
||||
Description: "cannot parse email",
|
||||
URI: "",
|
||||
State: "",
|
||||
frame: xerrors.Caller(1),
|
||||
}
|
||||
|
||||
func NewEmail(src string) (*Email, error) {
|
||||
func ParseEmail(src string) (*Email, error) {
|
||||
parts := strings.Split(strings.TrimPrefix(src, "mailto:"), "@")
|
||||
if len(parts) != 2 { //nolint: gomnd
|
||||
return nil, ErrEmailInvalid
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"source.toby3d.me/website/indieauth/internal/domain"
|
||||
)
|
||||
|
||||
func TestNewEmail(t *testing.T) {
|
||||
func TestParseEmail(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
for _, testCase := range []struct {
|
||||
|
@ -37,7 +37,7 @@ func TestNewEmail(t *testing.T) {
|
|||
t.Run(testCase.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
result, err := domain.NewEmail(testCase.input)
|
||||
result, err := domain.ParseEmail(testCase.input)
|
||||
if testCase.expError {
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, result)
|
||||
|
|
|
@ -133,7 +133,7 @@ func extractProfile(dst *domain.Profile, src *http.Response) {
|
|||
continue
|
||||
}
|
||||
|
||||
e, err := domain.NewEmail(email)
|
||||
e, err := domain.ParseEmail(email)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue