Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
constructor provider make public (#13)
Browse files Browse the repository at this point in the history
* Test coverage up
add tests for coverage up

* errors in variables

* return variable in start function

* add internet fake

* refactoring code

* credit cart refactoring
add new type and new file for credit cart

* add test internet
and add helpers function, which check slice string type to has element

* coverage up test internet file

* add payment and add test
done concept

* typo fix

* fix variable internet in struct Internet

* fix

* delete old code

* change init mutex

* merge

* add phone provider and test

* change format in stdout structure

* change format in stdout structure test

* add TollFreePhoneNumber function

* add e_164_phone_number

* fix test

* fix and done phone provider

* test coverage up

* create new provider Person
add TitleMale

* add FirstNameMale

* add FirstNameFemale

* typo fix

* add last name

* add name

* typo fix

* coverage up

* add unix time

* add date and time

* add month

* add year

* add day of week

* add day of month

* add timestamp format

* add century

* add TimeZone

* add time period

* update readme

* add password in provider internet

* add lorem provider
and add word

* add Sentence

* add sentences

* update read me

* fix import package slice

* changed the constructors hidden for available
  • Loading branch information
agoalofalife authored Oct 31, 2017
1 parent 1936f93 commit c672223
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 77 deletions.
2 changes: 1 addition & 1 deletion address.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
var address Addresser

// Constructor
func getAddress() Addresser {
func GetAddress() Addresser {
mu.Lock()
defer mu.Unlock()

Expand Down
2 changes: 1 addition & 1 deletion datetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ type DateTimer interface {

var date DateTimer

func getDateTimer() DateTimer {
func GetDateTimer() DateTimer {
mu.Lock()
defer mu.Unlock()

Expand Down
24 changes: 12 additions & 12 deletions datetime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestSetDateTimer(t *testing.T) {
}

func TestUnixTimeValueValid(t *testing.T) {
d := getDateTimer()
d := GetDateTimer()
var ref = struct {
some int64
}{
Expand All @@ -27,7 +27,7 @@ func TestUnixTimeValueValid(t *testing.T) {
}
}
func TestUnixTimeValueNotValid(t *testing.T) {
d := getDateTimer()
d := GetDateTimer()
var ref = struct {
some int
}{
Expand All @@ -41,7 +41,7 @@ func TestUnixTimeValueNotValid(t *testing.T) {
}

func TestDate(t *testing.T) {
d := getDateTimer()
d := GetDateTimer()
_, err := time.Parse(BaseDate, d.Date())

if err != nil {
Expand All @@ -50,7 +50,7 @@ func TestDate(t *testing.T) {
}

func TestTime(t *testing.T) {
d := getDateTimer()
d := GetDateTimer()
_, err := time.Parse(Time, d.Time())

if err != nil {
Expand All @@ -59,62 +59,62 @@ func TestTime(t *testing.T) {
}

func TestMonthName(t *testing.T) {
d := getDateTimer()
d := GetDateTimer()
_, err := time.Parse(Month, d.MonthName())
if err != nil {
t.Error("function Month need return valid month")
}
}

func TestYear(t *testing.T) {
d := getDateTimer()
d := GetDateTimer()
_, err := time.Parse(Year, d.Year())
if err != nil {
t.Error("function Year need return valid year")
}
}

func TestDayOfWeek(t *testing.T) {
d := getDateTimer()
d := GetDateTimer()
_, err := time.Parse(Day, d.DayOfWeek())
if err != nil {
t.Error("function DayOfWeek need return valid day")
}
}

func TestDayOfMonth(t *testing.T) {
d := getDateTimer()
d := GetDateTimer()
_, err := time.Parse(DayOfMonth, d.DayOfMonth())
if err != nil {
t.Error("function DayOfMonth need return valid digit")
}
}

func TestTimestamp(t *testing.T) {
d := getDateTimer()
d := GetDateTimer()
_, err := time.Parse(fmt.Sprintf("%s %s", BaseDate, Time), d.Timestamp())
if err != nil {
t.Error("function Timestamp need return valid timestamp format")
}
}

func TestCentury(t *testing.T) {
d := getDateTimer()
d := GetDateTimer()

if !slice.Contains(century, d.Century()) {
t.Error("Expected century from functuon Century")
}
}

func TestTimeZone(t *testing.T) {
d := getDateTimer()
d := GetDateTimer()
if !slice.Contains(timezones, d.TimeZone()) {
t.Error("Expected timezone from variable timezones")
}
}

func TestTimePeriod(t *testing.T) {
d := getDateTimer()
d := GetDateTimer()
_, err := time.Parse(TimePeriod, d.TimePeriod())
if err != nil {
t.Error("function TimePeriod need return valid period")
Expand Down
71 changes: 36 additions & 35 deletions faker.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,41 +58,41 @@ const (
)

var mapperTag = map[string]interface{}{
Email: getNetworker().Email,
MacAddress: getNetworker().MacAddress,
DomainName: getNetworker().DomainName,
Url: getNetworker().Url,
UserName: getNetworker().UserName,
IPV4: getNetworker().Ipv4,
IPV6: getNetworker().Ipv6,
PASSWORD: getNetworker().Password,
CREDIT_CARD_TYPE: getPayment().CreditCardType,
CREDIT_CARD_NUMBER: getPayment().CreditCardNumber,
LATITUDE: getAddress().Latitude,
LONGITUDE: getAddress().Longitude,
PHONE_NUMBER: getPhoner().PhoneNumber,
TOLL_FREE_NUMBER: getPhoner().TollFreePhoneNumber,
E164_PHONE_NUMBER: getPhoner().E164PhoneNumber,
TITLE_MALE: getPerson().TitleMale,
TITLE_FEMALE: getPerson().TitleFeMale,
FIRST_NAME_MALE: getPerson().FirstNameMale,
FIRST_NAME_FEMALE: getPerson().FirstNameFemale,
LAST_NAME: getPerson().LastName,
NAME: getPerson().Name,
UNIX_TIME: getDateTimer().UnixTime,
DATE: getDateTimer().Date,
TIME: getDateTimer().Time,
MONTH_NAME: getDateTimer().MonthName,
YEAR: getDateTimer().Year,
DAY_OF_WEEK: getDateTimer().DayOfWeek,
DAY_OF_MONTH: getDateTimer().DayOfMonth,
TIMESTAMP: getDateTimer().Timestamp,
CENTURY: getDateTimer().Century,
TIMEZONE: getDateTimer().TimeZone,
TIME_PERIOD: getDateTimer().TimePeriod,
WORD: getLorem().Word,
SENTENCE: getLorem().Sentence,
SENTENCES: getLorem().Sentences,
Email: GetNetworker().Email,
MacAddress: GetNetworker().MacAddress,
DomainName: GetNetworker().DomainName,
Url: GetNetworker().Url,
UserName: GetNetworker().UserName,
IPV4: GetNetworker().Ipv4,
IPV6: GetNetworker().Ipv6,
PASSWORD: GetNetworker().Password,
CREDIT_CARD_TYPE: GetPayment().CreditCardType,
CREDIT_CARD_NUMBER: GetPayment().CreditCardNumber,
LATITUDE: GetAddress().Latitude,
LONGITUDE: GetAddress().Longitude,
PHONE_NUMBER: GetPhoner().PhoneNumber,
TOLL_FREE_NUMBER: GetPhoner().TollFreePhoneNumber,
E164_PHONE_NUMBER: GetPhoner().E164PhoneNumber,
TITLE_MALE: GetPerson().TitleMale,
TITLE_FEMALE: GetPerson().TitleFeMale,
FIRST_NAME_MALE: GetPerson().FirstNameMale,
FIRST_NAME_FEMALE: GetPerson().FirstNameFemale,
LAST_NAME: GetPerson().LastName,
NAME: GetPerson().Name,
UNIX_TIME: GetDateTimer().UnixTime,
DATE: GetDateTimer().Date,
TIME: GetDateTimer().Time,
MONTH_NAME: GetDateTimer().MonthName,
YEAR: GetDateTimer().Year,
DAY_OF_WEEK: GetDateTimer().DayOfWeek,
DAY_OF_MONTH: GetDateTimer().DayOfMonth,
TIMESTAMP: GetDateTimer().Timestamp,
CENTURY: GetDateTimer().Century,
TIMEZONE: GetDateTimer().TimeZone,
TIME_PERIOD: GetDateTimer().TimePeriod,
WORD: GetLorem().Word,
SENTENCE: GetLorem().Sentence,
SENTENCES: GetLorem().Sentences,
}

// Error when get fake from ptr
Expand Down Expand Up @@ -325,6 +325,7 @@ func randomStringNumber(n int) string {
/ Get three parameters , only first mandatory and the rest are optional
/ --- If only set one parameter : This means the minimum number of digits and the total number
/ --- If only set two parameters : First this is min digit and second max digit and the total number the difference between them
/ --- If only three parameters: the third argument set Max count Digit
*/
func RandomInt(parameters ...int) (p []int, err error) {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
Expand Down
2 changes: 1 addition & 1 deletion internet.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var urlFormats = []string{
var internet Networker

// Constructor
func getNetworker() Networker {
func GetNetworker() Networker {
mu.Lock()
defer mu.Unlock()

Expand Down
16 changes: 8 additions & 8 deletions internet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func TestEmail(t *testing.T) {
if !strings.Contains(getNetworker().Email(), "@") {
if !strings.Contains(GetNetworker().Email(), "@") {
t.Error("Expected email")
}
}
Expand All @@ -19,7 +19,7 @@ func TestMacAddress(t *testing.T) {
}
}
func TestDomainName(t *testing.T) {
preTld := strings.Split(getNetworker().DomainName(), ".")
preTld := strings.Split(GetNetworker().DomainName(), ".")

if !slice.Contains(tld, preTld[1]) {
t.Error("Expected get DomainName")
Expand All @@ -29,31 +29,31 @@ func TestUrlOneVerbs(t *testing.T) {
urlFormats = []string{
"http://www.%s/"}

if !strings.Contains(getNetworker().Url(), "http") {
if !strings.Contains(GetNetworker().Url(), "http") {
t.Error("Expected get url")
}
}
func TestUrlTwoVerbs(t *testing.T) {
urlFormats = []string{
"http://www.%s/%s"}

if !strings.Contains(getNetworker().Url(), "http") {
if !strings.Contains(GetNetworker().Url(), "http") {
t.Error("Expected get url")
}
}
func TestUserName(t *testing.T) {
if getNetworker().UserName() == "" {
if GetNetworker().UserName() == "" {
t.Error("Expected get username")
}

}
func TestIpv4(t *testing.T) {
if strings.Count(getNetworker().Ipv4(), ".") != 3 {
if strings.Count(GetNetworker().Ipv4(), ".") != 3 {
t.Error("Expected Ipv4 format")
}
}
func TestIpv6(t *testing.T) {
if strings.Count(getNetworker().Ipv6(), ":") != 7 {
if strings.Count(GetNetworker().Ipv6(), ":") != 7 {
t.Error("Expected Ipv4 format")
}
}
Expand All @@ -62,7 +62,7 @@ func TestSetNetwork(t *testing.T) {
}

func TestPassword(t *testing.T) {
if getNetworker().Password() == "" {
if GetNetworker().Password() == "" {
t.Error("Expected hash password")
}
}
2 changes: 1 addition & 1 deletion lorem.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func SetDataFaker(d DataFaker) {
}

// Constructor
func getLorem() DataFaker {
func GetLorem() DataFaker {
mu.Lock()
defer mu.Unlock()

Expand Down
6 changes: 3 additions & 3 deletions lorem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ func TestDataFaker(t *testing.T) {
}

func TestWord(t *testing.T) {
if !slice.Contains(wordList, getLorem().Word()) {
if !slice.Contains(wordList, GetLorem().Word()) {
t.Error("Expected word from slice wordList")
}
}

func TestSentence(t *testing.T) {
s := getLorem().Sentence()
s := GetLorem().Sentence()
if s == "" || !strings.HasSuffix(s, ".") {
t.Error("Expected sentence")
}
}

func TestSentences(t *testing.T) {
s := getLorem().Sentences()
s := GetLorem().Sentences()
if s == "" || !strings.HasSuffix(s, ".") {
t.Error("Expected sentences")
}
Expand Down
2 changes: 1 addition & 1 deletion payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var pay Render
var cacheCreditCard string

// Constructor
func getPayment() Render {
func GetPayment() Render {
mu.Lock()
defer mu.Unlock()

Expand Down
4 changes: 2 additions & 2 deletions payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
)

func TestCreditCardType(t *testing.T) {
randCC := strings.ToLower(getPayment().CreditCardType())
randCC := strings.ToLower(GetPayment().CreditCardType())
if _, exist := creditCards[randCC]; !exist {
t.Errorf("Expected from function creditCardType() : %s", randCC)
}
}

func TestCreditCardNumber(t *testing.T) {
getPayment().CreditCardNumber()
GetPayment().CreditCardNumber()
}

func TestSetPayment(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion person.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ var lastNames = []string{
}
var randNameFlag = rand.Intn(100)

func getPerson() Dowser {
func GetPerson() Dowser {
mu.Lock()
defer mu.Unlock()

Expand Down
Loading

0 comments on commit c672223

Please sign in to comment.