Merge pull request #152 from bluesuncorp/v6-development

Updated Panic Tests after updates to assertion library
pull/153/head v6.5.1
Dean Karn 9 years ago
commit 6df82fdf49
  1. 67
      validator_test.go

@ -4,7 +4,6 @@ import (
"database/sql"
"database/sql/driver"
"encoding/json"
"errors"
"fmt"
"reflect"
"testing"
@ -130,7 +129,8 @@ type valuer struct {
func (v valuer) Value() (driver.Value, error) {
if v.Name == "errorme" {
return nil, errors.New("some kind of error")
panic("SQL Driver Valuer error: some kind of error")
// return nil, errors.New("some kind of error")
}
if len(v.Name) == 0 {
@ -248,7 +248,7 @@ func TestSQLValue2Validation(t *testing.T) {
val.Name = "errorme"
PanicMatches(t, func() { errs = validate.Field(val, "required") }, "SQL Driver Valuer error: some kind of error")
PanicMatches(t, func() { validate.Field(val, "required") }, "SQL Driver Valuer error: some kind of error")
type myValuer valuer
@ -3187,7 +3187,9 @@ func TestHsla(t *testing.T) {
AssertError(t, errs, "", "", "hsla")
i := 1
PanicMatches(t, func() { validate.Field(i, "hsla") }, "interface conversion: interface is int, not string")
validate.Field(i, "hsla")
NotEqual(t, errs, nil)
AssertError(t, errs, "", "", "hsla")
}
func TestHsl(t *testing.T) {
@ -3221,7 +3223,9 @@ func TestHsl(t *testing.T) {
AssertError(t, errs, "", "", "hsl")
i := 1
PanicMatches(t, func() { validate.Field(i, "hsl") }, "interface conversion: interface is int, not string")
errs = validate.Field(i, "hsl")
NotEqual(t, errs, nil)
AssertError(t, errs, "", "", "hsl")
}
func TestRgba(t *testing.T) {
@ -3263,7 +3267,9 @@ func TestRgba(t *testing.T) {
AssertError(t, errs, "", "", "rgba")
i := 1
PanicMatches(t, func() { validate.Field(i, "rgba") }, "interface conversion: interface is int, not string")
errs = validate.Field(i, "rgba")
NotEqual(t, errs, nil)
AssertError(t, errs, "", "", "rgba")
}
func TestRgb(t *testing.T) {
@ -3301,7 +3307,9 @@ func TestRgb(t *testing.T) {
AssertError(t, errs, "", "", "rgb")
i := 1
PanicMatches(t, func() { validate.Field(i, "rgb") }, "interface conversion: interface is int, not string")
errs = validate.Field(i, "rgb")
NotEqual(t, errs, nil)
AssertError(t, errs, "", "", "rgb")
}
func TestEmail(t *testing.T) {
@ -3331,7 +3339,9 @@ func TestEmail(t *testing.T) {
AssertError(t, errs, "", "", "email")
i := true
PanicMatches(t, func() { validate.Field(i, "email") }, "interface conversion: interface is bool, not string")
errs = validate.Field(i, "email")
NotEqual(t, errs, nil)
AssertError(t, errs, "", "", "email")
}
func TestHexColor(t *testing.T) {
@ -3355,7 +3365,9 @@ func TestHexColor(t *testing.T) {
AssertError(t, errs, "", "", "hexcolor")
i := true
PanicMatches(t, func() { validate.Field(i, "hexcolor") }, "interface conversion: interface is bool, not string")
errs = validate.Field(i, "hexcolor")
NotEqual(t, errs, nil)
AssertError(t, errs, "", "", "hexcolor")
}
func TestHexadecimal(t *testing.T) {
@ -3370,7 +3382,9 @@ func TestHexadecimal(t *testing.T) {
AssertError(t, errs, "", "", "hexadecimal")
i := true
PanicMatches(t, func() { validate.Field(i, "hexadecimal") }, "interface conversion: interface is bool, not string")
errs = validate.Field(i, "hexadecimal")
NotEqual(t, errs, nil)
AssertError(t, errs, "", "", "hexadecimal")
}
func TestNumber(t *testing.T) {
@ -3415,7 +3429,9 @@ func TestNumber(t *testing.T) {
AssertError(t, errs, "", "", "number")
i := 1
PanicMatches(t, func() { validate.Field(i, "number") }, "interface conversion: interface is int, not string")
errs = validate.Field(i, "number")
NotEqual(t, errs, nil)
AssertError(t, errs, "", "", "number")
}
func TestNumeric(t *testing.T) {
@ -3455,7 +3471,9 @@ func TestNumeric(t *testing.T) {
AssertError(t, errs, "", "", "numeric")
i := 1
PanicMatches(t, func() { validate.Field(i, "numeric") }, "interface conversion: interface is int, not string")
errs = validate.Field(i, "numeric")
NotEqual(t, errs, nil)
AssertError(t, errs, "", "", "numeric")
}
func TestAlphaNumeric(t *testing.T) {
@ -3469,7 +3487,9 @@ func TestAlphaNumeric(t *testing.T) {
NotEqual(t, errs, nil)
AssertError(t, errs, "", "", "alphanum")
PanicMatches(t, func() { validate.Field(1, "alphanum") }, "interface conversion: interface is int, not string")
errs = validate.Field(1, "alphanum")
NotEqual(t, errs, nil)
AssertError(t, errs, "", "", "alphanum")
}
func TestAlpha(t *testing.T) {
@ -3481,10 +3501,11 @@ func TestAlpha(t *testing.T) {
s = "abc1"
errs = validate.Field(s, "alpha")
NotEqual(t, errs, nil)
AssertError(t, errs, "", "", "alpha")
PanicMatches(t, func() { validate.Field(1, "alpha") }, "interface conversion: interface is int, not string")
errs = validate.Field(1, "alpha")
NotEqual(t, errs, nil)
AssertError(t, errs, "", "", "alpha")
}
func TestStructStringValidation(t *testing.T) {
@ -3737,22 +3758,6 @@ func TestInvalidStruct(t *testing.T) {
PanicMatches(t, func() { validate.Struct(s.Test) }, "value passed for validation is not a struct")
}
func TestInvalidField(t *testing.T) {
s := &SubTest{
Test: "1",
}
PanicMatches(t, func() { validate.Field(s, "required") }, "Invalid field passed to traverseField")
}
func TestInvalidTagField(t *testing.T) {
s := &SubTest{
Test: "1",
}
PanicMatches(t, func() { validate.Field(s.Test, "") }, fmt.Sprintf("Invalid validation tag on field %s", ""))
}
func TestInvalidValidatorFunction(t *testing.T) {
s := &SubTest{
Test: "1",

Loading…
Cancel
Save