示例#1
0
// UserName generates user name in one of the following forms first name + last
// name, letter + last names or concatenation of from 1 to 3 lowercased words
func (s *Stabber) UserName(lang string) string {
	fake.SetLang("en")

	username := fake.UserName()

	fake.SetLang(stabberFakeLang)

	return username
}
示例#2
0
func TestSetLang(t *testing.T) {
	err := fake.SetLang("ru")
	if err != nil {
		t.Error("SetLang should successfully set lang")
	}

	err = fake.SetLang("sd")
	if err == nil {
		t.Error("SetLang with nonexistent lang should return error")
	}
}
示例#3
0
func TestProducts(t *testing.T) {
	for _, lang := range fake.GetLangs() {
		fake.SetLang(lang)

		v := fake.Brand()
		if v == "" {
			t.Errorf("Brand failed with lang %s", lang)
		}

		v = fake.ProductName()
		if v == "" {
			t.Errorf("ProductName failed with lang %s", lang)
		}

		v = fake.Product()
		if v == "" {
			t.Errorf("Product failed with lang %s", lang)
		}

		v = fake.Model()
		if v == "" {
			t.Errorf("Model failed with lang %s", lang)
		}
	}
}
示例#4
0
func main() {
	cfg := NewConfig()

	if err := cfg.Load("config.json"); err != nil {
		log.Printf("[ERROR] %+v", err)
		return
	}
	defer func() {
		if err := cfg.Save(); err != nil {
			log.Printf("[ERROR] %+v", err)
			return
		}
	}()

	if len(cfg.Ips) > 100 {
		for k, v := range cfg.Ips {
			cfg.DeleteIp(k)
			log.Printf("Delete IP %s: %s", k, v)
			break
		}
	}

	fake.SetLang("ru")
	ipParams := cfg.SetIp(fake.IPv4(), true)
	ipParams.Description = fake.FullName()
	ipParams.SetExpire(time.Now().Add(time.Minute))

	pp.Println(cfg.AllowIp("181.113.250.128"))
	pp.Println(cfg.AllowIp("89.155.206.159"))
}
示例#5
0
func TestFakerRuWithCallback(t *testing.T) {
	fake.SetLang("ru")
	fake.EnFallback(true)
	brand := fake.Brand()
	if brand == "" {
		t.Error("Fake call for name with no samples with callback should not return blank string")
	}
}
示例#6
0
func TestFakerRuWithoutCallback(t *testing.T) {
	fake.SetLang("ru")
	fake.EnFallback(false)
	brand := fake.Brand()
	if brand != "" {
		t.Error("Fake call with no samples should return blank string")
	}
}
示例#7
0
文件: geo_test.go 项目: hiroakis/fake
func TestGeo(t *testing.T) {
	for _, lang := range fake.GetLangs() {
		fake.SetLang(lang)

		f := fake.Latitute()
		if f == 0 {
			t.Errorf("Latitude failed with lang %s", lang)
		}

		i := fake.LatitudeDegress()
		if i < -180 || i > 180 {
			t.Errorf("LatitudeDegress failed with lang %s", lang)
		}

		i = fake.LatitudeMinutes()
		if i < 0 || i >= 60 {
			t.Errorf("LatitudeMinutes failed with lang %s", lang)
		}

		i = fake.LatitudeSeconds()
		if i < 0 || i >= 60 {
			t.Errorf("LatitudeSeconds failed with lang %s", lang)
		}

		s := fake.LatitudeDirection()
		if s != "N" && s != "S" {
			t.Errorf("LatitudeDirection failed with lang %s", lang)
		}

		f = fake.Longitude()
		if f == 0 {
			t.Errorf("Longitude failed with lang %s", lang)
		}

		i = fake.LongitudeDegrees()
		if i < -180 || i > 180 {
			t.Errorf("LongitudeDegrees failed with lang %s", lang)
		}

		i = fake.LongitudeMinutes()
		if i < 0 || i >= 60 {
			t.Errorf("LongitudeMinutes failed with lang %s", lang)
		}

		i = fake.LongitudeSeconds()
		if i < 0 || i >= 60 {
			t.Errorf("LongitudeSeconds failed with lang %s", lang)
		}

		s = fake.LongitudeDirection()
		if s != "W" && s != "E" {
			t.Errorf("LongitudeDirection failed with lang %s", lang)
		}
	}
}
示例#8
0
func TestAddresses(t *testing.T) {
	for _, lang := range fake.GetLangs() {
		fake.SetLang(lang)

		v := fake.Continent()
		if v == "" {
			t.Errorf("Continent failed with lang %s", lang)
		}

		v = fake.Country()
		if v == "" {
			t.Errorf("Country failed with lang %s", lang)
		}

		v = fake.City()
		if v == "" {
			t.Errorf("City failed with lang %s", lang)
		}

		v = fake.State()
		if v == "" {
			t.Errorf("State failed with lang %s", lang)
		}

		v = fake.StateAbbrev()
		if v == "" && lang == "en" {
			t.Errorf("StateAbbrev failed with lang %s", lang)
		}

		v = fake.Street()
		if v == "" {
			t.Errorf("Street failed with lang %s", lang)
		}

		v = fake.StreetAddress()
		if v == "" {
			t.Errorf("StreetAddress failed with lang %s", lang)
		}

		v = fake.Zip()
		if v == "" {
			t.Errorf("Zip failed with lang %s", lang)
		}

		v = fake.Phone()
		if v == "" {
			t.Errorf("Phone failed with lang %s", lang)
		}
	}
}
示例#9
0
func TestCurrencies(t *testing.T) {
	for _, lang := range fake.GetLangs() {
		fake.SetLang(lang)

		v := fake.Currency()
		if v == "" {
			t.Errorf("Currency failed with lang %s", lang)
		}

		v = fake.CurrencyCode()
		if v == "" {
			t.Errorf("CurrencyCode failed with lang %s", lang)
		}
	}
}
示例#10
0
func TestInternet(t *testing.T) {
	for _, lang := range fake.GetLangs() {
		fake.SetLang(lang)

		v := fake.UserName()
		if v == "" {
			t.Errorf("UserName failed with lang %s", lang)
		}

		v = fake.TopLevelDomain()
		if v == "" {
			t.Errorf("TopLevelDomain failed with lang %s", lang)
		}

		v = fake.DomainName()
		if v == "" {
			t.Errorf("DomainName failed with lang %s", lang)
		}

		v = fake.EmailAddress()
		if v == "" {
			t.Errorf("EmailAddress failed with lang %s", lang)
		}

		v = fake.EmailSubject()
		if v == "" {
			t.Errorf("EmailSubject failed with lang %s", lang)
		}

		v = fake.EmailBody()
		if v == "" {
			t.Errorf("EmailBody failed with lang %s", lang)
		}

		v = fake.DomainZone()
		if v == "" {
			t.Errorf("DomainZone failed with lang %s", lang)
		}

		v = fake.IPv4()
		if v == "" {
			t.Errorf("IPv4 failed with lang %s", lang)
		}
	}
}
示例#11
0
func TestCreditCards(t *testing.T) {
	for _, lang := range fake.GetLangs() {
		fake.SetLang(lang)

		v := fake.CreditCardType()
		if v == "" {
			t.Errorf("CreditCardType failed with lang %s", lang)
		}

		v = fake.CreditCardNum("")
		if v == "" {
			t.Errorf("CreditCardNum failed with lang %s", lang)
		}

		v = fake.CreditCardNum("visa")
		if v == "" {
			t.Errorf("CreditCardNum failed with lang %s", lang)
		}
	}
}
示例#12
0
func TestPersonal(t *testing.T) {
	for _, lang := range fake.GetLangs() {
		fake.SetLang(lang)

		v := fake.Gender()
		if v == "" {
			t.Errorf("Gender failed with lang %s", lang)
		}

		v = fake.GenderAbbrev()
		if v == "" {
			t.Errorf("GenderAbbrev failed with lang %s", lang)
		}

		v = fake.Language()
		if v == "" {
			t.Errorf("Language failed with lang %s", lang)
		}
	}
}
示例#13
0
func TestJobs(t *testing.T) {
	for _, lang := range fake.GetLangs() {
		fake.SetLang(lang)

		v := fake.Company()
		if v == "" {
			t.Errorf("Company failed with lang %s", lang)
		}

		v = fake.JobTitle()
		if v == "" {
			t.Errorf("JobTitle failed with lang %s", lang)
		}

		v = fake.Industry()
		if v == "" {
			t.Errorf("Industry failed with lang %s", lang)
		}
	}
}
示例#14
0
func TestGeneral(t *testing.T) {
	for _, lang := range fake.GetLangs() {
		fake.SetLang(lang)

		v := fake.Password(4, 10, true, true, true)
		if v == "" {
			t.Errorf("Password failed with lang %s", lang)
		}

		v = fake.SimplePassword()
		if v == "" {
			t.Errorf("SimplePassword failed with lang %s", lang)
		}

		v = fake.Color()
		if v == "" {
			t.Errorf("Color failed with lang %s", lang)
		}

		v = fake.HexColor()
		if v == "" {
			t.Errorf("HexColor failed with lang %s", lang)
		}

		v = fake.HexColorShort()
		if v == "" {
			t.Errorf("HexColorShort failed with lang %s", lang)
		}

		v = fake.DigitsN(2)
		if v == "" {
			t.Errorf("DigitsN failed with lang %s", lang)
		}

		v = fake.Digits()
		if v == "" {
			t.Errorf("Digits failed with lang %s", lang)
		}
	}
}
示例#15
0
func TestDates(t *testing.T) {
	for _, lang := range fake.GetLangs() {
		fake.SetLang(lang)

		v := fake.WeekDay()
		if v == "" {
			t.Errorf("WeekDay failed with lang %s", lang)
		}

		v = fake.WeekDayShort()
		if v == "" {
			t.Errorf("WeekDayShort failed with lang %s", lang)
		}

		n := fake.WeekdayNum()
		if n < 0 || n > 7 {
			t.Errorf("WeekdayNum failed with lang %s", lang)
		}

		v = fake.Month()
		if v == "" {
			t.Errorf("Month failed with lang %s", lang)
		}

		v = fake.MonthShort()
		if v == "" {
			t.Errorf("MonthShort failed with lang %s", lang)
		}

		n = fake.MonthNum()
		if n < 0 || n > 31 {
			t.Errorf("MonthNum failed with lang %s", lang)
		}

		n = fake.Year(1950, 2020)
		if n < 1950 || n > 2020 {
			t.Errorf("Year failed with lang %s", lang)
		}
	}
}
示例#16
0
func setLang(lang string) {
	if lang != "" && lang != stabberFakeLang {
		fake.SetLang(lang)
	}
}
示例#17
0
func TestLoremIpsum(t *testing.T) {
	for _, lang := range fake.GetLangs() {
		fake.SetLang(lang)

		v := fake.Character()
		if v == "" {
			t.Errorf("Character failed with lang %s", lang)
		}

		v = fake.CharactersN(2)
		if v == "" {
			t.Errorf("CharactersN failed with lang %s", lang)
		}

		v = fake.Characters()
		if v == "" {
			t.Errorf("Characters failed with lang %s", lang)
		}

		v = fake.Word()
		if v == "" {
			t.Errorf("Word failed with lang %s", lang)
		}

		v = fake.WordsN(2)
		if v == "" {
			t.Errorf("WordsN failed with lang %s", lang)
		}

		v = fake.Words()
		if v == "" {
			t.Errorf("Words failed with lang %s", lang)
		}

		v = fake.Title()
		if v == "" {
			t.Errorf("Title failed with lang %s", lang)
		}

		v = fake.Sentence()
		if v == "" {
			t.Errorf("Sentence failed with lang %s", lang)
		}

		v = fake.SentencesN(2)
		if v == "" {
			t.Errorf("SentencesN failed with lang %s", lang)
		}

		v = fake.Sentences()
		if v == "" {
			t.Errorf("Sentences failed with lang %s", lang)
		}

		v = fake.Paragraph()
		if v == "" {
			t.Errorf("Paragraph failed with lang %s", lang)
		}

		v = fake.ParagraphsN(2)
		if v == "" {
			t.Errorf("ParagraphsN failed with lang %s", lang)
		}

		v = fake.Paragraphs()
		if v == "" {
			t.Errorf("Paragraphs failed with lang %s", lang)
		}
	}
}
示例#18
0
func TestLoremIpsum(t *testing.T) {
	for _, lang := range fake.GetLangs() {
		fake.SetLang(lang)

		v := fake.Character()
		if v == "" {
			t.Errorf("Character failed with lang %s", lang)
		}

		v = fake.CharactersN(2)
		if v == "" {
			t.Errorf("CharactersN failed with lang %s", lang)
		}

		v = fake.Characters()
		if v == "" {
			t.Errorf("Characters failed with lang %s", lang)
		}

		v = fake.Word()
		if v == "" {
			t.Errorf("Word failed with lang %s", lang)
		}

		v = fake.WordsN(2)
		if v == "" {
			t.Errorf("WordsN failed with lang %s", lang)
		}

		v = fake.Words()
		if v == "" {
			t.Errorf("Words failed with lang %s", lang)
		}

		v = fake.Title()
		if v == "" {
			t.Errorf("Title failed with lang %s", lang)
		}

		v = fake.Sentence()
		if v == "" {
			t.Errorf("Sentence failed with lang %s", lang)
		}

		v = fake.SentencesN(2)
		if v == "" {
			t.Errorf("SentencesN failed with lang %s", lang)
		}

		v = fake.Sentences()
		if v == "" {
			t.Errorf("Sentences failed with lang %s", lang)
		}

		v = fake.Paragraph()
		if v == "" {
			t.Errorf("Paragraph failed with lang %s", lang)
		}

		v = fake.ParagraphsN(2)
		if v == "" {
			t.Errorf("ParagraphsN failed with lang %s", lang)
		}

		v = fake.Paragraphs()
		if v == "" {
			t.Errorf("Paragraphs failed with lang %s", lang)
		}

		vs := fake.WordsNUnique(251)
		if len(vs) != 251 {
			t.Errorf("WordsNUnique failed with lang %s", lang)
		}
		lw := ""
		for n, w := range vs {
			if w == lw {
				t.Errorf("Duplicate words found")
			}
			if w == "" {
				t.Errorf("Word %d is empty", n)
				continue
			}
			lw = w
		}
	}
}
示例#19
0
func TestNames(t *testing.T) {
	for _, lang := range fake.GetLangs() {
		fake.SetLang(lang)

		v := fake.MaleFirstName()
		if v == "" {
			t.Errorf("MaleFirstName failed with lang %s", lang)
		}

		v = fake.FemaleFirstName()
		if v == "" {
			t.Errorf("FemaleFirstName failed with lang %s", lang)
		}

		v = fake.FirstName()
		if v == "" {
			t.Errorf("FirstName failed with lang %s", lang)
		}

		v = fake.MaleLastName()
		if v == "" {
			t.Errorf("MaleLastName failed with lang %s", lang)
		}

		v = fake.FemaleLastName()
		if v == "" {
			t.Errorf("FemaleLastName failed with lang %s", lang)
		}

		v = fake.LastName()
		if v == "" {
			t.Errorf("LastName failed with lang %s", lang)
		}

		v = fake.MalePatronymic()
		if v == "" {
			t.Errorf("MalePatronymic failed with lang %s", lang)
		}

		v = fake.FemalePatronymic()
		if v == "" {
			t.Errorf("FemalePatronymic failed with lang %s", lang)
		}

		v = fake.Patronymic()
		if v == "" {
			t.Errorf("Patronymic failed with lang %s", lang)
		}

		v = fake.MaleFullNameWithPrefix()
		if v == "" {
			t.Errorf("MaleFullNameWithPrefix failed with lang %s", lang)
		}

		v = fake.FemaleFullNameWithPrefix()
		if v == "" {
			t.Errorf("FemaleFullNameWithPrefix failed with lang %s", lang)
		}

		v = fake.FullNameWithPrefix()
		if v == "" {
			t.Errorf("FullNameWithPrefix failed with lang %s", lang)
		}

		v = fake.MaleFullNameWithSuffix()
		if v == "" {
			t.Errorf("MaleFullNameWithSuffix failed with lang %s", lang)
		}

		v = fake.FemaleFullNameWithSuffix()
		if v == "" {
			t.Errorf("FemaleFullNameWithSuffix failed with lang %s", lang)
		}

		v = fake.FullNameWithSuffix()
		if v == "" {
			t.Errorf("FullNameWithSuffix failed with lang %s", lang)
		}

		v = fake.MaleFullName()
		if v == "" {
			t.Errorf("MaleFullName failed with lang %s", lang)
		}

		v = fake.FemaleFullName()
		if v == "" {
			t.Errorf("FemaleFullName failed with lang %s", lang)
		}

		v = fake.FullName()
		if v == "" {
			t.Errorf("FullName failed with lang %s", lang)
		}
	}
}