Skip to content

Commit

Permalink
Merge pull request #7 from rezakhademix/fix-required-msg
Browse files Browse the repository at this point in the history
fixed: required msg
  • Loading branch information
rezakhademix authored Mar 3, 2024
2 parents 0b647cb + ec59302 commit 03e45c5
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 73 deletions.
50 changes: 25 additions & 25 deletions max_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,36 @@ import (

func TestValidator_MaxInt(t *testing.T) {
tests := []struct {
field string
value int
max int
message string
isPassed bool
excpectedMsg string
field string
value int
max int
message string
isPassed bool
expectedMsg string
}{
{
field: "t0",
value: 10,
max: 10,
message: "",
isPassed: true,
excpectedMsg: "",
field: "t0",
value: 10,
max: 10,
message: "",
isPassed: true,
expectedMsg: "",
},
{
field: "t1",
value: 1,
max: 0,
message: "t1 must be less than 0",
isPassed: false,
excpectedMsg: "t1 must be less than 0",
field: "t1",
value: 1,
max: 0,
message: "t1 must be less than 0",
isPassed: false,
expectedMsg: "t1 must be less than 0",
},
{
field: "t2",
value: 122,
max: 20,
message: "t1 must be less than 20",
isPassed: false,
excpectedMsg: "t1 must be less than 20",
field: "t2",
value: 122,
max: 20,
message: "t1 must be less than 20",
isPassed: false,
expectedMsg: "t1 must be less than 20",
},
}

Expand All @@ -49,7 +49,7 @@ func TestValidator_MaxInt(t *testing.T) {
assert.Equal(t, test.isPassed, v.IsPassed())

if !test.isPassed {
assert.Equal(t, test.excpectedMsg, v.Errors()[test.field])
assert.Equal(t, test.expectedMsg, v.Errors()[test.field])
}
}
}
50 changes: 25 additions & 25 deletions min_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,36 @@ import (

func TestValidator_MinInt(t *testing.T) {
tests := []struct {
field string
value int
min int
message string
isPassed bool
excpectedMsg string
field string
value int
min int
message string
isPassed bool
expectedMsg string
}{
{
field: "t0",
value: 2,
min: 1,
message: "",
isPassed: true,
excpectedMsg: "",
field: "t0",
value: 2,
min: 1,
message: "",
isPassed: true,
expectedMsg: "",
},
{
field: "t1",
value: -1,
min: 0,
message: "t1 must be greater than 0",
isPassed: false,
excpectedMsg: "t1 must be greater than 0",
field: "t1",
value: -1,
min: 0,
message: "t1 must be greater than 0",
isPassed: false,
expectedMsg: "t1 must be greater than 0",
},
{
field: "t2",
value: 12,
min: 20,
message: "t1 must be greater than 20",
isPassed: false,
excpectedMsg: "t1 must be greater than 20",
field: "t2",
value: 12,
min: 20,
message: "t1 must be greater than 20",
isPassed: false,
expectedMsg: "t1 must be greater than 20",
},
}

Expand All @@ -49,7 +49,7 @@ func TestValidator_MinInt(t *testing.T) {
assert.Equal(t, test.isPassed, v.IsPassed())

if !test.isPassed {
assert.Equal(t, test.excpectedMsg, v.Errors()[test.field])
assert.Equal(t, test.expectedMsg, v.Errors()[test.field])
}
}
}
4 changes: 2 additions & 2 deletions required.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ const (

// RequiredString checks if a string value is empty or not.
func (v *Validator) RequiredString(s, field string, msg string) *Validator {
v.Check(strings.TrimSpace(s) != "", field, v.msg(Required, field, msg))
v.Check(strings.TrimSpace(s) != "", field, v.msg(Required, msg, field))

return v
}

// RequiredInt checks if an integer value is provided or not.
func (v *Validator) RequiredInt(i int, field string, msg string) *Validator {
v.Check(i == 0, field, v.msg(Required, field, msg))
v.Check(i == 0, field, v.msg(Required, msg, field))

return v
}
42 changes: 21 additions & 21 deletions required_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@ import (

func TestValidator_RequiredString(t *testing.T) {
tests := []struct {
tag string
value string
message string
isPassed bool
excpectedMsg string
tag string
value string
message string
isPassed bool
expectedMsg string
}{
{
tag: "t0",
value: "test 0",
message: "",
isPassed: true,
excpectedMsg: "",
tag: "t0",
value: "test 0",
message: "",
isPassed: true,
expectedMsg: "",
},
{
tag: "t1",
value: "",
message: "t1 is required",
isPassed: false,
excpectedMsg: "t1 is required",
tag: "t1",
value: "",
message: "t1 is required",
isPassed: false,
expectedMsg: "t1 is required",
},
{
tag: "t2",
value: " ",
message: "t2 is required",
isPassed: false,
excpectedMsg: "t2 is required",
tag: "t2",
value: " ",
message: "t2 is required",
isPassed: false,
expectedMsg: "t2 is required",
},
}

Expand All @@ -44,7 +44,7 @@ func TestValidator_RequiredString(t *testing.T) {
assert.Equal(t, test.isPassed, v.IsPassed())

if !test.isPassed {
assert.Equal(t, test.excpectedMsg, v.Errors()[test.tag])
assert.Equal(t, test.expectedMsg, v.Errors()[test.tag])
}
}
}

0 comments on commit 03e45c5

Please sign in to comment.