Skip to content

Commit

Permalink
add new test
Browse files Browse the repository at this point in the history
  • Loading branch information
aacebo committed Apr 6, 2024
1 parent d5c7cdc commit 51b8f4e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions rules/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,20 @@ func Test_Default(t *testing.T) {
t.Error("should set default value")
}
})

t.Run("should succeed with required", func(t *testing.T) {
v := struct {
A *string `json:"a" owl:"default=123,required"`
}{}

errs := owl.Validate(&v)

if len(errs) > 0 {
t.Error(errs)
}

if v.A == nil || *v.A != "123" {
t.Error("should set default value")
}
})
}
2 changes: 1 addition & 1 deletion validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ type owl struct {
func New() *owl {
return &owl{
rules: map[string]rules.Rule{
"required": rules.Required,
"default": rules.Default,
"required": rules.Required,
"pattern": rules.Pattern,
"format": rules.Format,
"min": rules.Min,
Expand Down

0 comments on commit 51b8f4e

Please sign in to comment.