-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
error_test.go
55 lines (42 loc) · 1.55 KB
/
error_test.go
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package truemail
import (
"fmt"
"net"
"testing"
"github.com/stretchr/testify/assert"
)
func TestValidationErrorError(t *testing.T) {
t.Run("returns wrapped error message", func(t *testing.T) {
errorMessage := "error message"
customError := &validationError{err: fmt.Errorf(errorMessage)}
assert.Equal(t, errorMessage, customError.Error())
})
}
func TestWrapNullMxError(t *testing.T) {
t.Run("wrappes error to validationError with isNullMxFound marker", func(t *testing.T) {
errorMessage := "error message"
err := wrapNullMxError(fmt.Errorf(errorMessage))
assert.True(t, err.isNullMxFound)
assert.Equal(t, errorMessage, err.Error())
})
}
func TestWrapDnsError(t *testing.T) {
hostname, server, errMessage := randomDomain(), localhostIPv4Address+":53", "no such host"
t.Run("when DNSError not found error", func(t *testing.T) {
err := wrapDnsError(&net.DNSError{Name: hostname, Server: server, Err: errMessage, IsNotFound: true})
assert.True(t, err.isDnsNotFound)
assert.Equal(t, dnsErrorMessage(hostname), err.Error())
})
t.Run("when other DNSError error", func(t *testing.T) {
err := wrapDnsError(&net.DNSError{Name: hostname, Server: server, Err: errMessage, IsTimeout: true})
assert.False(t, err.isDnsNotFound)
assert.Equal(t, dnsErrorMessage(hostname), err.Error())
})
}
func TestSmtpClientErrorError(t *testing.T) {
t.Run("returns wrapped error message", func(t *testing.T) {
errorMessage := "error message"
customError := &SmtpClientError{err: fmt.Errorf(errorMessage)}
assert.Equal(t, errorMessage, customError.Error())
})
}