Skip to content

Commit

Permalink
Fixed tests for mac address message error
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagoacardoso committed Jun 13, 2019
1 parent 3ab87e6 commit d057078
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ func Test_MacAddress(t *testing.T) {
}

messages := MapData{
"web": []string{"mac_address:custom_message"},
"mac_address": []string{"mac_address:custom_message"},
}

opts := Options{
Expand All @@ -1365,6 +1365,40 @@ func Test_MacAddress(t *testing.T) {
}
}

func Test_MacAddress_message(t *testing.T) {
type user struct {
MacAddress string `json:"mac_address"`
}

postUser := user{MacAddress: "invalid_mac_address"}
var userObj user

body, _ := json.Marshal(postUser)
req, _ := http.NewRequest("POST", "http://www.example.com", bytes.NewReader(body))

rules := MapData{
"mac_address": []string{"mac_address"},
}

messages := MapData{
"mac_address": []string{"mac_address:custom_message"},
}

opts := Options{
Request: req,
Data: &userObj,
Rules: rules,
Messages: messages,
}

vd := New(opts)
validationErr := vd.ValidateJSON()
if validationErr.Get("mac_address") != "custom_message" {
t.Error("Mac Address custom message failed!")
}
}


func Test_Numeric(t *testing.T) {
type user struct {
NID string `json:"nid"`
Expand Down

0 comments on commit d057078

Please sign in to comment.