Skip to content

Commit

Permalink
Merge branch 'ceshihao/fix_random_time_issue_in_test' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
aarondl committed Jul 16, 2018
2 parents 9efaa8a + 633d2b6 commit 94ca010
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions randomize/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func randMoney(s *Seed) string {
return fmt.Sprintf("%d.00", s.nextInt())
}

func randTime() string {
return fmt.Sprintf("%d:%d:%d", rand.Intn(24), rand.Intn(60), rand.Intn(60))
}

// StableDBName takes a database name in, and generates
// a random string using the database name as the rand Seed.
// getDBNameHash is used to generate unique test database names.
Expand Down
12 changes: 11 additions & 1 deletion randomize/randomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var (
"inet", "line", "uuid", "interval", "mediumint",
"json", "jsonb", "box", "cidr", "circle",
"lseg", "macaddr", "path", "pg_lsn", "point",
"polygon", "txid_snapshot", "money", "hstore",
"polygon", "txid_snapshot", "money", "time", "hstore",
}
)

Expand Down Expand Up @@ -244,6 +244,11 @@ func randomizeField(s *Seed, field reflect.Value, fieldType string, canBeNull bo
field.Set(reflect.ValueOf(value))
return nil
}
if fieldType == "time" {
value = null.NewString(randTime(), true)
field.Set(reflect.ValueOf(value))
return nil
}
case typeNullInt32:
if fieldType == "mediumint" {
// 8388607 is the max for 3 byte int
Expand Down Expand Up @@ -320,6 +325,11 @@ func randomizeField(s *Seed, field reflect.Value, fieldType string, canBeNull bo
field.Set(reflect.ValueOf(value))
return nil
}
if fieldType == "time" {
value = randTime()
field.Set(reflect.ValueOf(value))
return nil
}
case reflect.Int32:
if fieldType == "mediumint" {
// 8388607 is the max for 3 byte int
Expand Down

0 comments on commit 94ca010

Please sign in to comment.