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 18, 2025
1 parent 2bd0ea5 commit ab30d63
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
10 changes: 9 additions & 1 deletion rule/max_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func TestMaxWithInvalidValue(t *testing.T) {
t.Errorf("unexpected validation result as okay")
}
}

}

func TestMaxFailure(t *testing.T) {
Expand All @@ -87,3 +86,12 @@ func TestMaxFailure(t *testing.T) {
}
}
}

func TestMaxError(t *testing.T) {
err := &ErrMax{Field: "text", Value: 3, Max: 1}
got := err.Error()
want := "the value 3 in field text is grater than 1"
if got != want {
t.Errorf(`&ErrMax{Field: "text", Value: 3, Max: 1}.Error(), got: %v, want: %v`, got, want)
}
}
9 changes: 9 additions & 0 deletions rule/min_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,12 @@ func TestMinFailure(t *testing.T) {
}
}
}

func TestMinError(t *testing.T) {
err := &ErrMin{Field: "text", Value: 1, Min: 3}
got := err.Error()
want := "the value 1 in field text is less than 3"
if got != want {
t.Errorf(`&ErrMin{Field: "text", Value: 1, Min: 3}.Error(), got: %v, want: %v`, got, want)
}
}
9 changes: 9 additions & 0 deletions rule/required_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,12 @@ func TestRequiredWithInvalidParam(t *testing.T) {
t.Errorf("unexpected result, result: %v, expected: %v", ok, false)
}
}

func TestRequiredError(t *testing.T) {
err := &ErrRequired{Field: "text"}
got := err.Error()
want := "text is required"
if got != want {
t.Errorf(`&ErrRequired{Field: "text"}.Error(), got: %v, want: %v`, got, want)
}
}

0 comments on commit ab30d63

Please sign in to comment.