Skip to content

Commit 94ca010

Browse files
committed
Merge branch 'ceshihao/fix_random_time_issue_in_test' into dev
2 parents 9efaa8a + 633d2b6 commit 94ca010

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

randomize/random.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ func randMoney(s *Seed) string {
9090
return fmt.Sprintf("%d.00", s.nextInt())
9191
}
9292

93+
func randTime() string {
94+
return fmt.Sprintf("%d:%d:%d", rand.Intn(24), rand.Intn(60), rand.Intn(60))
95+
}
96+
9397
// StableDBName takes a database name in, and generates
9498
// a random string using the database name as the rand Seed.
9599
// getDBNameHash is used to generate unique test database names.

randomize/randomize.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var (
5555
"inet", "line", "uuid", "interval", "mediumint",
5656
"json", "jsonb", "box", "cidr", "circle",
5757
"lseg", "macaddr", "path", "pg_lsn", "point",
58-
"polygon", "txid_snapshot", "money", "hstore",
58+
"polygon", "txid_snapshot", "money", "time", "hstore",
5959
}
6060
)
6161

@@ -244,6 +244,11 @@ func randomizeField(s *Seed, field reflect.Value, fieldType string, canBeNull bo
244244
field.Set(reflect.ValueOf(value))
245245
return nil
246246
}
247+
if fieldType == "time" {
248+
value = null.NewString(randTime(), true)
249+
field.Set(reflect.ValueOf(value))
250+
return nil
251+
}
247252
case typeNullInt32:
248253
if fieldType == "mediumint" {
249254
// 8388607 is the max for 3 byte int
@@ -320,6 +325,11 @@ func randomizeField(s *Seed, field reflect.Value, fieldType string, canBeNull bo
320325
field.Set(reflect.ValueOf(value))
321326
return nil
322327
}
328+
if fieldType == "time" {
329+
value = randTime()
330+
field.Set(reflect.ValueOf(value))
331+
return nil
332+
}
323333
case reflect.Int32:
324334
if fieldType == "mediumint" {
325335
// 8388607 is the max for 3 byte int

0 commit comments

Comments
 (0)