Skip to content

Commit

Permalink
add support for fork.MonthNum (#117)
Browse files Browse the repository at this point in the history
Co-authored-by: Geoffrey GREBERT <ggrebert@sii.fr>
  • Loading branch information
ggrebert and sii-ggrebert committed Nov 26, 2020
1 parent 7a65596 commit 8e50ca9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
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)
}
}
}

0 comments on commit 8e50ca9

Please sign in to comment.