mirror of
https://github.com/wneessen/go-mail.git
synced 2024-12-22 18:50:37 +01:00
Merge pull request #66 from wneessen/golangci-lint
Introduce golangci-lint
This commit is contained in:
commit
ebe6fc5e6b
8 changed files with 89 additions and 20 deletions
49
.github/workflows/golangci-lint.yml
vendored
Normal file
49
.github/workflows/golangci-lint.yml
vendored
Normal file
|
@ -0,0 +1,49 @@
|
|||
# SPDX-FileCopyrightText: 2022 Winni Neessen <winni@neessen.dev>
|
||||
#
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
name: golangci-lint
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- v*
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
permissions:
|
||||
contents: read
|
||||
# Optional: allow read access to pull request. Use with `only-new-issues` option.
|
||||
# pull-requests: read
|
||||
jobs:
|
||||
golangci:
|
||||
name: lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.19
|
||||
- uses: actions/checkout@v3
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v3
|
||||
with:
|
||||
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
|
||||
version: latest
|
||||
|
||||
# Optional: working directory, useful for monorepos
|
||||
# working-directory: somedir
|
||||
|
||||
# Optional: golangci-lint command line arguments.
|
||||
# args: --issues-exit-code=0
|
||||
|
||||
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
||||
# only-new-issues: true
|
||||
|
||||
# Optional: if set to true then the all caching functionality will be complete disabled,
|
||||
# takes precedence over all other caching options.
|
||||
# skip-cache: true
|
||||
|
||||
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
|
||||
# skip-pkg-cache: true
|
||||
|
||||
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
|
||||
# skip-build-cache: true
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -20,7 +20,7 @@
|
|||
|
||||
# Local testfiles and auth data
|
||||
.auth
|
||||
cmd/*
|
||||
examples/*
|
||||
|
||||
# SonarQube
|
||||
.scannerwork/
|
||||
|
|
11
.golangci.toml
Normal file
11
.golangci.toml
Normal file
|
@ -0,0 +1,11 @@
|
|||
## SPDX-FileCopyrightText: 2022 Winni Neessen <winni@neessen.dev>
|
||||
##
|
||||
## SPDX-License-Identifier: MIT
|
||||
|
||||
[run]
|
||||
go = "1.16"
|
||||
tests = true
|
||||
|
||||
[linters]
|
||||
enable = ["stylecheck", "whitespace", "containedctx", "contextcheck", "decorder",
|
||||
"errname", "errorlint", "gofmt", "gofumpt"]
|
|
@ -20,9 +20,13 @@ func TestAuth(t *testing.T) {
|
|||
}
|
||||
|
||||
authTests := []authTest{
|
||||
{LoginAuth("user", "pass", "testserver"),
|
||||
[]string{"Username:", "Password:", "2.7.0 Authentication successful", "Invalid:"}, "LOGIN",
|
||||
[]string{"", "user", "pass", "", ""}, []bool{false, false, false, true}},
|
||||
{
|
||||
LoginAuth("user", "pass", "testserver"),
|
||||
[]string{"Username:", "Password:", "2.7.0 Authentication successful", "Invalid:"},
|
||||
"LOGIN",
|
||||
[]string{"", "user", "pass", "", ""},
|
||||
[]bool{false, false, false, true},
|
||||
},
|
||||
}
|
||||
|
||||
testLoop:
|
||||
|
|
|
@ -9,12 +9,13 @@ import (
|
|||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/wneessen/go-mail/auth"
|
||||
"net"
|
||||
"net/smtp"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/wneessen/go-mail/auth"
|
||||
)
|
||||
|
||||
// Defaults
|
||||
|
@ -504,7 +505,7 @@ func (c *Client) Send(ml ...*Msg) error {
|
|||
}
|
||||
|
||||
if err := c.Reset(); err != nil {
|
||||
return fmt.Errorf("sending RSET command failed: %s", err)
|
||||
return fmt.Errorf("sending RSET command failed: %w", err)
|
||||
}
|
||||
if err := c.checkConn(); err != nil {
|
||||
return fmt.Errorf("failed to check server connection: %w", err)
|
||||
|
@ -555,7 +556,7 @@ func (c *Client) DialAndSendWithContext(ctx context.Context, ml ...*Msg) error {
|
|||
return fmt.Errorf("send failed: %w", err)
|
||||
}
|
||||
if err := c.Close(); err != nil {
|
||||
return fmt.Errorf("failed to close connction: %s", err)
|
||||
return fmt.Errorf("failed to close connction: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -8,11 +8,12 @@ import (
|
|||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"github.com/wneessen/go-mail/auth"
|
||||
"net/smtp"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/wneessen/go-mail/auth"
|
||||
)
|
||||
|
||||
// DefaultHost is used as default hostname for the Client
|
||||
|
@ -89,9 +90,11 @@ func TestNewClientWithOptions(t *testing.T) {
|
|||
{"WithTLSConfig()", WithTLSConfig(&tls.Config{}), false},
|
||||
{"WithTLSConfig(); config is nil", WithTLSConfig(nil), true},
|
||||
{"WithSMTPAuth()", WithSMTPAuth(SMTPAuthLogin), false},
|
||||
{"WithSMTPAuthCustom()",
|
||||
{
|
||||
"WithSMTPAuthCustom()",
|
||||
WithSMTPAuthCustom(smtp.PlainAuth("", "", "", "")),
|
||||
false},
|
||||
false,
|
||||
},
|
||||
{"WithUsername()", WithUsername("test"), false},
|
||||
{"WithPassword()", WithPassword("test"), false},
|
||||
{"WithDSN()", WithDSN(), false},
|
||||
|
@ -99,8 +102,10 @@ func TestNewClientWithOptions(t *testing.T) {
|
|||
{"WithDSNMailReturnType() wrong option", WithDSNMailReturnType("FAIL"), true},
|
||||
{"WithDSNRcptNotifyType()", WithDSNRcptNotifyType(DSNRcptNotifySuccess), false},
|
||||
{"WithDSNRcptNotifyType() wrong option", WithDSNRcptNotifyType("FAIL"), true},
|
||||
{"WithDSNRcptNotifyType() NEVER combination",
|
||||
WithDSNRcptNotifyType(DSNRcptNotifySuccess, DSNRcptNotifyNever), true},
|
||||
{
|
||||
"WithDSNRcptNotifyType() NEVER combination",
|
||||
WithDSNRcptNotifyType(DSNRcptNotifySuccess, DSNRcptNotifyNever), true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
@ -796,7 +801,6 @@ func TestClient_DialSendCloseBroken(t *testing.T) {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// TestClient_DialSendCloseBrokenWithDSN tests the Dial(), Send() and Close() method of Client with
|
||||
|
@ -857,7 +861,6 @@ func TestClient_DialSendCloseBrokenWithDSN(t *testing.T) {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// TestClient_auth tests the Dial(), Send() and Close() method of Client with broken settings
|
||||
|
@ -948,10 +951,10 @@ func getTestConnection(auth bool) (*Client, error) {
|
|||
}
|
||||
}
|
||||
if err := c.DialWithContext(context.Background()); err != nil {
|
||||
return c, fmt.Errorf("connection to test server failed: %s", err)
|
||||
return c, fmt.Errorf("connection to test server failed: %w", err)
|
||||
}
|
||||
if err := c.Close(); err != nil {
|
||||
return c, fmt.Errorf("disconnect from test server failed: %s", err)
|
||||
return c, fmt.Errorf("disconnect from test server failed: %w", err)
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
@ -985,10 +988,10 @@ func getTestConnectionWithDSN(auth bool) (*Client, error) {
|
|||
}
|
||||
}
|
||||
if err := c.DialWithContext(context.Background()); err != nil {
|
||||
return c, fmt.Errorf("connection to test server failed: %s", err)
|
||||
return c, fmt.Errorf("connection to test server failed: %w", err)
|
||||
}
|
||||
if err := c.Close(); err != nil {
|
||||
return c, fmt.Errorf("disconnect from test server failed: %s", err)
|
||||
return c, fmt.Errorf("disconnect from test server failed: %w", err)
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
|
|
@ -7,10 +7,11 @@ package mail_test
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/wneessen/go-mail"
|
||||
"os"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/wneessen/go-mail"
|
||||
)
|
||||
|
||||
// Code example for the NewClient method
|
||||
|
|
|
@ -132,7 +132,7 @@ const (
|
|||
|
||||
// List of MIME versions
|
||||
const (
|
||||
//Mime10 is the MIME Version 1.0
|
||||
// Mime10 is the MIME Version 1.0
|
||||
Mime10 MIMEVersion = "1.0"
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue