Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
csuzhangxc committed Oct 16, 2023
1 parent b544114 commit dfc0757
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 41 deletions.
5 changes: 2 additions & 3 deletions hack/verify-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 8 additions & 4 deletions pkg/manager/member/dm_master_member_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions pkg/manager/member/dm_worker_member_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
Expand Down
12 changes: 8 additions & 4 deletions pkg/manager/member/pd_member_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions pkg/manager/member/pump_member_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion pkg/manager/member/ticdc_member_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 10 additions & 5 deletions pkg/manager/member/tidb_member_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
Expand Down
6 changes: 4 additions & 2 deletions pkg/manager/member/tiflash_member_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 8 additions & 4 deletions pkg/manager/member/tikv_member_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion pkg/manager/volumes/delegation/aws/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/manager/volumes/phase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion pkg/manager/volumes/pod_vol_modifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
27 changes: 18 additions & 9 deletions pkg/monitor/monitor/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion pkg/upgrader/upgrader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Loading

0 comments on commit dfc0757

Please sign in to comment.