From dfc07576f3740bb94d35788052ef08327ff43b5b Mon Sep 17 00:00:00 2001 From: csuzhangxc Date: Mon, 16 Oct 2023 11:48:59 +0000 Subject: [PATCH] fix lint --- hack/verify-lint.sh | 5 ++-- .../member/dm_master_member_manager_test.go | 12 ++++++--- .../member/dm_worker_member_manager_test.go | 9 ++++--- pkg/manager/member/pd_member_manager_test.go | 12 ++++++--- .../member/pump_member_manager_test.go | 6 +++-- .../member/ticdc_member_manager_test.go | 3 ++- .../member/tidb_member_manager_test.go | 15 +++++++---- .../member/tiflash_member_manager_test.go | 6 +++-- .../member/tikv_member_manager_test.go | 12 ++++++--- pkg/manager/volumes/delegation/aws/fake.go | 3 ++- pkg/manager/volumes/phase_test.go | 3 ++- pkg/manager/volumes/pod_vol_modifier_test.go | 3 ++- pkg/monitor/monitor/util_test.go | 27 ++++++++++++------- pkg/upgrader/upgrader_test.go | 3 ++- tests/drainer.go | 1 + 15 files changed, 79 insertions(+), 41 deletions(-) diff --git a/hack/verify-lint.sh b/hack/verify-lint.sh index 7d49710695..8e3f19a3c1 100755 --- a/hack/verify-lint.sh +++ b/hack/verify-lint.sh @@ -25,12 +25,11 @@ source hack/lib.sh hack::ensure_golangci_lint # main module -# lower concurrency to avoid OOM for GitHub Actions -${OUTPUT_BIN}/golangci-lint run --timeout 20m -j 2 $(go list ./... | sed 's|github.com/pingcap/tidb-operator/||') +${OUTPUT_BIN}/golangci-lint run --timeout 20m -v $(go list ./... | sed 's|github.com/pingcap/tidb-operator/||') # sub modules for dir in ${GO_SUBMODULE_DIRS[@]}; do pushd "${ROOT}/${dir}" >/dev/null - ${OUTPUT_BIN}/golangci-lint run --timeout 20m + ${OUTPUT_BIN}/golangci-lint run --timeout 20m -v popd >/dev/null done diff --git a/pkg/manager/member/dm_master_member_manager_test.go b/pkg/manager/member/dm_master_member_manager_test.go index 21a12845c9..514883ece6 100644 --- a/pkg/manager/member/dm_master_member_manager_test.go +++ b/pkg/manager/member/dm_master_member_manager_test.go @@ -877,7 +877,8 @@ func TestGetNewMasterHeadlessServiceForDMCluster(t *testing.T) { }, } - for _, tt := range tests { + for i := range tests { + tt := tests[i] t.Run(tt.name, func(t *testing.T) { svc := getNewMasterHeadlessServiceForDMCluster(&tt.dc) if diff := cmp.Diff(tt.expected, *svc); diff != "" { @@ -1376,7 +1377,8 @@ func TestGetNewMasterSetForDMCluster(t *testing.T) { // TODO add more tests } - for _, tt := range tests { + for i := range tests { + tt := tests[i] t.Run(tt.name, func(t *testing.T) { var cm *corev1.ConfigMap if !tt.nilCM { @@ -1547,7 +1549,8 @@ ssl-key = "/var/lib/dm-master-tls/tls.key" }, } - for _, tt := range testCases { + for i := range testCases { + tt := testCases[i] t.Run(tt.name, func(t *testing.T) { cm, err := getMasterConfigMap(&tt.dc) g.Expect(err).To(Succeed()) @@ -1882,7 +1885,8 @@ func TestGetNewMasterServiceForDMCluster(t *testing.T) { }, } - for _, tt := range tests { + for i := range tests { + tt := tests[i] t.Run(tt.name, func(t *testing.T) { mmm, _, _, _, _, _, _ := newFakeMasterMemberManager() svc := mmm.getNewMasterServiceForDMCluster(&tt.dc) diff --git a/pkg/manager/member/dm_worker_member_manager_test.go b/pkg/manager/member/dm_worker_member_manager_test.go index f1db907e2a..51501ade23 100644 --- a/pkg/manager/member/dm_worker_member_manager_test.go +++ b/pkg/manager/member/dm_worker_member_manager_test.go @@ -856,7 +856,8 @@ func TestGetNewWorkerHeadlessService(t *testing.T) { }, } - for _, tt := range tests { + for i := range tests { + tt := tests[i] t.Run(tt.name, func(t *testing.T) { svc := getNewWorkerHeadlessServiceForDMCluster(&tt.dc) if diff := cmp.Diff(tt.expected, *svc); diff != "" { @@ -1325,7 +1326,8 @@ func TestGetNewWorkerSetForDMCluster(t *testing.T) { // TODO add more tests } - for _, tt := range tests { + for i := range tests { + tt := tests[i] t.Run(tt.name, func(t *testing.T) { var cm *corev1.ConfigMap if !tt.nilCM { @@ -1445,7 +1447,8 @@ log-level = "info" }, } - for _, tt := range tests { + for i := range tests { + tt := tests[i] t.Run(tt.name, func(t *testing.T) { cm, err := getWorkerConfigMap(&tt.dc) g.Expect(err).To(Succeed()) diff --git a/pkg/manager/member/pd_member_manager_test.go b/pkg/manager/member/pd_member_manager_test.go index b0115d74d9..06c74e6887 100644 --- a/pkg/manager/member/pd_member_manager_test.go +++ b/pkg/manager/member/pd_member_manager_test.go @@ -1073,7 +1073,8 @@ func TestGetNewPDHeadlessServiceForTidbCluster(t *testing.T) { }, } - for _, tt := range tests { + for i := range tests { + tt := tests[i] t.Run(tt.name, func(t *testing.T) { svc := getNewPDHeadlessServiceForTidbCluster(&tt.tc) if diff := cmp.Diff(tt.expected, *svc); diff != "" { @@ -1980,7 +1981,8 @@ func TestGetNewPDSetForTidbCluster(t *testing.T) { }, } - for _, tt := range tests { + for i := range tests { + tt := tests[i] t.Run(tt.name, func(t *testing.T) { sts, err := getNewPDSetForTidbCluster(&tt.tc, nil) if (err != nil) != tt.wantErr { @@ -2305,7 +2307,8 @@ func TestGetPDConfigMap(t *testing.T) { }, } - for _, tt := range testCases { + for i := range testCases { + tt := testCases[i] t.Run(tt.name, func(t *testing.T) { cm, err := getPDConfigMap(&tt.tc) g.Expect(err).To(Succeed()) @@ -2673,7 +2676,8 @@ func TestGetNewPdServiceForTidbCluster(t *testing.T) { }, } - for _, tt := range tests { + for i := range tests { + tt := tests[i] t.Run(tt.name, func(t *testing.T) { pmm, _, _ := newFakePDMemberManager() svc := pmm.getNewPDServiceForTidbCluster(&tt.tc) diff --git a/pkg/manager/member/pump_member_manager_test.go b/pkg/manager/member/pump_member_manager_test.go index 79acca9925..4b00682a2b 100644 --- a/pkg/manager/member/pump_member_manager_test.go +++ b/pkg/manager/member/pump_member_manager_test.go @@ -595,7 +595,8 @@ func TestGetNewPumpHeadlessService(t *testing.T) { }, } - for _, tt := range tests { + for i := range tests { + tt := tests[i] t.Run(tt.name, func(t *testing.T) { svc := getNewPumpHeadlessService(&tt.tc) if diff := cmp.Diff(tt.expected, *svc); diff != "" { @@ -717,7 +718,8 @@ func TestGetNewPumpConfigMap(t *testing.T) { }, } - for _, tt := range tests { + for i := range tests { + tt := tests[i] t.Run(tt.name, func(t *testing.T) { cm, err := getNewPumpConfigMap(&tt.tc) g.Expect(err).To(Succeed()) diff --git a/pkg/manager/member/ticdc_member_manager_test.go b/pkg/manager/member/ticdc_member_manager_test.go index ff2c55639f..3fec903163 100644 --- a/pkg/manager/member/ticdc_member_manager_test.go +++ b/pkg/manager/member/ticdc_member_manager_test.go @@ -583,7 +583,8 @@ func TestGetNewTiCDCStatefulSet(t *testing.T) { }, } - for _, tt := range tests { + for i := range tests { + tt := tests[i] t.Run(tt.name, func(t *testing.T) { sts, _ := getNewTiCDCStatefulSet(&tt.tc, nil) tt.testSts(sts) diff --git a/pkg/manager/member/tidb_member_manager_test.go b/pkg/manager/member/tidb_member_manager_test.go index db2512e629..fd687f3cb4 100644 --- a/pkg/manager/member/tidb_member_manager_test.go +++ b/pkg/manager/member/tidb_member_manager_test.go @@ -936,7 +936,8 @@ func TestGetNewTiDBHeadlessServiceForTidbCluster(t *testing.T) { }, } - for _, tt := range tests { + for i := range tests { + tt := tests[i] t.Run(tt.name, func(t *testing.T) { svc := getNewTiDBHeadlessServiceForTidbCluster(&tt.tc) if diff := cmp.Diff(tt.expected, *svc); diff != "" { @@ -1267,7 +1268,8 @@ func TestGetNewTiDBSetForTidbCluster(t *testing.T) { // TODO add more tests } - for _, tt := range tests { + for i := range tests { + tt := tests[i] t.Run(tt.name, func(t *testing.T) { sts, _ := getNewTiDBSetForTidbCluster(&tt.tc, tt.cm) tt.testSts(sts) @@ -1601,7 +1603,8 @@ func TestTiDBInitContainers(t *testing.T) { }, } - for _, tt := range tests { + for i := range tests { + tt := tests[i] t.Run(tt.name, func(t *testing.T) { sts, _ := getNewTiDBSetForTidbCluster(&tt.tc, nil) if diff := cmp.Diff(tt.expectedInit, sts.Spec.Template.Spec.InitContainers); diff != "" { @@ -1931,7 +1934,8 @@ func TestGetNewTiDBService(t *testing.T) { }, } - for _, tt := range testCases { + for i := range testCases { + tt := testCases[i] t.Run(tt.name, func(t *testing.T) { svc := getNewTiDBServiceOrNil(&tt.tc) if tt.expected == nil { @@ -2140,7 +2144,8 @@ func TestGetTiDBConfigMap(t *testing.T) { }, } - for _, tt := range testCases { + for i := range testCases { + tt := testCases[i] t.Run(tt.name, func(t *testing.T) { cm, err := getTiDBConfigMap(&tt.tc) g.Expect(err).To(Succeed()) diff --git a/pkg/manager/member/tiflash_member_manager_test.go b/pkg/manager/member/tiflash_member_manager_test.go index c30d205ceb..f0391bd195 100644 --- a/pkg/manager/member/tiflash_member_manager_test.go +++ b/pkg/manager/member/tiflash_member_manager_test.go @@ -1440,7 +1440,8 @@ func TestGetNewServiceForTidbCluster(t *testing.T) { }, } - for _, tt := range tests { + for i := range tests { + tt := tests[i] t.Run(tt.name, func(t *testing.T) { svc := getNewServiceForTidbCluster(&tt.tc, tt.svcConfig) if diff := cmp.Diff(tt.expected, *svc); diff != "" { @@ -1730,7 +1731,8 @@ func TestGetNewTiFlashSetForTidbCluster(t *testing.T) { // TODO add more tests } - for _, tt := range tests { + for i := range tests { + tt := tests[i] t.Run(tt.name, func(t *testing.T) { sts, err := getNewStatefulSet(&tt.tc, nil) if (err != nil) != tt.wantErr { diff --git a/pkg/manager/member/tikv_member_manager_test.go b/pkg/manager/member/tikv_member_manager_test.go index f296a7ba58..b99e3de9b1 100644 --- a/pkg/manager/member/tikv_member_manager_test.go +++ b/pkg/manager/member/tikv_member_manager_test.go @@ -1722,7 +1722,8 @@ func TestGetNewTiKVServiceForTidbCluster(t *testing.T) { }, } - for _, tt := range tests { + for i := range tests { + tt := tests[i] t.Run(tt.name, func(t *testing.T) { svc := getNewServiceForTidbCluster(&tt.tc, tt.svcConfig) if diff := cmp.Diff(tt.expected, *svc); diff != "" { @@ -2167,7 +2168,8 @@ func TestGetNewTiKVSetForTidbCluster(t *testing.T) { }, } - for _, tt := range tests { + for i := range tests { + tt := tests[i] t.Run(tt.name, func(t *testing.T) { sts, err := getNewTiKVSetForTidbCluster(&tt.tc, nil) if (err != nil) != tt.wantErr { @@ -2506,7 +2508,8 @@ func TestTiKVInitContainers(t *testing.T) { }, } - for _, tt := range tests { + for i := range tests { + tt := tests[i] t.Run(tt.name, func(t *testing.T) { sts, err := getNewTiKVSetForTidbCluster(&tt.tc, nil) if (err != nil) != tt.wantErr { @@ -2616,7 +2619,8 @@ func TestGetTiKVConfigMap(t *testing.T) { }, } - for _, tt := range testCases { + for i := range testCases { + tt := &testCases[i] t.Run(tt.name, func(t *testing.T) { cm, err := getTikVConfigMap(&tt.tc) g.Expect(err).To(Succeed()) diff --git a/pkg/manager/volumes/delegation/aws/fake.go b/pkg/manager/volumes/delegation/aws/fake.go index 70bdb46c0d..2cbcb788b1 100644 --- a/pkg/manager/volumes/delegation/aws/fake.go +++ b/pkg/manager/volumes/delegation/aws/fake.go @@ -85,7 +85,8 @@ func (m *FakeEC2VolumeAPI) ModifyVolume(ctx context.Context, param *ec2.ModifyVo func (m *FakeEC2VolumeAPI) DescribeVolumesModifications(ctx context.Context, param *ec2.DescribeVolumesModificationsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeVolumesModificationsOutput, error) { mods := []types.VolumeModification{} for _, id := range param.VolumeIds { - for _, v := range m.vs { + for i := range m.vs { + v := m.vs[i] if v.VolumeId != id { continue } diff --git a/pkg/manager/volumes/phase_test.go b/pkg/manager/volumes/phase_test.go index 5ae9843638..2d18a96ef3 100644 --- a/pkg/manager/volumes/phase_test.go +++ b/pkg/manager/volumes/phase_test.go @@ -227,7 +227,8 @@ func TestGetVolumePhase(t *testing.T) { } g := NewGomegaWithT(t) - for _, c := range cases { + for i := range cases { + c := &cases[i] actual := ActualVolume{ PVC: c.pvc, StorageClass: c.oldSc, diff --git a/pkg/manager/volumes/pod_vol_modifier_test.go b/pkg/manager/volumes/pod_vol_modifier_test.go index 62b4c8abf4..62cce4b95b 100644 --- a/pkg/manager/volumes/pod_vol_modifier_test.go +++ b/pkg/manager/volumes/pod_vol_modifier_test.go @@ -192,7 +192,8 @@ func TestModify(t *testing.T) { } g := NewGomegaWithT(t) - for _, c := range cases { + for i := range cases { + c := &cases[i] kc := fake.NewSimpleClientset( c.pvc, c.pv, diff --git a/pkg/monitor/monitor/util_test.go b/pkg/monitor/monitor/util_test.go index 58a1058cd2..f4c63c25d5 100644 --- a/pkg/monitor/monitor/util_test.go +++ b/pkg/monitor/monitor/util_test.go @@ -296,7 +296,8 @@ func TestGetMonitorConfigMap(t *testing.T) { }, } - for _, tt := range testCases { + for i := range testCases { + tt := testCases[i] t.Run(tt.name, func(t *testing.T) { cm, err := getPromConfigMap(&tt.monitor, tt.monitorClusterInfos, nil, 0, nil) g.Expect(err).NotTo(HaveOccurred()) @@ -363,7 +364,8 @@ func TestGetMonitorSecret(t *testing.T) { }, } - for _, tt := range testCases { + for i := range testCases { + tt := testCases[i] t.Run(tt.name, func(t *testing.T) { sec := getMonitorSecret(&tt.monitor) if tt.expected == nil { @@ -417,7 +419,8 @@ func TestGetMonitorServiceAccount(t *testing.T) { }, } - for _, tt := range testCases { + for i := range testCases { + tt := testCases[i] t.Run(tt.name, func(t *testing.T) { sa := getMonitorServiceAccount(&tt.monitor) if tt.expected == nil { @@ -868,7 +871,8 @@ func TestGetMonitorService(t *testing.T) { }, } - for _, tt := range testCases { + for i := range testCases { + tt := testCases[i] t.Run(tt.name, func(t *testing.T) { svc := getMonitorService(&tt.monitor) if tt.expected == nil { @@ -1163,7 +1167,8 @@ func TestGetMonitorVolumes(t *testing.T) { }, } - for _, tt := range testCases { + for i := range testCases { + tt := testCases[i] t.Run(tt.name, func(t *testing.T) { sa := getMonitorVolumes(&tt.monitor) tt.expected(sa) @@ -1288,7 +1293,8 @@ func TestGetMonitorPrometheusContainer(t *testing.T) { }, } - for _, tt := range testCases { + for i := range testCases { + tt := testCases[i] t.Run(tt.name, func(t *testing.T) { sa := getMonitorPrometheusContainer(&tt.monitor, 0) if tt.expected == nil { @@ -1440,7 +1446,8 @@ func TestGetMonitorGrafanaContainer(t *testing.T) { }, } - for _, tt := range testCases { + for i := range testCases { + tt := testCases[i] t.Run(tt.name, func(t *testing.T) { sa := getMonitorGrafanaContainer(&tt.secret, &tt.monitor) if tt.expected == nil { @@ -1564,7 +1571,8 @@ func TestGetMonitorThanosSidecarContainer(t *testing.T) { }, } - for _, tt := range testCases { + for i := range testCases { + tt := testCases[i] t.Run(tt.name, func(t *testing.T) { sa := getThanosSidecarContainer(&tt.monitor) if tt.expected == nil { @@ -1614,7 +1622,8 @@ func TestBuildExternalLabels(t *testing.T) { }, } - for _, tt := range testCases { + for i := range testCases { + tt := testCases[i] t.Run(tt.name, func(t *testing.T) { sa := buildExternalLabels(&tt.monitor) if tt.expected == nil { diff --git a/pkg/upgrader/upgrader_test.go b/pkg/upgrader/upgrader_test.go index 4dd0f8b12e..2ba544bc10 100644 --- a/pkg/upgrader/upgrader_test.go +++ b/pkg/upgrader/upgrader_test.go @@ -88,7 +88,8 @@ func TestIsOwnedByTidbCluster(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - ok, _ := util.IsOwnedByTidbCluster(&tt.sts) + sts := tt.sts + ok, _ := util.IsOwnedByTidbCluster(&sts) if tt.wantOK != ok { t.Errorf("got %v, want %v", ok, tt.wantOK) } diff --git a/tests/drainer.go b/tests/drainer.go index 6fb5e0b2e9..151ca795c1 100644 --- a/tests/drainer.go +++ b/tests/drainer.go @@ -200,6 +200,7 @@ func (d *DrainerConfig) DrainerHelmString(m map[string]string, source *DrainerSo func GetDrainerSubValuesOrDie(info *DrainerConfig) string { if info == nil { slack.NotifyAndPanic(fmt.Errorf("Cannot get drainer sub values, the drainer config is nil")) + return "" } buff := new(bytes.Buffer) switch info.DbType {