Skip to content

Commit

Permalink
Update object_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
aacebo committed Oct 15, 2024
1 parent 8e0ec8e commit 0b4f307
Showing 1 changed file with 56 additions and 4 deletions.
60 changes: 56 additions & 4 deletions object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,67 @@ func TestObject(t *testing.T) {
func BenchmarkObject(b *testing.B) {
b.Run("simple", func(b *testing.B) {
schema := owl.Object().Fields(map[string]owl.Schema{
"email": owl.String().Required(),
"password": owl.String().Required(),
"email": owl.String(),
"password": owl.String(),
})

data := map[string]string{
"email": "test",
"password": "test",
}

for i := 0; i < b.N; i++ {
err := schema.Validate(data)

if err != nil {
b.Fatal(err)
}
}
})

b.Run("array", func(b *testing.B) {
schema := owl.Object().Fields(map[string]owl.Schema{
"email": owl.String(),
"password": owl.String(),
"phones": owl.Array(owl.String()),
})

data := map[string]any{
"email": "test",
"password": "test",
"phonees": []string{"1112223333"},
}

for i := 0; i < b.N; i++ {
err := schema.Validate(map[string]string{
err := schema.Validate(data)

if err != nil {
b.Fatal(err)
}
}
})

b.Run("object", func(b *testing.B) {
schema := owl.Object().Fields(map[string]owl.Schema{
"email": owl.String(),
"password": owl.String(),
"created_by": owl.Object().Fields(map[string]owl.Schema{
"email": owl.String(),
"password": owl.String(),
}),
})

data := map[string]any{
"email": "test",
"password": "test",
"phonees": map[string]string{
"email": "test",
"password": "test",
})
},
}

for i := 0; i < b.N; i++ {
err := schema.Validate(data)

if err != nil {
b.Fatal(err)
Expand Down

0 comments on commit 0b4f307

Please sign in to comment.