namecheck/twitter/twitter_test.go

116 lines
2.7 KiB
Go

package twitter
import "testing"
func TestContainsOnlyLegalChars(t *testing.T) {
goodUsername := "cadoles"
badUsername := "cadoles!"
if !containsOnlyLegalChars(goodUsername) {
t.Errorf("The user is valid but containsOnlyLegalChars says it's not")
}
if containsOnlyLegalChars(badUsername) {
t.Errorf("The user is bad but containsOnlyLegalChars says it's OK")
}
}
func TestContainsNoIllegalPattern(t *testing.T) {
goodUsername := "puppetmaster"
if !containsNoIllegalPattern(goodUsername) {
t.Errorf("The username is valid but containsNoIllegalPattern says it's not")
}
badUsername := "twitterPuppetMaster"
if containsNoIllegalPattern(badUsername) {
t.Errorf("The username is bad but containsNoIllegalPattern says it's OK")
}
}
func TestIsLongEnough(t *testing.T) {
goodUsername := "cadoles_test"
if !isLongEnough(goodUsername) {
t.Errorf("The username is long enough but isLongEnough says it's not")
}
badUsername := ""
if isLongEnough(badUsername) {
t.Errorf("The username is not long enought but isLongEnough says it's OK")
}
}
func TestIsShortEnough(t *testing.T) {
goodUsername := "cadoles_test"
if !isShortEnough(goodUsername) {
t.Errorf("The username is short enough but isShortEnough says it's not !")
}
badUsername := "cadoles_cadoles_cadoles_cadoles_cadoles"
if isShortEnough(badUsername) {
t.Errorf("The username is not short enough but isShortEnough says it's OK !")
}
}
func TestIsValid(t *testing.T) {
var tw Twitter
goodUsername := "cadoles"
if !tw.IsValid(goodUsername) {
t.Errorf("The username is valid and isValid says it's not !")
}
}
func TestIsToShort(t *testing.T) {
var tw Twitter
toShort := ""
if tw.IsValid(toShort) {
t.Errorf("The is to short but isValid says it's OK !")
}
}
func TestIsToLong(t *testing.T) {
var tw Twitter
toLong := "cadoles_cadoles_cadoles_cadoles_cadoles_cadoles"
if tw.IsValid(toLong) {
t.Errorf("The username is to long but isValid says it's OK !")
}
}
func TestContainsBadPattern(t *testing.T) {
var tw Twitter
twitterBad := "twittercadoles"
if tw.IsValid(twitterBad) {
t.Errorf("The username contains twitter but isValid says it's OK !")
}
}
func TestTakenUsername(t *testing.T) {
var tw Twitter
username := "puppetmaster"
res, err := tw.IsAvailable(username)
if err == nil {
t.Errorf("The user is supposed to be taken ! [%s]", err)
}
if res {
t.Errorf("The user is not supposed to be available !")
}
}
func TestFreeUsername(t *testing.T) {
var tw Twitter
username := "caseiro23"
res, err := tw.IsAvailable(username)
if err != nil {
t.Errorf("The user is supposed to be free ! [%s]", err)
}
if res == false {
t.Errorf("The user is supposed to be available !")
}
}