Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
brianvoe committed May 7, 2024
2 parents c4255fd + 7fec78a commit 9d25135
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
4 changes: 2 additions & 2 deletions json.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func addFileJSONLookup() {
// encoding/json.RawMessage is a special case of []byte
// it cannot be handled as a reflect.Array/reflect.Slice
// because it needs additional structure in the output
func rJsonRawMessage(f *Faker, t reflect.Type, v reflect.Value, tag string, size int) error {
func rJsonRawMessage(f *Faker, v reflect.Value) error {
b, err := f.JSON(nil)
if err != nil {
return err
Expand All @@ -268,7 +268,7 @@ func rJsonRawMessage(f *Faker, t reflect.Type, v reflect.Value, tag string, size
// that represents a JSON number literal.
// It cannot be handled as a string because it needs to
// represent an integer or a floating-point number.
func rJsonNumber(f *Faker, t reflect.Type, v reflect.Value, tag string, size int) error {
func rJsonNumber(f *Faker, v reflect.Value, tag string) error {
var ret json.Number

var numberType string
Expand Down
7 changes: 6 additions & 1 deletion lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ func (i *Info) GetAny(m *MapParams, field string) (any, error) {
return nil, err
}

// Make sure value[0] exists
if len(value) == 0 {
return nil, fmt.Errorf("could not find field: %s", field)
}

var anyValue any

// Try to convert to int
Expand Down Expand Up @@ -333,7 +338,7 @@ func (i *Info) GetField(m *MapParams, field string) (*Param, []string, error) {
}

return p, value, nil
} else if m == nil && p.Default != "" {
} else if p.Default != "" {
// If p.Type is []uint, then we need to convert it to []string
if strings.HasPrefix(p.Default, "[") {
// Remove [] from type
Expand Down
12 changes: 6 additions & 6 deletions struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ func r(f *Faker, t reflect.Type, v reflect.Value, tag string, size int) error {

switch t.Name() {
case "RawMessage":
return rJsonRawMessage(f, t, v, tag, size)
return rJsonRawMessage(f, v)
case "Number":
return rJsonNumber(f, t, v, tag, size)
return rJsonNumber(f, v, tag)
default:
return errors.New("unknown encoding/json type: " + t.Name())
}
Expand Down Expand Up @@ -72,7 +72,7 @@ func r(f *Faker, t reflect.Type, v reflect.Value, tag string, size int) error {
return nil
}

func rCustom(f *Faker, t reflect.Type, v reflect.Value, tag string) error {
func rCustom(f *Faker, v reflect.Value, tag string) error {
// If tag is empty return error
if tag == "" {
return errors.New("tag is empty")
Expand Down Expand Up @@ -126,7 +126,7 @@ func rCustom(f *Faker, t reflect.Type, v reflect.Value, tag string) error {
func rStruct(f *Faker, t reflect.Type, v reflect.Value, tag string) error {
// Check if tag exists, if so run custom function
if t.Name() != "" && tag != "" {
return rCustom(f, t, v, tag)
return rCustom(f, v, tag)
}

// Check if struct is fakeable
Expand Down Expand Up @@ -252,7 +252,7 @@ func rSlice(f *Faker, t reflect.Type, v reflect.Value, tag string, size int) err
// Check if tag exists, if so run custom function
if t.Name() != "" && tag != "" {
// Check to see if custom function works if not continue to normal loop of values
err := rCustom(f, t, v, tag)
err := rCustom(f, v, tag)
if err == nil {
return nil
}
Expand Down Expand Up @@ -308,7 +308,7 @@ func rMap(f *Faker, t reflect.Type, v reflect.Value, tag string, size int) error

// Check if tag exists, if so run custom function
if tag != "" {
return rCustom(f, t, v, tag)
return rCustom(f, v, tag)
} else if size > 0 {
// NOOP
} else if isFakeable(t) {
Expand Down
12 changes: 6 additions & 6 deletions time.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ func date(f *Faker) time.Time {
return time.Date(year(f), time.Month(month(f)), day(f), hour(f), minute(f), second(f), nanoSecond(f), time.UTC)
}

// FutureDate will generate a random past time.Time struct
// PastDate will generate a random past time.Time struct
func PastDate() time.Time { return pastDate(GlobalFaker) }

// FutureDate will generate a random past time.Time struct
// PastDate will generate a random past time.Time struct
func (f *Faker) PastDate() time.Time { return pastDate(f) }

func pastDate(f *Faker) time.Time {
Expand Down Expand Up @@ -322,8 +322,8 @@ func addDateTimeLookup() {
},
})

AddFuncLookup("pasttime", Info{
Display: "PastTime",
AddFuncLookup("pastdate", Info{
Display: "PastDate",
Category: "time",
Description: "Date that has occurred before the current moment in time",
Example: "2007-01-24 13:00:35.820738079 +0000 UTC",
Expand All @@ -333,8 +333,8 @@ func addDateTimeLookup() {
},
})

AddFuncLookup("futuretime", Info{
Display: "FutureTime",
AddFuncLookup("futuredate", Info{
Display: "FutureDate",
Category: "time",
Description: "Date that has occurred after the current moment in time",
Example: "2107-01-24 13:00:35.820738079 +0000 UTC",
Expand Down

0 comments on commit 9d25135

Please sign in to comment.