mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-09 23:42:55 +01:00
More tests coverage for client.go
This commit is contained in:
parent
d17decfdc2
commit
fe3925c1e6
2 changed files with 37 additions and 25 deletions
|
@ -133,7 +133,6 @@ func NewClient(h string, o ...Option) (*Client, error) {
|
||||||
// Some settings in a Client cannot be empty/unset
|
// Some settings in a Client cannot be empty/unset
|
||||||
if c.host == "" {
|
if c.host == "" {
|
||||||
return c, ErrNoHostname
|
return c, ErrNoHostname
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return c, nil
|
return c, nil
|
||||||
|
|
|
@ -13,31 +13,44 @@ const DefaultHost = "localhost"
|
||||||
// TestNewClient tests the NewClient() method with its default options
|
// TestNewClient tests the NewClient() method with its default options
|
||||||
func TestNewClient(t *testing.T) {
|
func TestNewClient(t *testing.T) {
|
||||||
host := "mail.example.com"
|
host := "mail.example.com"
|
||||||
c, err := NewClient(host)
|
tests := []struct {
|
||||||
if err != nil {
|
name string
|
||||||
t.Errorf("failed to create new client: %s", err)
|
host string
|
||||||
return
|
shouldfail bool
|
||||||
|
}{
|
||||||
|
{"Default", "mail.example.com", false},
|
||||||
|
{"Empty host should fail", "", true},
|
||||||
}
|
}
|
||||||
if c.host != host {
|
|
||||||
t.Errorf("failed to create new client. Host expected: %s, got: %s", host, c.host)
|
for _, tt := range tests {
|
||||||
}
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if c.cto != DefaultTimeout {
|
c, err := NewClient(tt.host)
|
||||||
t.Errorf("failed to create new client. Timeout expected: %s, got: %s", DefaultTimeout.String(),
|
if err != nil && !tt.shouldfail {
|
||||||
c.cto.String())
|
t.Errorf("failed to create new client: %s", err)
|
||||||
}
|
return
|
||||||
if c.port != DefaultPort {
|
}
|
||||||
t.Errorf("failed to create new client. Port expected: %d, got: %d", DefaultPort, c.port)
|
if c.host != host {
|
||||||
}
|
t.Errorf("failed to create new client. Host expected: %s, got: %s", host, c.host)
|
||||||
if c.tlspolicy != TLSMandatory {
|
}
|
||||||
t.Errorf("failed to create new client. TLS policy expected: %d, got: %d", TLSMandatory, c.tlspolicy)
|
if c.cto != DefaultTimeout {
|
||||||
}
|
t.Errorf("failed to create new client. Timeout expected: %s, got: %s", DefaultTimeout.String(),
|
||||||
if c.tlsconfig.ServerName != host {
|
c.cto.String())
|
||||||
t.Errorf("failed to create new client. TLS config host expected: %s, got: %s",
|
}
|
||||||
host, c.tlsconfig.ServerName)
|
if c.port != DefaultPort {
|
||||||
}
|
t.Errorf("failed to create new client. Port expected: %d, got: %d", DefaultPort, c.port)
|
||||||
if c.tlsconfig.MinVersion != DefaultTLSMinVersion {
|
}
|
||||||
t.Errorf("failed to create new client. TLS config min versino expected: %d, got: %d",
|
if c.tlspolicy != TLSMandatory {
|
||||||
DefaultTLSMinVersion, c.tlsconfig.MinVersion)
|
t.Errorf("failed to create new client. TLS policy expected: %d, got: %d", TLSMandatory, c.tlspolicy)
|
||||||
|
}
|
||||||
|
if c.tlsconfig.ServerName != host {
|
||||||
|
t.Errorf("failed to create new client. TLS config host expected: %s, got: %s",
|
||||||
|
host, c.tlsconfig.ServerName)
|
||||||
|
}
|
||||||
|
if c.tlsconfig.MinVersion != DefaultTLSMinVersion {
|
||||||
|
t.Errorf("failed to create new client. TLS config min versino expected: %d, got: %d",
|
||||||
|
DefaultTLSMinVersion, c.tlsconfig.MinVersion)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue