diff --git a/.golangci.yml b/.golangci.yml index 4be53bd71..9eed09601 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -14,6 +14,7 @@ linters: - staticcheck - unconvert - unused + - usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library. https://golangci-lint.run/usage/linters/#usestdlibvars - whitespace - decorder # Check declaration order and count of types, constants, variables and functions. https://golangci-lint.run/usage/linters/#decorder - tagalign # Check that struct tags are well aligned. https://golangci-lint.run/usage/linters/#tagalign diff --git a/provider/godaddy/client.go b/provider/godaddy/client.go index 4104087ec..2efb7824d 100644 --- a/provider/godaddy/client.go +++ b/provider/godaddy/client.go @@ -243,7 +243,7 @@ func (c *Client) Do(req *http.Request) (*http.Response, error) { return nil, err } // In case of several clients behind NAT we still can hit rate limit - for i := 1; i < 3 && resp != nil && resp.StatusCode == 429; i++ { + for i := 1; i < 3 && resp != nil && resp.StatusCode == http.StatusTooManyRequests; i++ { retryAfter, err := strconv.ParseInt(resp.Header.Get("Retry-After"), 10, 0) if err != nil { log.Error("Rate-limited response did not contain a valid Retry-After header, quota likely exceeded") diff --git a/provider/ibmcloud/ibmcloud_test.go b/provider/ibmcloud/ibmcloud_test.go index 6c94db504..599b1158a 100644 --- a/provider/ibmcloud/ibmcloud_test.go +++ b/provider/ibmcloud/ibmcloud_test.go @@ -32,6 +32,7 @@ import ( . "github.com/onsi/ginkgo" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "sigs.k8s.io/external-dns/endpoint" "sigs.k8s.io/external-dns/plan" "sigs.k8s.io/external-dns/provider" @@ -393,7 +394,7 @@ func TestPublicConfig_Validate(t *testing.T) { // Set mock response res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) + res.WriteHeader(http.StatusOK) fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": [{"id": "123", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "name": "example.com", "original_registrar": "GoDaddy", "original_dnshost": "NameCheap", "status": "active", "paused": false, "original_name_servers": ["ns1.originaldnshost.com"], "name_servers": ["ns001.name.cloud.ibm.com"]}], "result_info": {"page": 1, "per_page": 20, "count": 1, "total_count": 2000}}`) })) zoneIDFilterTest := provider.NewZoneIDFilter([]string{"123"}) diff --git a/provider/pihole/clientV6_test.go b/provider/pihole/clientV6_test.go index ba1403821..3a5b00545 100644 --- a/provider/pihole/clientV6_test.go +++ b/provider/pihole/clientV6_test.go @@ -114,7 +114,7 @@ func TestNewPiholeClientV6(t *testing.T) { // Create a test server srvr := newTestServerV6(t, func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path == "/api/auth" && r.Method == "POST" { + if r.URL.Path == "/api/auth" && r.Method == http.MethodPost { var requestData map[string]string json.NewDecoder(r.Body).Decode(&requestData) defer r.Body.Close() @@ -178,7 +178,7 @@ func TestNewPiholeClientV6(t *testing.T) { func TestListRecordsV6(t *testing.T) { // Create a test server srvr := newTestServerV6(t, func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path == "/api/config/dns/hosts" && r.Method == "GET" { + if r.URL.Path == "/api/config/dns/hosts" && r.Method == http.MethodGet { w.WriteHeader(http.StatusOK) w.Header().Set("Content-Type", "application/json") @@ -201,7 +201,7 @@ func TestListRecordsV6(t *testing.T) { }, "took": 5 }`)) - } else if r.URL.Path == "/api/config/dns/cnameRecords" && r.Method == "GET" { + } else if r.URL.Path == "/api/config/dns/cnameRecords" && r.Method == http.MethodGet { w.WriteHeader(http.StatusOK) w.Header().Set("Content-Type", "application/json") @@ -373,7 +373,7 @@ func TestErrorsV6(t *testing.T) { // bad record format return by server srvrErr := newTestServerV6(t, func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path == "/api/config/dns/hosts" && r.Method == "GET" { + if r.URL.Path == "/api/config/dns/hosts" && r.Method == http.MethodGet { w.WriteHeader(http.StatusOK) w.Header().Set("Content-Type", "application/json") @@ -388,7 +388,7 @@ func TestErrorsV6(t *testing.T) { }, "took": 5 }`)) - } else if r.URL.Path == "/api/config/dns/cnameRecords" && r.Method == "GET" { + } else if r.URL.Path == "/api/config/dns/cnameRecords" && r.Method == http.MethodGet { w.WriteHeader(http.StatusOK) w.Header().Set("Content-Type", "application/json") @@ -439,7 +439,7 @@ func TestErrorsV6(t *testing.T) { func TestTokenValidity(t *testing.T) { srvok := newTestServerV6(t, func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path == "/api/auth" && r.Method == "GET" { + if r.URL.Path == "/api/auth" && r.Method == http.MethodGet { w.WriteHeader(http.StatusOK) w.Header().Set("Content-Type", "application/json") @@ -475,7 +475,7 @@ func TestTokenValidity(t *testing.T) { // Create a test server srvr := newTestServerV6(t, func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path == "/api/auth" && r.Method == "GET" { + if r.URL.Path == "/api/auth" && r.Method == http.MethodGet { w.WriteHeader(http.StatusOK) w.Header().Set("Content-Type", "application/json") @@ -527,7 +527,7 @@ func TestTokenValidity(t *testing.T) { func TestDo(t *testing.T) { srvDo := newTestServerV6(t, func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path == "/api/auth/ok" && r.Method == "GET" { + if r.URL.Path == "/api/auth/ok" && r.Method == http.MethodGet { w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) // Return bad content @@ -542,7 +542,7 @@ func TestDo(t *testing.T) { }, "took": 0.16 }`)) - } else if r.URL.Path == "/api/auth" && r.Method == "POST" { + } else if r.URL.Path == "/api/auth" && r.Method == http.MethodPost { w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) // Return bad content @@ -557,7 +557,7 @@ func TestDo(t *testing.T) { }, "took": 0.15 }`)) - } else if r.URL.Path == "/api/auth" && r.Method == "GET" { + } else if r.URL.Path == "/api/auth" && r.Method == http.MethodGet { w.WriteHeader(http.StatusUnauthorized) // Return bad content w.Write([]byte(`{ @@ -568,7 +568,7 @@ func TestDo(t *testing.T) { }, "took": 0.14 }`)) - } else if r.URL.Path == "/api/auth/418" && r.Method == "GET" { + } else if r.URL.Path == "/api/auth/418" && r.Method == http.MethodGet { w.WriteHeader(http.StatusTeapot) // Return bad content w.Write([]byte(`{ @@ -579,11 +579,11 @@ func TestDo(t *testing.T) { }, "took": 0.13 }`)) - } else if r.URL.Path == "/api/auth/nojson" && r.Method == "GET" { + } else if r.URL.Path == "/api/auth/nojson" && r.Method == http.MethodGet { // Return bad content w.WriteHeader(http.StatusTeapot) w.Write([]byte(`Not a JSON`)) - } else if r.URL.Path == "/api/auth/401" && r.Method == "GET" { + } else if r.URL.Path == "/api/auth/401" && r.Method == http.MethodGet { w.WriteHeader(http.StatusUnauthorized) // Return bad content w.Write([]byte(`{ @@ -655,7 +655,7 @@ func TestDo(t *testing.T) { func TestDoRetryOne(t *testing.T) { nbCall := 0 srvRetry := newTestServerV6(t, func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path == "/api/auth" && r.Method == "GET" { + if r.URL.Path == "/api/auth" && r.Method == http.MethodGet { w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) // Return bad content @@ -670,7 +670,7 @@ func TestDoRetryOne(t *testing.T) { }, "took": 0.24 }`)) - } else if r.URL.Path == "/api/auth/401" && r.Method == "GET" { + } else if r.URL.Path == "/api/auth/401" && r.Method == http.MethodGet { if nbCall == 0 { w.WriteHeader(http.StatusUnauthorized) // Return bad content @@ -713,7 +713,7 @@ func TestDoRetryOne(t *testing.T) { func TestCreateRecordV6(t *testing.T) { var ep *endpoint.Endpoint srvr := newTestServerV6(t, func(w http.ResponseWriter, r *http.Request) { - if r.Method == "PUT" && (r.URL.Path == "/api/config/dns/hosts/192.168.1.1 test.example.com" || + if r.Method == http.MethodPut && (r.URL.Path == "/api/config/dns/hosts/192.168.1.1 test.example.com" || r.URL.Path == "/api/config/dns/hosts/fc00::1:192:168:1:1 test.example.com" || r.URL.Path == "/api/config/dns/cnameRecords/source1.example.com,target1.domain.com" || r.URL.Path == "/api/config/dns/cnameRecords/source2.example.com,target2.domain.com,500") { @@ -846,7 +846,7 @@ func TestCreateRecordV6(t *testing.T) { func TestDeleteRecordV6(t *testing.T) { var ep *endpoint.Endpoint srvr := newTestServerV6(t, func(w http.ResponseWriter, r *http.Request) { - if r.Method == "DELETE" && (r.URL.Path == "/api/config/dns/hosts/192.168.1.1 test.example.com" || + if r.Method == http.MethodDelete && (r.URL.Path == "/api/config/dns/hosts/192.168.1.1 test.example.com" || r.URL.Path == "/api/config/dns/hosts/fc00::1:192:168:1:1 test.example.com" || r.URL.Path == "/api/config/dns/cnameRecords/source1.example.com,target1.domain.com" || r.URL.Path == "/api/config/dns/cnameRecords/source2.example.com,target2.domain.com,500") { diff --git a/provider/webhook/webhook_test.go b/provider/webhook/webhook_test.go index f4a0ea390..bb73e5ceb 100644 --- a/provider/webhook/webhook_test.go +++ b/provider/webhook/webhook_test.go @@ -28,6 +28,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "sigs.k8s.io/external-dns/endpoint" "sigs.k8s.io/external-dns/plan" "sigs.k8s.io/external-dns/provider" @@ -87,7 +88,7 @@ func TestInvalidDomainFilter(t *testing.T) { svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/" { w.Header().Set(webhookapi.ContentTypeHeader, webhookapi.MediaTypeFormatAndVersion) - w.WriteHeader(200) + w.WriteHeader(http.StatusOK) return } w.Write([]byte(`[{ diff --git a/source/skipper_routegroup.go b/source/skipper_routegroup.go index 601055383..2610dcd48 100644 --- a/source/skipper_routegroup.go +++ b/source/skipper_routegroup.go @@ -164,7 +164,7 @@ func (cli *routeGroupClient) getRouteGroupList(url string) (*routeGroupList, err } defer resp.Body.Close() - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("failed to get routegroup list from %s, got: %s", url, resp.Status) } @@ -178,7 +178,7 @@ func (cli *routeGroupClient) getRouteGroupList(url string) (*routeGroupList, err } func (cli *routeGroupClient) get(url string) (*http.Response, error) { - req, err := http.NewRequest("GET", url, nil) + req, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { return nil, err }