Skip to content

Commit a485d53

Browse files
Merge pull request #125802 from mmorel-35/testifylint/len+empty
fix: enable empty and len rules from testifylint on pkg and staging package Kubernetes-commit: 2d4514e1690dc5babb144542da799f6b331afd1b
2 parents c741ec4 + 5d4ec5a commit a485d53

File tree

8 files changed

+27
-27
lines changed

8 files changed

+27
-27
lines changed

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ require (
2525
go.uber.org/zap v1.26.0
2626
golang.org/x/sys v0.21.0
2727
gopkg.in/yaml.v2 v2.4.0
28-
k8s.io/apimachinery v0.0.0-20240707022528-c1f240355706
29-
k8s.io/client-go v0.0.0-20240707023231-354ed1bc9f1f
28+
k8s.io/apimachinery v0.0.0-20240711222537-4524748494bf
29+
k8s.io/client-go v0.0.0-20240712063246-53b8be7ceab5
3030
k8s.io/klog/v2 v2.130.1
3131
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
3232
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd
@@ -75,7 +75,7 @@ require (
7575
google.golang.org/protobuf v1.34.2 // indirect
7676
gopkg.in/inf.v0 v0.9.1 // indirect
7777
gopkg.in/yaml.v3 v3.0.1 // indirect
78-
k8s.io/api v0.0.0-20240707022826-2cf4612580d3 // indirect
78+
k8s.io/api v0.0.0-20240712023323-4badb3333d55 // indirect
7979
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
8080
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
8181
sigs.k8s.io/yaml v1.4.0 // indirect

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,12 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
204204
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
205205
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
206206
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
207-
k8s.io/api v0.0.0-20240707022826-2cf4612580d3 h1:2bHi5SAn7dRf6oJGO29yFEtMyIN9oCD86In1R70UnXA=
208-
k8s.io/api v0.0.0-20240707022826-2cf4612580d3/go.mod h1:TeZW9JsLR2mmT3LA7JsD/4i5g40HHrREIdaD0QCEP1Y=
209-
k8s.io/apimachinery v0.0.0-20240707022528-c1f240355706 h1:17r0OQj+n4pHLABJJ5Sb5GeSSZy4NF0YSaEy2qsPLLY=
210-
k8s.io/apimachinery v0.0.0-20240707022528-c1f240355706/go.mod h1:Et4EUFrefx1K28ZwNXpkHUqq7fSML2FROj79Ku7Lj1w=
211-
k8s.io/client-go v0.0.0-20240707023231-354ed1bc9f1f h1:HEQPgzOtITgo4RE9ZpCX7Sn2Cu8h1DlXY9S1Bi9djsU=
212-
k8s.io/client-go v0.0.0-20240707023231-354ed1bc9f1f/go.mod h1:Nbn3B+SZKebFY2/5RTVUF6AyS37oDLJ9XXwrxjXpbTI=
207+
k8s.io/api v0.0.0-20240712023323-4badb3333d55 h1:n44Qr23IUW2bPIMGrDScIdqmu1u+XUHqdd0O0hTj2pM=
208+
k8s.io/api v0.0.0-20240712023323-4badb3333d55/go.mod h1:O8LAmMgsWzumSE9wGhqSdC+9HFxJ3Bh+NuDzms9R/D4=
209+
k8s.io/apimachinery v0.0.0-20240711222537-4524748494bf h1:BO1LyfoftoDsAxaqL9zPspuFZPuY2mq8vH4qqqoAodc=
210+
k8s.io/apimachinery v0.0.0-20240711222537-4524748494bf/go.mod h1:Et4EUFrefx1K28ZwNXpkHUqq7fSML2FROj79Ku7Lj1w=
211+
k8s.io/client-go v0.0.0-20240712063246-53b8be7ceab5 h1:FlYnjobR2ssh20GtO47ze/jqACrODJjmPFPIuE8lj90=
212+
k8s.io/client-go v0.0.0-20240712063246-53b8be7ceab5/go.mod h1:t2i0B87/e6Kk2nUK0ctt34B/wr3K4unmBKrCKccHQuk=
213213
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
214214
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
215215
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag=

metrics/counter_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func TestCounter(t *testing.T) {
8787
mfs, err := registry.Gather()
8888
var buf bytes.Buffer
8989
enc := expfmt.NewEncoder(&buf, "text/plain; version=0.0.4; charset=utf-8")
90-
assert.Equalf(t, test.expectedMetricCount, len(mfs), "Got %v metrics, Want: %v metrics", len(mfs), test.expectedMetricCount)
90+
assert.Lenf(t, mfs, test.expectedMetricCount, "Got %v metrics, Want: %v metrics", len(mfs), test.expectedMetricCount)
9191
assert.Nil(t, err, "Gather failed %v", err)
9292
for _, metric := range mfs {
9393
err := enc.Encode(metric)
@@ -186,12 +186,12 @@ func TestCounterVec(t *testing.T) {
186186
registry.MustRegister(c)
187187
c.WithLabelValues("1", "2").Inc()
188188
mfs, err := registry.Gather()
189-
assert.Equalf(t, test.expectedMetricFamilyCount, len(mfs), "Got %v metric families, Want: %v metric families", len(mfs), test.expectedMetricFamilyCount)
189+
assert.Lenf(t, mfs, test.expectedMetricFamilyCount, "Got %v metric families, Want: %v metric families", len(mfs), test.expectedMetricFamilyCount)
190190
assert.Nil(t, err, "Gather failed %v", err)
191191

192192
// this no-opts here when there are no metric families (i.e. when the metric is hidden)
193193
for _, mf := range mfs {
194-
assert.Equalf(t, 1, len(mf.GetMetric()), "Got %v metrics, wanted 1 as the count", len(mf.GetMetric()))
194+
assert.Lenf(t, mf.GetMetric(), 1, "Got %v metrics, wanted 1 as the count", len(mf.GetMetric()))
195195
assert.Equalf(t, test.expectedHelp, mf.GetHelp(), "Got %s as help message, want %s", mf.GetHelp(), test.expectedHelp)
196196
}
197197

@@ -203,7 +203,7 @@ func TestCounterVec(t *testing.T) {
203203

204204
// this no-opts here when there are no metric families (i.e. when the metric is hidden)
205205
for _, mf := range mfs {
206-
assert.Equalf(t, 3, len(mf.GetMetric()), "Got %v metrics, wanted 3 as the count", len(mf.GetMetric()))
206+
assert.Lenf(t, mf.GetMetric(), 3, "Got %v metrics, wanted 3 as the count", len(mf.GetMetric()))
207207
}
208208
})
209209
}

metrics/gauge_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func TestGauge(t *testing.T) {
8787
registry.MustRegister(c)
8888

8989
ms, err := registry.Gather()
90-
assert.Equalf(t, test.expectedMetricCount, len(ms), "Got %v metrics, Want: %v metrics", len(ms), test.expectedMetricCount)
90+
assert.Lenf(t, ms, test.expectedMetricCount, "Got %v metrics, Want: %v metrics", len(ms), test.expectedMetricCount)
9191
assert.Nil(t, err, "Gather failed %v", err)
9292

9393
for _, metric := range ms {
@@ -175,7 +175,7 @@ func TestGaugeVec(t *testing.T) {
175175
registry.MustRegister(c)
176176
c.WithLabelValues("1", "2").Set(1.0)
177177
ms, err := registry.Gather()
178-
assert.Equalf(t, test.expectedMetricCount, len(ms), "Got %v metrics, Want: %v metrics", len(ms), test.expectedMetricCount)
178+
assert.Lenf(t, ms, test.expectedMetricCount, "Got %v metrics, Want: %v metrics", len(ms), test.expectedMetricCount)
179179
assert.Nil(t, err, "Gather failed %v", err)
180180
for _, metric := range ms {
181181
assert.Equalf(t, test.expectedHelp, metric.GetHelp(), "Got %s as help message, want %s", metric.GetHelp(), test.expectedHelp)
@@ -188,7 +188,7 @@ func TestGaugeVec(t *testing.T) {
188188
assert.Nil(t, err, "Gather failed %v", err)
189189

190190
for _, mf := range ms {
191-
assert.Equalf(t, 3, len(mf.GetMetric()), "Got %v metrics, wanted 3 as the count", len(mf.GetMetric()))
191+
assert.Lenf(t, mf.GetMetric(), 3, "Got %v metrics, wanted 3 as the count", len(mf.GetMetric()))
192192
}
193193
})
194194
}

metrics/histogram_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func TestHistogram(t *testing.T) {
102102
}
103103

104104
ms, err := registry.Gather()
105-
assert.Equalf(t, test.expectedMetricCount, len(ms), "Got %v metrics, Want: %v metrics", len(ms), test.expectedMetricCount)
105+
assert.Lenf(t, ms, test.expectedMetricCount, "Got %v metrics, Want: %v metrics", len(ms), test.expectedMetricCount)
106106
assert.Nil(t, err, "Gather failed %v", err)
107107

108108
for _, metric := range ms {
@@ -211,7 +211,7 @@ func TestHistogramVec(t *testing.T) {
211211
}
212212

213213
ms, err := registry.Gather()
214-
assert.Equalf(t, test.expectedMetricCount, len(ms), "Got %v metrics, Want: %v metrics", len(ms), test.expectedMetricCount)
214+
assert.Lenf(t, ms, test.expectedMetricCount, "Got %v metrics, Want: %v metrics", len(ms), test.expectedMetricCount)
215215
assert.Nil(t, err, "Gather failed %v", err)
216216
for _, metric := range ms {
217217
if metric.GetHelp() != test.expectedHelp {
@@ -226,7 +226,7 @@ func TestHistogramVec(t *testing.T) {
226226
assert.Nil(t, err, "Gather failed %v", err)
227227

228228
for _, mf := range ms {
229-
assert.Equalf(t, 3, len(mf.GetMetric()), "Got %v metrics, wanted 3 as the count", len(mf.GetMetric()))
229+
assert.Lenf(t, mf.GetMetric(), 3, "Got %v metrics, wanted 3 as the count", len(mf.GetMetric()))
230230
for _, m := range mf.GetMetric() {
231231
assert.Equalf(t, uint64(1), m.GetHistogram().GetSampleCount(), "Got %v metrics, expected histogram sample count to equal 1", m.GetHistogram().GetSampleCount())
232232
}

metrics/registry_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func TestShowHiddenMetric(t *testing.T) {
235235

236236
ms, err := registry.Gather()
237237
assert.Nil(t, err, "Gather failed %v", err)
238-
assert.Equalf(t, expectedMetricCount, len(ms), "Got %v metrics, Want: %v metrics", len(ms), expectedMetricCount)
238+
assert.Lenf(t, ms, expectedMetricCount, "Got %v metrics, Want: %v metrics", len(ms), expectedMetricCount)
239239

240240
showHidden.Store(true)
241241
defer showHidden.Store(false)
@@ -253,7 +253,7 @@ func TestShowHiddenMetric(t *testing.T) {
253253

254254
ms, err = registry.Gather()
255255
assert.Nil(t, err, "Gather failed %v", err)
256-
assert.Equalf(t, expectedMetricCount, len(ms), "Got %v metrics, Want: %v metrics", len(ms), expectedMetricCount)
256+
assert.Lenf(t, ms, expectedMetricCount, "Got %v metrics, Want: %v metrics", len(ms), expectedMetricCount)
257257
}
258258

259259
func TestValidateShowHiddenMetricsVersion(t *testing.T) {

metrics/summary_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func TestSummary(t *testing.T) {
8787
registry.MustRegister(c)
8888

8989
ms, err := registry.Gather()
90-
assert.Equalf(t, test.expectedMetricCount, len(ms), "Got %v metrics, Want: %v metrics", len(ms), test.expectedMetricCount)
90+
assert.Lenf(t, ms, test.expectedMetricCount, "Got %v metrics, Want: %v metrics", len(ms), test.expectedMetricCount)
9191
assert.Nil(t, err, "Gather failed %v", err)
9292

9393
for _, metric := range ms {
@@ -176,7 +176,7 @@ func TestSummaryVec(t *testing.T) {
176176
registry.MustRegister(c)
177177
c.WithLabelValues("1", "2").Observe(1.0)
178178
ms, err := registry.Gather()
179-
assert.Equalf(t, test.expectedMetricCount, len(ms), "Got %v metrics, Want: %v metrics", len(ms), test.expectedMetricCount)
179+
assert.Lenf(t, ms, test.expectedMetricCount, "Got %v metrics, Want: %v metrics", len(ms), test.expectedMetricCount)
180180
assert.Nil(t, err, "Gather failed %v", err)
181181

182182
for _, metric := range ms {
@@ -190,7 +190,7 @@ func TestSummaryVec(t *testing.T) {
190190
assert.Nil(t, err, "Gather failed %v", err)
191191

192192
for _, mf := range ms {
193-
assert.Equalf(t, 3, len(mf.GetMetric()), "Got %v metrics, wanted 2 as the count", len(mf.GetMetric()))
193+
assert.Lenf(t, mf.GetMetric(), 3, "Got %v metrics, wanted 2 as the count", len(mf.GetMetric()))
194194
for _, m := range mf.GetMetric() {
195195
assert.Equalf(t, uint64(1), m.GetSummary().GetSampleCount(), "Got %v metrics, wanted 1 as the summary sample count", m.GetSummary().GetSampleCount())
196196
}

metrics/timing_histogram_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func TestTimingHistogram(t *testing.T) {
111111
}
112112

113113
ms, err := registry.Gather()
114-
assert.Equalf(t, test.expectedMetricCount, len(ms), "Got %v metrics, Want: %v metrics", len(ms), test.expectedMetricCount)
114+
assert.Lenf(t, ms, test.expectedMetricCount, "Got %v metrics, Want: %v metrics", len(ms), test.expectedMetricCount)
115115
assert.Nil(t, err, "Gather failed %v", err)
116116

117117
for _, metric := range ms {
@@ -242,7 +242,7 @@ func TestTimingHistogramVec(t *testing.T) {
242242
}
243243

244244
ms, err := registry.Gather()
245-
assert.Equalf(t, test.expectedMetricCount, len(ms), "Got %v metrics, Want: %v metrics", len(ms), test.expectedMetricCount)
245+
assert.Lenf(t, ms, test.expectedMetricCount, "Got %v metrics, Want: %v metrics", len(ms), test.expectedMetricCount)
246246
assert.Nil(t, err, "Gather failed %v", err)
247247
for _, metric := range ms {
248248
if metric.GetHelp() != test.expectedHelp {
@@ -264,7 +264,7 @@ func TestTimingHistogramVec(t *testing.T) {
264264

265265
for _, mf := range ms {
266266
t.Logf("Considering metric family %s", mf.String())
267-
assert.Equalf(t, 3, len(mf.GetMetric()), "Got %v metrics, wanted 3 as the count for family %#+v", len(mf.GetMetric()), mf)
267+
assert.Lenf(t, mf.GetMetric(), 3, "Got %v metrics, wanted 3 as the count for family %#+v", len(mf.GetMetric()), mf)
268268
for _, m := range mf.GetMetric() {
269269
expectedCount := uint64(dt1)
270270
expectedSum := float64(dt1) * v0

0 commit comments

Comments
 (0)