-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail_validator_test.go
More file actions
38 lines (28 loc) · 1011 Bytes
/
email_validator_test.go
File metadata and controls
38 lines (28 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2021 Hyperscale. All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.
package validator
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestEmailValidator(t *testing.T) {
v := NewEmailValidator(EmailTimeout(1 * time.Second))
assert.EqualError(t, v.Validate(124), "invalid input type \"int\" for email validator")
assert.Error(t, v.Validate("bad"))
assert.Error(t, v.Validate("bad@bad-domain-name.tld"))
assert.Error(t, v.Validate("user@perdu.com"))
assert.NoError(t, v.Validate("euskadi31@gmail.com"))
assert.NoError(t, v.Validate("axel@etcheverry.biz"))
}
func TestEmailValidatorSingle(t *testing.T) {
v := NewEmailValidator(EmailTimeout(1 * time.Second))
assert.NoError(t, v.Validate("euskadi31@gmail.com"))
}
func BenchmarkEmailValidator(b *testing.B) {
v := NewEmailValidator(EmailTimeout(200 * time.Millisecond))
for i := 0; i < b.N; i++ {
v.Validate("euskadi31@gmail.com")
}
}