Merge pull request #66 from wneessen/golangci-lint

Introduce golangci-lint
This commit is contained in:
Winni Neessen 2022-10-17 18:46:19 +02:00 committed by GitHub
commit ebe6fc5e6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 89 additions and 20 deletions

49
.github/workflows/golangci-lint.yml vendored Normal file
View 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
View file

@ -20,7 +20,7 @@
# Local testfiles and auth data # Local testfiles and auth data
.auth .auth
cmd/* examples/*
# SonarQube # SonarQube
.scannerwork/ .scannerwork/

11
.golangci.toml Normal file
View 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"]

View file

@ -20,9 +20,13 @@ func TestAuth(t *testing.T) {
} }
authTests := []authTest{ authTests := []authTest{
{LoginAuth("user", "pass", "testserver"), {
[]string{"Username:", "Password:", "2.7.0 Authentication successful", "Invalid:"}, "LOGIN", LoginAuth("user", "pass", "testserver"),
[]string{"", "user", "pass", "", ""}, []bool{false, false, false, true}}, []string{"Username:", "Password:", "2.7.0 Authentication successful", "Invalid:"},
"LOGIN",
[]string{"", "user", "pass", "", ""},
[]bool{false, false, false, true},
},
} }
testLoop: testLoop:

View file

@ -9,12 +9,13 @@ import (
"crypto/tls" "crypto/tls"
"errors" "errors"
"fmt" "fmt"
"github.com/wneessen/go-mail/auth"
"net" "net"
"net/smtp" "net/smtp"
"os" "os"
"strings" "strings"
"time" "time"
"github.com/wneessen/go-mail/auth"
) )
// Defaults // Defaults
@ -504,7 +505,7 @@ func (c *Client) Send(ml ...*Msg) error {
} }
if err := c.Reset(); err != nil { 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 { if err := c.checkConn(); err != nil {
return fmt.Errorf("failed to check server connection: %w", err) 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) return fmt.Errorf("send failed: %w", err)
} }
if err := c.Close(); err != nil { 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 return nil
} }

View file

@ -8,11 +8,12 @@ import (
"context" "context"
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"github.com/wneessen/go-mail/auth"
"net/smtp" "net/smtp"
"os" "os"
"testing" "testing"
"time" "time"
"github.com/wneessen/go-mail/auth"
) )
// DefaultHost is used as default hostname for the Client // DefaultHost is used as default hostname for the Client
@ -89,9 +90,11 @@ func TestNewClientWithOptions(t *testing.T) {
{"WithTLSConfig()", WithTLSConfig(&tls.Config{}), false}, {"WithTLSConfig()", WithTLSConfig(&tls.Config{}), false},
{"WithTLSConfig(); config is nil", WithTLSConfig(nil), true}, {"WithTLSConfig(); config is nil", WithTLSConfig(nil), true},
{"WithSMTPAuth()", WithSMTPAuth(SMTPAuthLogin), false}, {"WithSMTPAuth()", WithSMTPAuth(SMTPAuthLogin), false},
{"WithSMTPAuthCustom()", {
"WithSMTPAuthCustom()",
WithSMTPAuthCustom(smtp.PlainAuth("", "", "", "")), WithSMTPAuthCustom(smtp.PlainAuth("", "", "", "")),
false}, false,
},
{"WithUsername()", WithUsername("test"), false}, {"WithUsername()", WithUsername("test"), false},
{"WithPassword()", WithPassword("test"), false}, {"WithPassword()", WithPassword("test"), false},
{"WithDSN()", WithDSN(), false}, {"WithDSN()", WithDSN(), false},
@ -99,8 +102,10 @@ func TestNewClientWithOptions(t *testing.T) {
{"WithDSNMailReturnType() wrong option", WithDSNMailReturnType("FAIL"), true}, {"WithDSNMailReturnType() wrong option", WithDSNMailReturnType("FAIL"), true},
{"WithDSNRcptNotifyType()", WithDSNRcptNotifyType(DSNRcptNotifySuccess), false}, {"WithDSNRcptNotifyType()", WithDSNRcptNotifyType(DSNRcptNotifySuccess), false},
{"WithDSNRcptNotifyType() wrong option", WithDSNRcptNotifyType("FAIL"), true}, {"WithDSNRcptNotifyType() wrong option", WithDSNRcptNotifyType("FAIL"), true},
{"WithDSNRcptNotifyType() NEVER combination", {
WithDSNRcptNotifyType(DSNRcptNotifySuccess, DSNRcptNotifyNever), true}, "WithDSNRcptNotifyType() NEVER combination",
WithDSNRcptNotifyType(DSNRcptNotifySuccess, DSNRcptNotifyNever), true,
},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { 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 // 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 // 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 { 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 { 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 return c, nil
} }
@ -985,10 +988,10 @@ func getTestConnectionWithDSN(auth bool) (*Client, error) {
} }
} }
if err := c.DialWithContext(context.Background()); err != nil { 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 { 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 return c, nil
} }

View file

@ -7,10 +7,11 @@ package mail_test
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/wneessen/go-mail"
"os" "os"
"text/template" "text/template"
"time" "time"
"github.com/wneessen/go-mail"
) )
// Code example for the NewClient method // Code example for the NewClient method