Skip to content

Commit

Permalink
chore: improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
guiferpa committed Jan 17, 2025
1 parent 7552ba5 commit cb3f0b1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions rule/enum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,12 @@ func TestEnumWithInvalidParams(t *testing.T) {
}
}
}

func TestEnumError(t *testing.T) {
err := &ErrEnum{Field: "text", Value: "2", Enum: []string{"A", "B"}}
got := err.Error()
want := "the value 2 in field text not contains in [A B]"
if got != want {
t.Errorf(`&ErrEnum{Field: "text", Value: "2", Enum: []string{"A", "B"}}.Error(), got: %v, want: %v`, got, want)
}
}
21 changes: 21 additions & 0 deletions validator_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gody

import (
"errors"
"testing"

"github.com/guiferpa/gody/v2/rule/ruletest"
Expand Down Expand Up @@ -53,3 +54,23 @@ func TestDuplicatedRule(t *testing.T) {
return
}
}

type mock struct{}

func (_ *mock) Name() string {
return "mock"
}

func (r *mock) Validate(_, _, _ string) (bool, error) {
return true, errors.New("mock error")
}

func TestDuplicatedRuleError(t *testing.T) {
r := &mock{}
err := &ErrDuplicatedRule{RuleDuplicated: r}
got := err.Error()
want := "rule mock is duplicated"
if got != want {
t.Errorf(`&ErrDuplicatedRule{RuleDuplicated: r}.Error(), got: %v, want: %v`, got, want)
}
}

0 comments on commit cb3f0b1

Please sign in to comment.