Skip to content

Commit

Permalink
chore: update linter (#2046)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Oct 31, 2023
1 parent 4f242c9 commit d51b5e4
Show file tree
Hide file tree
Showing 38 changed files with 127 additions and 116 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
env:
GO_VERSION: stable
GOLANGCI_LINT_VERSION: v1.54.1
GOLANGCI_LINT_VERSION: v1.55.1
HUGO_VERSION: '0.117.0'
CGO_ENABLED: 0
LEGO_E2E_TESTS: CI
Expand Down
13 changes: 13 additions & 0 deletions .golangci.yml
Expand Up @@ -88,6 +88,19 @@ linters-settings:
disabled: true
- name: unreachable-code
- name: redefines-builtin-id
testifylint:
enable:
- bool-compare
- compares
- empty
- error-is-as
- error-nil
- expected-actual
- float-compare
- len
- suite-dont-use-pkg
- suite-extra-assert-call
- suite-thelper

linters:
enable-all: true
Expand Down
11 changes: 5 additions & 6 deletions certificate/errors_test.go
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand All @@ -28,7 +27,7 @@ func Test_obtainError_Join(t *testing.T) {
err := failures.Join()

to := &TomatoError{}
assert.ErrorAs(t, err, &to)
require.ErrorAs(t, err, &to)
}

func Test_obtainError_Join_multiple_domains(t *testing.T) {
Expand All @@ -40,16 +39,16 @@ func Test_obtainError_Join_multiple_domains(t *testing.T) {
err := failures.Join()

to := &TomatoError{}
assert.ErrorAs(t, err, &to)
require.ErrorAs(t, err, &to)

ca := &CarrotError{}
assert.ErrorAs(t, err, &ca)
require.ErrorAs(t, err, &ca)
}

func Test_obtainError_Join_no_error(t *testing.T) {
failures := newObtainError()

assert.NoError(t, failures.Join())
require.NoError(t, failures.Join())
}

func Test_obtainError_Join_same_domain(t *testing.T) {
Expand All @@ -66,5 +65,5 @@ func Test_obtainError_Join_same_domain(t *testing.T) {
}

ca := &CarrotError{}
assert.ErrorAs(t, err, &ca)
require.ErrorAs(t, err, &ca)
}
7 changes: 3 additions & 4 deletions challenge/dns01/dns_challenge_manual_test.go
Expand Up @@ -5,7 +5,6 @@ import (
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand All @@ -32,14 +31,14 @@ func TestDNSProviderManual(t *testing.T) {
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
file, err := os.CreateTemp("", "lego_test")
assert.NoError(t, err)
require.NoError(t, err)
defer func() { _ = os.Remove(file.Name()) }()

_, err = file.WriteString(test.input)
assert.NoError(t, err)
require.NoError(t, err)

_, err = file.Seek(0, io.SeekStart)
assert.NoError(t, err)
require.NoError(t, err)

os.Stdin = file

Expand Down
2 changes: 1 addition & 1 deletion challenge/tlsalpn01/tls_alpn_challenge_test.go
Expand Up @@ -141,7 +141,7 @@ func TestChallengeIPaddress(t *testing.T) {
assert.Len(t, connState.PeerCertificates, 1, "Expected the challenge server to return exactly one certificate")

remoteCert := connState.PeerCertificates[0]
assert.Len(t, remoteCert.DNSNames, 0, "Expected the challenge certificate to have no DNSNames entry in context of challenge for IP")
assert.Empty(t, remoteCert.DNSNames, "Expected the challenge certificate to have no DNSNames entry in context of challenge for IP")
assert.Len(t, remoteCert.IPAddresses, 1, "Expected the challenge certificate to have exactly one IPAddresses entry")
assert.True(t, net.ParseIP("127.0.0.1").Equal(remoteCert.IPAddresses[0]), "challenge certificate IPAddress ")
assert.NotEmpty(t, remoteCert.Extensions, "Expected the challenge certificate to contain extensions")
Expand Down
16 changes: 8 additions & 8 deletions cmd/zz_gen_cmd_dnshelp.go
Expand Up @@ -1635,17 +1635,17 @@ func displayDNSHelp(w io.Writer, name string) error {
ew.writeln()

ew.writeln(`Credentials:`)
ew.writeln(` - "LIQUID_WEB_PASSWORD": Liquid Web API Password`)
ew.writeln(` - "LIQUID_WEB_USERNAME": Liquid Web API Username`)
ew.writeln(` - "LWAPI_PASSWORD": Liquid Web API Password`)
ew.writeln(` - "LWAPI_USERNAME": Liquid Web API Username`)
ew.writeln()

ew.writeln(`Additional Configuration:`)
ew.writeln(` - "LIQUID_WEB_HTTP_TIMEOUT": Maximum waiting time for the DNS records to be created (not verified)`)
ew.writeln(` - "LIQUID_WEB_POLLING_INTERVAL": Time between DNS propagation check`)
ew.writeln(` - "LIQUID_WEB_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation`)
ew.writeln(` - "LIQUID_WEB_TTL": The TTL of the TXT record used for the DNS challenge`)
ew.writeln(` - "LIQUID_WEB_URL": Liquid Web API endpoint`)
ew.writeln(` - "LIQUID_WEB_ZONE": DNS Zone`)
ew.writeln(` - "LWAPI_HTTP_TIMEOUT": Maximum waiting time for the DNS records to be created (not verified)`)
ew.writeln(` - "LWAPI_POLLING_INTERVAL": Time between DNS propagation check`)
ew.writeln(` - "LWAPI_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation`)
ew.writeln(` - "LWAPI_TTL": The TTL of the TXT record used for the DNS challenge`)
ew.writeln(` - "LWAPI_URL": Liquid Web API endpoint`)
ew.writeln(` - "LWAPI_ZONE": DNS Zone`)

ew.writeln()
ew.writeln(`More information: https://go-acme.github.io/lego/dns/liquidweb`)
Expand Down
20 changes: 10 additions & 10 deletions docs/content/dns/zz_gen_liquidweb.md
Expand Up @@ -26,8 +26,8 @@ Configuration for [Liquid Web](https://liquidweb.com).
Here is an example bash command using the Liquid Web provider:

```bash
LIQUID_WEB_USERNAME=someuser \
LIQUID_WEB_PASSWORD=somepass \
LWAPI_USERNAME=someuser \
LWAPI_PASSWORD=somepass \
lego --email you@example.com --dns liquidweb --domains my.example.org run
```

Expand All @@ -38,8 +38,8 @@ lego --email you@example.com --dns liquidweb --domains my.example.org run

| Environment Variable Name | Description |
|-----------------------|-------------|
| `LIQUID_WEB_PASSWORD` | Liquid Web API Password |
| `LIQUID_WEB_USERNAME` | Liquid Web API Username |
| `LWAPI_PASSWORD` | Liquid Web API Password |
| `LWAPI_USERNAME` | Liquid Web API Username |

The environment variable names can be suffixed by `_FILE` to reference a file instead of a value.
More information [here]({{< ref "dns#configuration-and-credentials" >}}).
Expand All @@ -49,12 +49,12 @@ More information [here]({{< ref "dns#configuration-and-credentials" >}}).

| Environment Variable Name | Description |
|--------------------------------|-------------|
| `LIQUID_WEB_HTTP_TIMEOUT` | Maximum waiting time for the DNS records to be created (not verified) |
| `LIQUID_WEB_POLLING_INTERVAL` | Time between DNS propagation check |
| `LIQUID_WEB_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation |
| `LIQUID_WEB_TTL` | The TTL of the TXT record used for the DNS challenge |
| `LIQUID_WEB_URL` | Liquid Web API endpoint |
| `LIQUID_WEB_ZONE` | DNS Zone |
| `LWAPI_HTTP_TIMEOUT` | Maximum waiting time for the DNS records to be created (not verified) |
| `LWAPI_POLLING_INTERVAL` | Time between DNS propagation check |
| `LWAPI_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation |
| `LWAPI_TTL` | The TTL of the TXT record used for the DNS challenge |
| `LWAPI_URL` | Liquid Web API endpoint |
| `LWAPI_ZONE` | DNS Zone |

The environment variable names can be suffixed by `_FILE` to reference a file instead of a value.
More information [here]({{< ref "dns#configuration-and-credentials" >}}).
Expand Down
4 changes: 2 additions & 2 deletions providers/dns/acmedns/acmedns.go
Expand Up @@ -28,10 +28,10 @@ const (
type acmeDNSClient interface {
// UpdateTXTRecord updates the provided account's TXT record
// to the given value or returns an error.
UpdateTXTRecord(goacmedns.Account, string) error
UpdateTXTRecord(account goacmedns.Account, value string) error
// RegisterAccount registers and returns a new account
// with the given allowFrom restriction or returns an error.
RegisterAccount([]string) (goacmedns.Account, error)
RegisterAccount(allowFrom []string) (goacmedns.Account, error)
}

// DNSProvider implements the challenge.Provider interface.
Expand Down
9 changes: 4 additions & 5 deletions providers/dns/autodns/autodns_test.go
Expand Up @@ -4,7 +4,6 @@ import (
"testing"

"github.com/go-acme/lego/v4/platform/tester"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -133,10 +132,10 @@ func TestLivePresent(t *testing.T) {

envTest.RestoreEnv()
provider, err := NewDNSProvider()
assert.NoError(t, err)
require.NoError(t, err)

err = provider.Present(envTest.GetDomain(), "", "123d==")
assert.NoError(t, err)
require.NoError(t, err)
}

func TestLiveCleanUp(t *testing.T) {
Expand All @@ -146,8 +145,8 @@ func TestLiveCleanUp(t *testing.T) {

envTest.RestoreEnv()
provider, err := NewDNSProvider()
assert.NoError(t, err)
require.NoError(t, err)

err = provider.CleanUp(envTest.GetDomain(), "", "123d==")
assert.NoError(t, err)
require.NoError(t, err)
}
5 changes: 3 additions & 2 deletions providers/dns/brandit/internal/client.go
Expand Up @@ -11,6 +11,7 @@ import (
"io"
"net/http"
"net/url"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -58,7 +59,7 @@ func (c *Client) ListRecords(ctx context.Context, account, dnsZone string) (*Lis
}

for len(result.Response.RR) < result.Response.Total[0] {
query.Add("first", fmt.Sprint(result.Response.Last[0]+1))
query.Add("first", strconv.Itoa(result.Response.Last[0]+1))

tmp := &Response[*ListRecordsResponse]{}
err := c.do(ctx, query, tmp)
Expand All @@ -76,7 +77,7 @@ func (c *Client) ListRecords(ctx context.Context, account, dnsZone string) (*Lis
// AddRecord adds a DNS record.
// https://portal.brandit.com/apidocv3#addDNSRR
func (c *Client) AddRecord(ctx context.Context, domainName, account, newRecordID string, record Record) (*AddRecord, error) {
value := strings.Join([]string{record.Name, fmt.Sprint(record.TTL), "IN", record.Type, record.Content}, " ")
value := strings.Join([]string{record.Name, strconv.Itoa(record.TTL), "IN", record.Type, record.Content}, " ")

query := url.Values{}
query.Add("command", "addDNSRR")
Expand Down
9 changes: 4 additions & 5 deletions providers/dns/checkdomain/checkdomain_test.go
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/go-acme/lego/v4/platform/tester"
"github.com/go-acme/lego/v4/providers/dns/checkdomain/internal"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -110,10 +109,10 @@ func TestLivePresent(t *testing.T) {

envTest.RestoreEnv()
provider, err := NewDNSProvider()
assert.NoError(t, err)
require.NoError(t, err)

err = provider.Present(envTest.GetDomain(), "", "123d==")
assert.NoError(t, err)
require.NoError(t, err)
}

func TestLiveCleanUp(t *testing.T) {
Expand All @@ -123,8 +122,8 @@ func TestLiveCleanUp(t *testing.T) {

envTest.RestoreEnv()
provider, err := NewDNSProvider()
assert.NoError(t, err)
require.NoError(t, err)

err = provider.CleanUp(envTest.GetDomain(), "", "123d==")
assert.NoError(t, err)
require.NoError(t, err)
}
4 changes: 2 additions & 2 deletions providers/dns/dns_providers_test.go
Expand Up @@ -29,12 +29,12 @@ func TestKnownDNSProviderError(t *testing.T) {
envTest.ClearEnv()

provider, err := NewDNSChallengeProviderByName("exec")
assert.Error(t, err)
require.Error(t, err)
assert.Nil(t, provider)
}

func TestUnknownDNSProvider(t *testing.T) {
provider, err := NewDNSChallengeProviderByName("foobar")
assert.Error(t, err)
require.Error(t, err)
assert.Nil(t, provider)
}
24 changes: 12 additions & 12 deletions providers/dns/dreamhost/dreamhost_test.go
Expand Up @@ -121,12 +121,12 @@ func TestDNSProvider_Present(t *testing.T) {
assert.Equal(t, http.MethodGet, r.Method, "method")

q := r.URL.Query()
assert.Equal(t, q.Get("key"), fakeAPIKey)
assert.Equal(t, q.Get("cmd"), "dns-add_record")
assert.Equal(t, q.Get("format"), "json")
assert.Equal(t, q.Get("record"), "_acme-challenge.example.com")
assert.Equal(t, q.Get("value"), fakeKeyAuth)
assert.Equal(t, q.Get("comment"), "Managed+By+lego")
assert.Equal(t, fakeAPIKey, q.Get("key"))
assert.Equal(t, "dns-add_record", q.Get("cmd"))
assert.Equal(t, "json", q.Get("format"))
assert.Equal(t, "_acme-challenge.example.com", q.Get("record"))
assert.Equal(t, fakeKeyAuth, q.Get("value"))
assert.Equal(t, "Managed+By+lego", q.Get("comment"))

_, err := fmt.Fprintf(w, `{"data":"record_added","result":"success"}`)
if err != nil {
Expand Down Expand Up @@ -163,12 +163,12 @@ func TestDNSProvider_Cleanup(t *testing.T) {
assert.Equal(t, http.MethodGet, r.Method, "method")

q := r.URL.Query()
assert.Equal(t, q.Get("key"), fakeAPIKey, "key mismatch")
assert.Equal(t, q.Get("cmd"), "dns-remove_record", "cmd mismatch")
assert.Equal(t, q.Get("format"), "json")
assert.Equal(t, q.Get("record"), "_acme-challenge.example.com")
assert.Equal(t, q.Get("value"), fakeKeyAuth, "value mismatch")
assert.Equal(t, q.Get("comment"), "Managed+By+lego")
assert.Equal(t, fakeAPIKey, q.Get("key"), "key mismatch")
assert.Equal(t, "dns-remove_record", q.Get("cmd"), "cmd mismatch")
assert.Equal(t, "json", q.Get("format"))
assert.Equal(t, "_acme-challenge.example.com", q.Get("record"))
assert.Equal(t, fakeKeyAuth, q.Get("value"), "value mismatch")
assert.Equal(t, "Managed+By+lego", q.Get("comment"))

_, err := fmt.Fprintf(w, `{"data":"record_removed","result":"success"}`)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions providers/dns/edgedns/edgedns_integration_test.go
Expand Up @@ -78,9 +78,9 @@ func TestLiveTTL(t *testing.T) {
}

t.Run(fmt.Sprintf("testing record set %d", i), func(t *testing.T) {
assert.Equal(t, rrset.Name, fqdn)
assert.Equal(t, rrset.Type, "TXT")
assert.Equal(t, rrset.TTL, dns01.DefaultTTL)
assert.Equal(t, fqdn, rrset.Name)
assert.Equal(t, "TXT", rrset.Type)
assert.Equal(t, dns01.DefaultTTL, rrset.TTL)
})
}
}
6 changes: 3 additions & 3 deletions providers/dns/epik/internal/client_test.go
Expand Up @@ -94,7 +94,7 @@ func TestClient_GetDNSRecords_error(t *testing.T) {
mux.HandleFunc("/domains/example.com/records", testHandler(http.MethodGet, http.StatusUnauthorized, "error.json"))

_, err := client.GetDNSRecords(context.Background(), "example.com")
assert.Error(t, err)
require.Error(t, err)
}

func TestClient_CreateHostRecord(t *testing.T) {
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestClient_CreateHostRecord_error(t *testing.T) {
}

_, err := client.CreateHostRecord(context.Background(), "example.com", record)
assert.Error(t, err)
require.Error(t, err)
}

func TestClient_RemoveHostRecord(t *testing.T) {
Expand All @@ -160,7 +160,7 @@ func TestClient_RemoveHostRecord_error(t *testing.T) {
mux.HandleFunc("/domains/example.com/records", testHandler(http.MethodDelete, http.StatusUnauthorized, "error.json"))

_, err := client.RemoveHostRecord(context.Background(), "example.com", "abc123")
assert.Error(t, err)
require.Error(t, err)
}

func testHandler(method string, statusCode int, filename string) http.HandlerFunc {
Expand Down
1 change: 0 additions & 1 deletion providers/dns/gcloud/googlecloud_test.go
Expand Up @@ -391,7 +391,6 @@ func TestLivePresent(t *testing.T) {
}

envTest.RestoreEnv()

provider, err := NewDNSProviderCredentials(envTest.GetValue(EnvProject))
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion providers/dns/internal/selectel/client_test.go
Expand Up @@ -78,7 +78,7 @@ func TestClient_ListRecords_error(t *testing.T) {

records, err := client.ListRecords(context.Background(), 123)

assert.EqualError(t, err, "request failed with status code 401: API error: 400 - error description - field that the error occurred in")
require.EqualError(t, err, "request failed with status code 401: API error: 400 - error description - field that the error occurred in")
assert.Nil(t, records)
}

Expand Down

0 comments on commit d51b5e4

Please sign in to comment.