Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task: update golangci lint #213

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: lint
uses: golangci/[email protected]
with:
version: v1.52.2
version: v1.54.2

tests-on-unix:
needs: golangci-lint # run after golangci-lint action to not produce duplicated errors
Expand Down
5 changes: 1 addition & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ linters-settings:
min-complexity: 15
govet:
check-shadowing: true
maligned:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this linter is not enabled

suggest-new: true
tagliatelle:
# check the struck tag name case
case:
Expand Down Expand Up @@ -65,7 +63,6 @@ linters:
disable-all: true
enable:
- bodyclose # checks whether HTTP response body is closed successfully [fast: false, auto-fix: false]
- depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: false, auto-fix: false]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused and now fails if the allowed list is not defined

- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) [fast: true, auto-fix: false]
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases [fast: false, auto-fix: false]
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. [fast: false, auto-fix: false]
Expand Down Expand Up @@ -101,6 +98,7 @@ linters:
- unparam # Reports unused function parameters [fast: false, auto-fix: false]
- unused # Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false]
- usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library. [fast: true, auto-fix: false]
- wastedassign # wastedassign finds wasted assignment statements. [fast: false, auto-fix: false]
- whitespace # Tool for detection of leading and trailing whitespace [fast: true, auto-fix: true]

# don't enable:
Expand Down Expand Up @@ -163,7 +161,6 @@ linters:
# - tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes [fast: false, auto-fix: false]
# - varcheck # [deprecated] Finds unused global variables and constants [fast: false, auto-fix: false]
# - varnamelen # checks that the length of a variable's name matches its scope [fast: false, auto-fix: false]
# - wastedassign # wastedassign finds wasted assignment statements. [fast: false, auto-fix: false]
# - wrapcheck # Checks that errors returned from external packages are wrapped [fast: false, auto-fix: false]
# - wsl # Whitespace Linter - Forces you to use empty lines! [fast: true, auto-fix: false]
run:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# A Self-Documenting Makefile: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html

SOURCE_FILES?=./...
GOLANGCI_VERSION=v1.52.2
GOLANGCI_VERSION=v1.54.2
COVERAGE=coverage.out

export PATH := ./bin:$(PATH)
Expand Down
2 changes: 1 addition & 1 deletion opsmngr/agents_api_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/go-test/deep"
)

const projectID = "5e66185d917b220fbd8bb4d1"
const projectID = "5e66185d917b220fbd8bb4d1" //nolint:gosec // not a credential

func TestAgentsServiceOp_ListAgentAPIKeys(t *testing.T) {
client, mux, teardown := setup()
Expand Down
33 changes: 16 additions & 17 deletions opsmngr/alert_configurations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import (
atlas "go.mongodb.org/atlas/mongodbatlas"
)

const alertConfigID = "57b76ddc96e8215c017ceafb"
const alertConfigID = "57b76ddc96e8215c017ceafb" //nolint:gosec // not a credential

func TestAlertConfiguration_Create(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/groups/%s/alertConfigs", groupID), func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/groups/%s/alertConfigs", projectID), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)

expected := map[string]interface{}{
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestAlertConfiguration_Create(t *testing.T) {
},
}

