Skip to content

Commit a0d024e

Browse files
committed
fix data generator for format: time
1 parent db6a7d0 commit a0d024e

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

schema/json/generator/string.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package generator
22

33
import (
4-
"github.com/brianvoe/gofakeit/v6"
54
"mokapi/schema/json/schema"
65
"time"
6+
7+
"github.com/brianvoe/gofakeit/v6"
78
)
89

910
var (
@@ -73,6 +74,8 @@ func fakeFormat(s *schema.Schema) (interface{}, error) {
7374
return date().Format("2006-01-02"), nil
7475
case "date-time":
7576
return date().Format(time.RFC3339), nil
77+
case "time":
78+
return date().Format("15:04:05Z07:00"), nil
7679
case "password":
7780
return gofakeit.Generate("{password}"), nil
7881
case "email":

schema/json/generator/string_test.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package generator
22

33
import (
4-
"github.com/brianvoe/gofakeit/v6"
5-
"github.com/stretchr/testify/require"
64
"mokapi/schema/json/schema/schematest"
75
"testing"
6+
7+
"github.com/brianvoe/gofakeit/v6"
8+
"github.com/stretchr/testify/require"
89
)
910

1011
func TestStringFormat(t *testing.T) {
@@ -33,6 +34,16 @@ func TestStringFormat(t *testing.T) {
3334
require.Equal(t, "2007-08-26T07:02:11Z", v)
3435
},
3536
},
37+
{
38+
name: "time",
39+
req: &Request{
40+
Schema: schematest.New("string", schematest.WithFormat("time")),
41+
},
42+
test: func(t *testing.T, v interface{}, err error) {
43+
require.NoError(t, err)
44+
require.Equal(t, "07:02:11Z", v)
45+
},
46+
},
3647
{
3748
name: "password",
3849
req: &Request{

0 commit comments

Comments
 (0)