Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for fake.MonthNum #117

Merged
merged 1 commit into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ Quick overview of the path syntax available to extract values form the request:
- fake.Language
- fake.Model
- fake.Month
- fake.MonthShort
- fake.MonthNum
- fake.Year
- fake.Paragraph
- fake.Paragraphs
Expand Down
1 change: 1 addition & 0 deletions pkg/vars/fake/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Generator interface {
Month() string
Year() string
MonthShort() string
MonthNum() string
Paragraph() string
Paragraphs() string
ParagraphsN(n int) string
Expand Down
5 changes: 5 additions & 0 deletions pkg/vars/fake/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ func (p Provider) MonthShort() string {
return fake.MonthShort()
}

//MonthNum returns a random month (Numeric Version)
func (p Provider) MonthNum() string {
return strconv.Itoa(fake.MonthNum())
}

//WeekDay returns a random day of week
func (p Provider) WeekDay() string {
return fake.WeekDay()
Expand Down
17 changes: 17 additions & 0 deletions pkg/vars/fake/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,20 @@ func TestHex(t *testing.T) {
}
}
}

func TestMonthNum(t *testing.T) {
faker := Provider{}

for i := 1; i < 10000; i++ {
result := faker.MonthNum()
month, err := strconv.ParseInt(result, 10, 64)

if err != nil {
t.Error("The result should be a valid month number", result)
}

if month < 0 || month > 12 {
t.Error("The random number should be between 0 and 12", month)
}
}
}