alertConfiguration, _, err := client.AlertConfigurations.Create(ctx, groupID, alertReq)
alertConfiguration, _, err := client.AlertConfigurations.Create(ctx, projectID, alertReq)
if err != nil {
t.Fatalf("AlertConfiguration.Create returned error: %v", err)
return
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestAlertConfiguration_EnableAnAlertConfig(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/groups/%s/alertConfigs/%s", groupID, alertConfigID), func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/groups/%s/alertConfigs/%s", projectID, alertConfigID), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPatch)
expected := map[string]interface{}{
"enabled": true,
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestAlertConfiguration_EnableAnAlertConfig(t *testing.T) {
}`)
})

alertConfiguration, _, err := client.AlertConfigurations.EnableAnAlertConfig(ctx, groupID, alertConfigID, pointer(true))
alertConfiguration, _, err := client.AlertConfigurations.EnableAnAlertConfig(ctx, projectID, alertConfigID, pointer(true))
if err != nil {
t.Fatalf("AlertConfiguration.EnableAnAlertConfig returned error: %v", err)
}
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestAlertConfiguration_GetAnAlertConfig(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/groups/%s/alertConfigs/%s", groupID, alertConfigID), func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/groups/%s/alertConfigs/%s", projectID, alertConfigID), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{
"id": "533dc40ae4b00835ff81eaee",
Expand Down Expand Up @@ -233,7 +233,7 @@ func TestAlertConfiguration_GetAnAlertConfig(t *testing.T) {
}`)
})

alertConfiguration, _, err := client.AlertConfigurations.GetAnAlertConfig(ctx, groupID, alertConfigID)
alertConfiguration, _, err := client.AlertConfigurations.GetAnAlertConfig(ctx, projectID, alertConfigID)
if err != nil {
t.Fatalf("AlertConfigurations.GetAnAlertConfig returned error: %v", err)
}
Expand Down Expand Up @@ -279,7 +279,7 @@ func TestAlertConfiguration_GetOpenAlertsConfig(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/groups/%s/alertConfigs/%s/alerts", groupID, alertConfigID), func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/groups/%s/alertConfigs/%s/alerts", projectID, alertConfigID), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{
"totalCount": 2,
Expand Down Expand Up @@ -317,7 +317,7 @@ func TestAlertConfiguration_GetOpenAlertsConfig(t *testing.T) {
}`)
})

alertConfigurations, _, err := client.AlertConfigurations.GetOpenAlertsConfig(ctx, groupID, alertConfigID)
alertConfigurations, _, err := client.AlertConfigurations.GetOpenAlertsConfig(ctx, projectID, alertConfigID)
if err != nil {
t.Fatalf("AlertConfigurations.GetOpenAlertsConfig returned error: %v", err)
}
Expand Down Expand Up @@ -363,7 +363,7 @@ func TestAlertConfiguration_List(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/groups/%s/alertConfigs", groupID), func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/groups/%s/alertConfigs", projectID), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{
"results": [
Expand Down Expand Up @@ -434,7 +434,7 @@ func TestAlertConfiguration_List(t *testing.T) {
}`)
})

alertConfigurations, _, err := client.AlertConfigurations.List(ctx, groupID, nil)
alertConfigurations, _, err := client.AlertConfigurations.List(ctx, projectID, nil)
if err != nil {
t.Fatalf("AlertConfigurations.List returned error: %v", err)
}
Expand Down Expand Up @@ -513,7 +513,7 @@ func TestAlertConfiguration_Update(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/groups/%s/alertConfigs/%s", groupID, alertConfigID), func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/groups/%s/alertConfigs/%s", projectID, alertConfigID), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)

expected := map[string]interface{}{
Expand Down Expand Up @@ -576,7 +576,7 @@ func TestAlertConfiguration_Update(t *testing.T) {
},
}

alertConfiguration, _, err := client.AlertConfigurations.Update(ctx, groupID, alertConfigID, alertReq)
alertConfiguration, _, err := client.AlertConfigurations.Update(ctx, projectID, alertConfigID, alertReq)
if err != nil {
t.Fatalf("AlertConfiguration.Update returned error: %v", err)
return
Expand Down Expand Up @@ -610,11 +610,11 @@ func TestAlertConfiguration_Delete(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/groups/%s/alertConfigs/%s", groupID, alertConfigID), func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/groups/%s/alertConfigs/%s", projectID, alertConfigID), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodDelete)
})

