Skip to content

Commit 8f3ca8a

Browse files
authored
[chore] mdatagen comply with testifylint (#11136)
#### Description As Testifylint is not applied on generated files, this update mdatagen to comply with actually applied testifylint recommandations. Signed-off-by: Matthieu MOREL <[email protected]>
1 parent 168bba7 commit 8f3ca8a

26 files changed

+70
-58
lines changed

cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_metrics_test.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/mdatagen/templates/metrics_test.go.tmpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func TestMetricsBuilder(t *testing.T) {
164164
assert.Equal(t, "{{ $metric.Description }}", ms.At(i).Description())
165165
assert.Equal(t, "{{ $metric.Unit }}", ms.At(i).Unit())
166166
{{- if $metric.Data.HasMonotonic }}
167-
assert.Equal(t, {{ $metric.Data.Monotonic }}, ms.At(i).{{ $metric.Data.Type }}().IsMonotonic())
167+
assert.{{- if $metric.Data.Monotonic }}True{{ else }}False{{ end }}(t, ms.At(i).{{ $metric.Data.Type }}().IsMonotonic())
168168
{{- end }}
169169
{{- if $metric.Data.HasAggregated }}
170170
assert.Equal(t, pmetric.AggregationTemporality{{ $metric.Data.AggregationTemporality }}, ms.At(i).{{ $metric.Data.Type }}().AggregationTemporality())
@@ -178,7 +178,11 @@ func TestMetricsBuilder(t *testing.T) {
178178
{{- range $i, $attr := $metric.Attributes }}
179179
attrVal, ok {{ if eq $i 0 }}:{{ end }}= dp.Attributes().Get("{{ (attributeInfo $attr).Name }}")
180180
assert.True(t, ok)
181+
{{- if eq (attributeInfo $attr).Type.String "Bool"}}
182+
assert.{{- if (attributeInfo $attr).TestValue }}True{{ else }}False{{- end }}(t, attrVal.{{ (attributeInfo $attr).Type }}()
183+
{{- else }}
181184
assert.EqualValues(t, {{ (attributeInfo $attr).TestValue }}, attrVal.{{ (attributeInfo $attr).Type }}()
185+
{{- end }}
182186
{{- if or (eq (attributeInfo $attr).Type.String "Slice") (eq (attributeInfo $attr).Type.String "Map")}}.AsRaw(){{ end }})
183187
{{- end }}
184188
{{- end }}

pdata/internal/cmd/pdatagen/internal/base_fields.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,17 @@ const accessorsOneOfPrimitiveTestTemplate = `func Test{{ .structName }}_{{ .acce
177177

178178
const accessorsPrimitiveTestTemplate = `func Test{{ .structName }}_{{ .fieldName }}(t *testing.T) {
179179
ms := New{{ .structName }}()
180+
{{- if eq .returnType "bool" }}
181+
assert.{{- if eq .defaultVal "true" }}True{{- else }}False{{- end }}(t, ms.{{ .fieldName }}())
182+
{{- else }}
180183
assert.Equal(t, {{ .defaultVal }}, ms.{{ .fieldName }}())
184+
{{- end }}
181185
ms.Set{{ .fieldName }}({{ .testValue }})
186+
{{- if eq .returnType "bool" }}
187+
assert.{{- if eq .testValue "true" }}True{{- else }}False{{- end }}(t, ms.{{ .fieldName }}())
188+
{{- else }}
182189
assert.Equal(t, {{ .testValue }}, ms.{{ .fieldName }}())
190+
{{- end }}
183191
sharedState := internal.StateReadOnly
184192
assert.Panics(t, func() { new{{ .structName }}(&{{ .originStructName }}{}, &sharedState).Set{{ .fieldName }}({{ .testValue }}) })
185193
}`

pdata/internal/cmd/pdatagen/internal/base_slices.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,13 @@ func Test{{ .structName }}_Sort(t *testing.T) {
272272
return uintptr(unsafe.Pointer(a.orig)) < uintptr(unsafe.Pointer(b.orig))
273273
})
274274
for i := 1; i < es.Len(); i++ {
275-
assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) < uintptr(unsafe.Pointer(es.At(i).orig)))
275+
assert.Less(t, uintptr(unsafe.Pointer(es.At(i-1).orig)), uintptr(unsafe.Pointer(es.At(i).orig)))
276276
}
277277
es.Sort(func(a, b {{ .elementName }}) bool {
278278
return uintptr(unsafe.Pointer(a.orig)) > uintptr(unsafe.Pointer(b.orig))
279279
})
280280
for i := 1; i < es.Len(); i++ {
281-
assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) > uintptr(unsafe.Pointer(es.At(i).orig)))
281+
assert.Greater(t, uintptr(unsafe.Pointer(es.At(i-1).orig)), uintptr(unsafe.Pointer(es.At(i).orig)))
282282
}
283283
}
284284
{{- end }}`

pdata/plog/generated_logrecordslice_test.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pdata/plog/generated_resourcelogsslice_test.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pdata/plog/generated_scopelogsslice_test.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pdata/pmetric/generated_exponentialhistogramdatapointslice_test.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pdata/pmetric/generated_histogramdatapointslice_test.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pdata/pmetric/generated_metricslice_test.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)