-
Notifications
You must be signed in to change notification settings - Fork 733
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The validation doesn't apply to already created usernames. This should close #925
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
package validator // import "miniflux.app/v2/internal/validator" | ||
|
||
import "testing" | ||
import "miniflux.app/v2/internal/locale" | ||
|
||
func TestIsValidURL(t *testing.T) { | ||
scenarios := map[string]bool{ | ||
|
@@ -77,3 +78,25 @@ func TestIsValidDomain(t *testing.T) { | |
} | ||
} | ||
} | ||
|
||
func TestValidateUsername(t *testing.T) { | ||
scenarios := map[string]*locale.LocalizedError{ | ||
"jvoisin": nil, | ||
"j.voisin": nil, | ||
"[email protected]": nil, | ||
"invalid username": locale.NewLocalizedError("error.invalid_username"), | ||
} | ||
|
||
for username, expected := range scenarios { | ||
result := validateUsername(username) | ||
if expected == nil { | ||
if result != nil { | ||
t.Errorf(`got an unexpected error for %q instead of nil: %v`, username, result) | ||
} | ||
} else { | ||
if result == nil { | ||
t.Errorf(`expected an error, got nil.`) | ||
} | ||
} | ||
} | ||
} |