chore: update linter. (#997)

This commit is contained in:
Ludovic Fernandez 2019-10-25 01:27:40 +02:00 committed by GitHub
parent 8afde164a1
commit 635b9ac93d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 23 additions and 44 deletions

View file

@ -29,7 +29,10 @@
"dupl", "dupl",
"prealloc", "prealloc",
"scopelint", "scopelint",
"bodyclose", # https://github.com/timakin/bodyclose/pull/14 "bodyclose",
"wsl",
"stylecheck",
"godox",
] ]
[issues] [issues]
@ -112,3 +115,6 @@
[[issues.exclude-rules]] [[issues.exclude-rules]]
path = "providers/dns/gandi/gandi.go" path = "providers/dns/gandi/gandi.go"
text = "Function 'Present' is too long" text = "Function 'Present' is too long"
[[issues.exclude-rules]]
path = "cmd/zz_gen_cmd_dnshelp.go"
linters = ["gocyclo", "funlen"]

View file

@ -88,3 +88,5 @@ deploy:
local_dir: docs/public local_dir: docs/public
skip_cleanup: true skip_cleanup: true
github_token: ${GITHUB_TOKEN} github_token: ${GITHUB_TOKEN}
on:
condition: $STABLE = true

View file

@ -120,7 +120,6 @@ func (d *Doer) formatUserAgent() string {
func checkError(req *http.Request, resp *http.Response) error { func checkError(req *http.Request, resp *http.Response) error {
if resp.StatusCode >= http.StatusBadRequest { if resp.StatusCode >= http.StatusBadRequest {
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
return fmt.Errorf("%d :: %s :: %s :: %v", resp.StatusCode, req.Method, req.URL, err) return fmt.Errorf("%d :: %s :: %s :: %v", resp.StatusCode, req.Method, req.URL, err)

View file

@ -44,7 +44,6 @@ func TestDo_UserAgentOnAllHTTPMethod(t *testing.T) {
for _, test := range testCases { for _, test := range testCases {
t.Run(test.method, func(t *testing.T) { t.Run(test.method, func(t *testing.T) {
_, err := test.call(ts.URL) _, err := test.call(ts.URL)
require.NoError(t, err) require.NoError(t, err)

View file

@ -93,7 +93,6 @@ func TestChallenge_PreSolve(t *testing.T) {
for _, test := range testCases { for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {
chlg := NewChallenge(core, test.validate, test.provider, WrapPreCheck(test.preCheck)) chlg := NewChallenge(core, test.validate, test.provider, WrapPreCheck(test.preCheck))
authz := acme.Authorization{ authz := acme.Authorization{
@ -178,7 +177,6 @@ func TestChallenge_Solve(t *testing.T) {
for _, test := range testCases { for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {
var options []ChallengeOption var options []ChallengeOption
if test.preCheck != nil { if test.preCheck != nil {
options = append(options, WrapPreCheck(test.preCheck)) options = append(options, WrapPreCheck(test.preCheck))
@ -266,7 +264,6 @@ func TestChallenge_CleanUp(t *testing.T) {
for _, test := range testCases { for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {
chlg := NewChallenge(core, test.validate, test.provider, WrapPreCheck(test.preCheck)) chlg := NewChallenge(core, test.validate, test.provider, WrapPreCheck(test.preCheck))
authz := acme.Authorization{ authz := acme.Authorization{

View file

@ -188,7 +188,6 @@ func TestResolveConfServers(t *testing.T) {
for _, test := range testCases { for _, test := range testCases {
t.Run(test.fixture, func(t *testing.T) { t.Run(test.fixture, func(t *testing.T) {
result := getNameservers(test.fixture, test.defaults) result := getNameservers(test.fixture, test.defaults)
sort.Strings(result) sort.Strings(result)

View file

@ -78,8 +78,8 @@ func (m *forwardedMatcher) matches(r *http.Request, domain string) bool {
if err != nil { if err != nil {
return false return false
} }
if len(fwds) == 0 {
if len(fwds) == 0 {
return false return false
} }

View file

@ -110,7 +110,6 @@ func Test_needRenewal(t *testing.T) {
for _, test := range testCases { for _, test := range testCases {
test := test test := test
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {
actual := needRenewal(test.x509Cert, "foo.com", test.days) actual := needRenewal(test.x509Cert, "foo.com", test.days)
assert.Equal(t, test.expected, actual) assert.Equal(t, test.expected, actual)

View file

@ -84,7 +84,6 @@ func displayDNSHelp(name string) error {
ew := &errWriter{w: w} ew := &errWriter{w: w}
switch name { switch name {
case "acme-dns": case "acme-dns":
// generated from: providers/dns/acmedns/acmedns.toml // generated from: providers/dns/acmedns/acmedns.toml
ew.writeln(`Configuration for Joohoi's ACME-DNS.`) ew.writeln(`Configuration for Joohoi's ACME-DNS.`)

View file

@ -27,7 +27,7 @@ func displayDNSHelp(name string) error {
ew := &errWriter{w: w} ew := &errWriter{w: w}
switch name { switch name {
{{ range $provider := .Providers }} {{- range $provider := .Providers }}
case "{{ $provider.Code }}": case "{{ $provider.Code }}":
// generated from: {{ .GeneratedFrom }} // generated from: {{ .GeneratedFrom }}
ew.writeln(`Configuration for {{ $provider.Name }}.`) ew.writeln(`Configuration for {{ $provider.Name }}.`)

View file

@ -304,7 +304,6 @@ func TestGetOrFile_ReadsFiles(t *testing.T) {
for _, test := range testCases { for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {
err := os.Unsetenv(varEnvFileName) err := os.Unsetenv(varEnvFileName)
require.NoError(t, err) require.NoError(t, err)
err = os.Unsetenv(varEnvName) err = os.Unsetenv(varEnvName)

View file

@ -95,7 +95,7 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
func (d *DNSProvider) Present(domain, token, keyAuth string) error { func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth) fqdn, value := dns01.GetRecord(domain, keyAuth)
_, zoneName, err := d.getHostedZone(domain) zoneName, err := d.getHostedZone(domain)
if err != nil { if err != nil {
return fmt.Errorf("alicloud: %v", err) return fmt.Errorf("alicloud: %v", err)
} }
@ -118,7 +118,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
return fmt.Errorf("alicloud: %v", err) return fmt.Errorf("alicloud: %v", err)
} }
_, _, err = d.getHostedZone(domain) _, err = d.getHostedZone(domain)
if err != nil { if err != nil {
return fmt.Errorf("alicloud: %v", err) return fmt.Errorf("alicloud: %v", err)
} }
@ -134,7 +134,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
return nil return nil
} }
func (d *DNSProvider) getHostedZone(domain string) (string, string, error) { func (d *DNSProvider) getHostedZone(domain string) (string, error) {
request := alidns.CreateDescribeDomainsRequest() request := alidns.CreateDescribeDomainsRequest()
var domains []alidns.Domain var domains []alidns.Domain
@ -145,7 +145,7 @@ func (d *DNSProvider) getHostedZone(domain string) (string, string, error) {
response, err := d.client.DescribeDomains(request) response, err := d.client.DescribeDomains(request)
if err != nil { if err != nil {
return "", "", fmt.Errorf("API call failed: %v", err) return "", fmt.Errorf("API call failed: %v", err)
} }
domains = append(domains, response.Domains.Domain...) domains = append(domains, response.Domains.Domain...)
@ -159,7 +159,7 @@ func (d *DNSProvider) getHostedZone(domain string) (string, string, error) {
authZone, err := dns01.FindZoneByFqdn(dns01.ToFqdn(domain)) authZone, err := dns01.FindZoneByFqdn(dns01.ToFqdn(domain))
if err != nil { if err != nil {
return "", "", err return "", err
} }
var hostedZone alidns.Domain var hostedZone alidns.Domain
@ -170,9 +170,10 @@ func (d *DNSProvider) getHostedZone(domain string) (string, string, error) {
} }
if hostedZone.DomainId == "" { if hostedZone.DomainId == "" {
return "", "", fmt.Errorf("zone %s not found in AliDNS for domain %s", authZone, domain) return "", fmt.Errorf("zone %s not found in AliDNS for domain %s", authZone, domain)
} }
return fmt.Sprintf("%v", hostedZone.DomainId), hostedZone.DomainName, nil
return hostedZone.DomainName, nil
} }
func (d *DNSProvider) newTxtRecord(zone, fqdn, value string) *alidns.AddDomainRecordRequest { func (d *DNSProvider) newTxtRecord(zone, fqdn, value string) *alidns.AddDomainRecordRequest {
@ -186,7 +187,7 @@ func (d *DNSProvider) newTxtRecord(zone, fqdn, value string) *alidns.AddDomainRe
} }
func (d *DNSProvider) findTxtRecords(domain, fqdn string) ([]alidns.Record, error) { func (d *DNSProvider) findTxtRecords(domain, fqdn string) ([]alidns.Record, error) {
_, zoneName, err := d.getHostedZone(domain) zoneName, err := d.getHostedZone(domain)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -106,7 +106,6 @@ func TestClientGetDomainInformation(t *testing.T) {
for _, test := range testCases { for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {
server := httptest.NewServer(handlerMock(http.MethodGet, test.response, test.data)) server := httptest.NewServer(handlerMock(http.MethodGet, test.response, test.data))
client, _ := NewClient("myKey", "mySecret") client, _ := NewClient("myKey", "mySecret")
@ -210,7 +209,6 @@ func TestClientFindTxtRecord(t *testing.T) {
for _, test := range testCases { for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {
server := httptest.NewServer(handlerMock(http.MethodGet, test.response, test.txtRecords)) server := httptest.NewServer(handlerMock(http.MethodGet, test.response, test.txtRecords))
client, _ := NewClient("myKey", "mySecret") client, _ := NewClient("myKey", "mySecret")

View file

@ -136,7 +136,6 @@ func TestClient_GetDomainID(t *testing.T) {
} }
}) })
} }
} }
func TestClient_CreateRecord(t *testing.T) { func TestClient_CreateRecord(t *testing.T) {
@ -203,8 +202,6 @@ func TestClient_CreateRecord(t *testing.T) {
} else { } else {
require.NoError(t, err) require.NoError(t, err)
} }
}) })
} }
} }

View file

@ -112,7 +112,6 @@ func TestNewDNSProviderConfig(t *testing.T) {
if test.baseURL != "" { if test.baseURL != "" {
assert.Equal(t, test.baseURL, p.client.BaseURL) assert.Equal(t, test.baseURL, p.client.BaseURL)
} }
} else { } else {
require.EqualError(t, err, test.expected) require.EqualError(t, err, test.expected)
} }

View file

@ -237,7 +237,7 @@ func TestDNSProvider_Cleanup_WhenHttpError_ReturnsError(t *testing.T) {
assert.Equal(t, "Basic VE9LRU46U0VDUkVU", r.Header.Get("Authorization"), "Authorization") assert.Equal(t, "Basic VE9LRU46U0VDUkVU", r.Header.Get("Authorization"), "Authorization")
w.WriteHeader(http.StatusNotAcceptable) w.WriteHeader(http.StatusNotAcceptable)
_, err := fmt.Fprintf(w, errorMessage) _, err := fmt.Fprint(w, errorMessage)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
} }

View file

@ -199,7 +199,6 @@ func TestSplitDomain(t *testing.T) {
assert.Equal(t, test.expectedZone, zone) assert.Equal(t, test.expectedZone, zone)
}) })
} }
} }
func TestLivePresent(t *testing.T) { func TestLivePresent(t *testing.T) {

View file

@ -485,7 +485,6 @@ func Test_addTxtEntryToZone(t *testing.T) {
for _, test := range testCases { for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {
zone := addTxtEntryToZone(test.input, "_acme-challenge", "test", 120) zone := addTxtEntryToZone(test.input, "_acme-challenge", "test", 120)
assert.Equal(t, zone, test.expected) assert.Equal(t, zone, test.expected)
}) })
@ -527,7 +526,6 @@ func Test_fixTxtLines(t *testing.T) {
for _, test := range testCases { for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {
line := fixTxtLines(test.input) line := fixTxtLines(test.input)
assert.Equal(t, line, test.expected) assert.Equal(t, line, test.expected)
}) })

View file

@ -209,7 +209,6 @@ func TestDNSProvider_Present(t *testing.T) {
for _, test := range testCases { for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {
server := newMockServer(test.mockResponses) server := newMockServer(test.mockResponses)
defer server.Close() defer server.Close()

View file

@ -226,7 +226,6 @@ func (c *Client) GetDNSRecords(hostname, apiSessionID string) ([]DNSRecord, erro
} }
return responseData.DNSRecords, nil return responseData.DNSRecords, nil
} }
// doRequest marshals given body to JSON, send the request to netcup API // doRequest marshals given body to JSON, send the request to netcup API

View file

@ -515,7 +515,6 @@ func TestLiveClientAuth(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
}) })
} }
} }
func TestLiveClientGetDnsRecords(t *testing.T) { func TestLiveClientGetDnsRecords(t *testing.T) {

View file

@ -81,7 +81,6 @@ func TestChangeResourceRecordSetsErrors(t *testing.T) {
for _, test := range testCases { for _, test := range testCases {
test := test test := test
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {
server := runTestServer(test.responseBody, test.statusCode) server := runTestServer(test.responseBody, test.statusCode)
defer server.Close() defer server.Close()
@ -161,7 +160,6 @@ func TestGetChangeErrors(t *testing.T) {
for _, test := range testCases { for _, test := range testCases {
test := test test := test
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {
server := runTestServer(test.responseBody, test.statusCode) server := runTestServer(test.responseBody, test.statusCode)
defer server.Close() defer server.Close()
@ -175,5 +173,4 @@ func TestGetChangeErrors(t *testing.T) {
assert.EqualError(t, err, test.expected) assert.EqualError(t, err, test.expected)
}) })
} }
} }

View file

@ -79,7 +79,6 @@ func (m *DNSServerMock) HandleListZonesSuccessfully() {
"id":"123123" "id":"123123"
}]} }]}
`) `)
}) })
} }

View file

@ -98,7 +98,6 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
token: identity.Access.Token.ID, token: identity.Access.Token.ID,
cloudDNSEndpoint: dnsEndpoint, cloudDNSEndpoint: dnsEndpoint,
}, nil }, nil
} }
// Present creates a TXT record to fulfill the dns-01 challenge // Present creates a TXT record to fulfill the dns-01 challenge

View file

@ -180,9 +180,7 @@ func (c *Client) do(req *http.Request, to interface{}) (*http.Response, error) {
} }
func checkResponse(resp *http.Response) error { func checkResponse(resp *http.Response) error {
if resp.StatusCode >= http.StatusBadRequest && if resp.StatusCode >= http.StatusBadRequest && resp.StatusCode <= http.StatusNetworkAuthenticationRequired {
resp.StatusCode <= http.StatusNetworkAuthenticationRequired {
if resp.Body == nil { if resp.Body == nil {
return fmt.Errorf("request failed with status code %d and empty body", resp.StatusCode) return fmt.Errorf("request failed with status code %d and empty body", resp.StatusCode)
} }

View file

@ -180,9 +180,7 @@ func (c *Client) do(req *http.Request, to interface{}) (*http.Response, error) {
} }
func checkResponse(resp *http.Response) error { func checkResponse(resp *http.Response) error {
if resp.StatusCode >= http.StatusBadRequest && if resp.StatusCode >= http.StatusBadRequest && resp.StatusCode <= http.StatusNetworkAuthenticationRequired {
resp.StatusCode <= http.StatusNetworkAuthenticationRequired {
if resp.Body == nil { if resp.Body == nil {
return fmt.Errorf("request failed with status code %d and empty body", resp.StatusCode) return fmt.Errorf("request failed with status code %d and empty body", resp.StatusCode)
} }