Esempio n. 1
0
func TestEmailInValid(t *testing.T) {
	v := struct {
		Email string `email:"-"`
	}{
		"fuga",
	}

	if err := gova.Validate(v); err == nil {
		t.Error("email validator doesn't work!")
	}
}
Esempio n. 2
0
func TestEmailValid(t *testing.T) {
	v := struct {
		Email string `email:"-"`
	}{
		"*****@*****.**",
	}

	if err := gova.Validate(v); err != nil {
		t.Error(err)
	}
}
Esempio n. 3
0
func TestPatternValid(t *testing.T) {
	v := struct {
		Num string `pattern:"[0-9]+"`
	}{
		"11111",
	}

	if err := gova.Validate(v); err != nil {
		t.Error(err)
	}
}
Esempio n. 4
0
func TestPatternInValid(t *testing.T) {
	v := struct {
		Num string `pattern:"[0-9]+"`
	}{
		"fuga",
	}

	if err := gova.Validate(v); err == nil {
		t.Error("pattern validator doesn't work!")
	}
}
Esempio n. 5
0
func TestLengthValid(t *testing.T) {
	v := struct {
		Str string `length:"10"`
	}{
		"1234567890",
	}

	if err := gova.Validate(v); err != nil {
		t.Error(err)
	}
}
Esempio n. 6
0
func TestLengthInValid(t *testing.T) {
	v := struct {
		Str string `length:"10"`
	}{
		"1234",
	}

	if err := gova.Validate(v); err == nil {
		t.Error("length validator doesn't work!")
	}
}
Esempio n. 7
0
func TestStructPointerResolutionValidation(t *testing.T) {
	// this test should not cause panic
	tmp := &Form{"alpha"}
	gova.Validate(tmp)
}