_, err := client.AlertConfigurations.Delete(ctx, groupID, alertConfigID)
_, err := client.AlertConfigurations.Delete(ctx, projectID, alertConfigID)
if err != nil {
t.Fatalf("AlertConfigurations.Delete returned error: %v", err)
}
Expand All @@ -626,8 +626,7 @@ func TestAlertConfiguration_ListMatcherFields(t *testing.T) {

mux.HandleFunc("/api/public/v1.0/alertConfigs/matchers/fieldNames", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)

fmt.Fprint(w, `
_, _ = fmt.Fprint(w, `
[
"TYPE_NAME",
"HOSTNAME",
Expand Down
20 changes: 10 additions & 10 deletions opsmngr/alerts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ import (
atlas "go.mongodb.org/atlas/mongodbatlas"
)

const alertID = "57b76ddc96e8215c017ceafb"
const alertID = "57b76ddc96e8215c017ceafb" //nolint:gosec // not a credential

func TestAlert_Get(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/groups/%s/alerts/%s", groupID, alertID), func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/groups/%s/alerts/%s", projectID, alertID), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{
_, _ = fmt.Fprint(w, `{
"id": "533dc40ae4b00835ff81eaee",
"groupId": "535683b3794d371327b",
"eventTypeName": "OUTSIDE_METRIC_THRESHOLD",
Expand Down Expand Up @@ -63,7 +63,7 @@ func TestAlert_Get(t *testing.T) {
}`)
})

alert, _, err := client.Alerts.Get(ctx, groupID, alertID)
alert, _, err := client.Alerts.Get(ctx, projectID, alertID)
if err != nil {
t.Fatalf("Alerts.Get returned error: %v", err)
}
Expand Down Expand Up @@ -108,9 +108,9 @@ func TestAlerts_List(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/groups/%s/alerts", groupID), func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/groups/%s/alerts", projectID), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{
_, _ = fmt.Fprint(w, `{
"results": [
{
"id": "533dc40ae4b00835ff81eaee",
Expand Down Expand Up @@ -177,7 +177,7 @@ func TestAlerts_List(t *testing.T) {
}`)
})

alerts, _, err := client.Alerts.List(ctx, groupID, nil)
alerts, _, err := client.Alerts.List(ctx, projectID, nil)
if err != nil {
t.Fatalf("Alerts.List returned error: %v", err)
}
Expand Down Expand Up @@ -265,9 +265,9 @@ func TestAlert_Acknowledge(t *testing.T) {
AcknowledgementComment: "This is normal. Please ignore.",
}

mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/groups/%s/alerts/%s", groupID, alertID), func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/groups/%s/alerts/%s", projectID, alertID), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPatch)
fmt.Fprint(w, `{
_, _ = fmt.Fprint(w, `{
"id": "533dc40ae4b00835ff81eaee",
"groupId": "535683b3794d371327b",
"eventTypeName": "OUTSIDE_METRIC_THRESHOLD",
Expand All @@ -286,7 +286,7 @@ func TestAlert_Acknowledge(t *testing.T) {
}`)
})

alert, _, err := client.Alerts.Acknowledge(ctx, groupID, alertID, &params)
alert, _, err := client.Alerts.Acknowledge(ctx, projectID, alertID, &params)
if err != nil {
t.Fatalf("Alerts.Acknowledge returned error: %v", err)
}
Expand Down
31 changes: 16 additions & 15 deletions opsmngr/checkpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ import (
atlas "go.mongodb.org/atlas/mongodbatlas"
)

const clusterID = "6b8cd61180eef547110159d9"
const clusterID = "6b8cd61180eef547110159d9" //nolint:gosec // not a credential

func TestCheckpoints_List(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

path := fmt.Sprintf("/api/public/v1.0/groups/%s/clusters/%s/checkpoints", groupID, clusterID)
path := fmt.Sprintf("/api/public/v1.0/groups/%s/clusters/%s/checkpoints", projectID, clusterID)

mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{
_, _ = fmt.Fprintf(w, `{
"links":[
{
"href":"https://cloud.mongodb.com/api/public/v1.0/groups/5c8100bcf2a30b12ff88258f/clusters/Cluster0/checkpoints?pageNum=1&itemsPerPage=100",
Expand All @@ -44,7 +44,7 @@ func TestCheckpoints_List(t *testing.T) {
{
"clusterId":"6b8cd61180eef547110159d9",
"completed":"2018-02-08T23:20:25Z",
"groupId":"5c8100bcf2a30b12ff88258f",
"groupId":"%[1]s",
"id":"5a7cdb3980eef53de5bffdcf",
"links":[
{
Expand Down Expand Up @@ -90,7 +90,7 @@ func TestCheckpoints_List(t *testing.T) {
{
"clusterId":"6b8cd61180eef547110159d9",
"completed":"2018-02-09T14:50:33Z",
"groupId":"5c8100bcf2a30b12ff88258f",
"groupId":"%[1]s",
"id":"5a7db53987d9d64fe298ff46",
"links":[
{
Expand Down Expand Up @@ -136,10 +136,11 @@ func TestCheckpoints_List(t *testing.T) {
],
"totalCount":2
}`,
projectID,
)
})

snapshots, _, err := client.Checkpoints.List(ctx, groupID, clusterID, nil)
snapshots, _, err := client.Checkpoints.List(ctx, projectID, clusterID, nil)
if err != nil {
t.Fatalf("Checkpoints.List returned error: %v", err)
}
Expand All @@ -149,7 +150,7 @@ func TestCheckpoints_List(t *testing.T) {
{
ClusterID: clusterID,
Completed: "2018-02-08T23:20:25Z",
GroupID: groupID,
GroupID: projectID,
ID: "5a7cdb3980eef53de5bffdcf",
Links: []*atlas.Link{
{
Expand Down Expand Up @@ -198,7 +199,7 @@ func TestCheckpoints_List(t *testing.T) {
{
ClusterID: clusterID,
Completed: "2018-02-09T14:50:33Z",
GroupID: groupID,
GroupID: projectID,
ID: "5a7db53987d9d64fe298ff46",
Links: []*atlas.Link{
{
Expand Down Expand Up @@ -263,15 +264,15 @@ func TestCheckpoints_Get(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

checkpointID := "6b8cd61180eef547110159d9"
path := fmt.Sprintf("/api/public/v1.0/groups/%s/clusters/%s/checkpoints/%s", groupID, clusterID, checkpointID)
const checkpointID = "6b8cd61180eef547110159d9" //nolint:gosec // not a credential
path := fmt.Sprintf("/api/public/v1.0/groups/%s/clusters/%s/checkpoints/%s", projectID, clusterID, checkpointID)

mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{
_, _ = fmt.Fprintf(w, `{
"clusterId":"6b8cd61180eef547110159d9",
"completed":"2018-02-08T23:20:25Z",
"groupId":"5c8100bcf2a30b12ff88258f",
"groupId":"%[1]s",
"id":"5a7cdb3980eef53de5bffdcf",
"links":[
{
Expand Down Expand Up @@ -313,18 +314,18 @@ func TestCheckpoints_Get(t *testing.T) {
"restorable":true,
"started":"2018-02-08T23:20:25Z",
"timestamp":"2018-02-08T23:19:37Z"
}`)
}`, projectID)
})

checkpoint, _, err := client.Checkpoints.Get(ctx, groupID, clusterID, checkpointID)
checkpoint, _, err := client.Checkpoints.Get(ctx, projectID, clusterID, checkpointID)
if err != nil {
t.Fatalf("Checkpoints.Get returned error: %v", err)
}

expected := &atlas.Checkpoint{
ClusterID: clusterID,
Completed: "2018-02-08T23:20:25Z",
GroupID: groupID,
GroupID: projectID,
ID: "5a7cdb3980eef53de5bffdcf",
Links: []*atlas.Link{
{
Expand Down
Loading
Loading