Skip to content

Conversation

@ywwg
Copy link
Member

@ywwg ywwg commented Jun 10, 2025

Fixes #37

@ywwg ywwg force-pushed the owilliams/untestify branch from d5437cf to d9c2e25 Compare June 10, 2025 19:10
@ywwg ywwg mentioned this pull request Jun 10, 2025
@pellared
Copy link
Contributor

I can review it tomorrow or on Thursday.
At quick glance you can look at following recommendations:

@ywwg ywwg marked this pull request as ready for review June 11, 2025 13:06
@ywwg
Copy link
Member Author

ywwg commented Jun 11, 2025

I'll squash down with DCO before merge

Copy link
Member

@ArthurSens ArthurSens left a comment

Choose a reason for hiding this comment

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

Thanks, just one comment and it should be good to go!

- predeclared
- revive
- sloglint
- testifylint
Copy link
Member

Choose a reason for hiding this comment

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

Our golangci-lint configuration is synchronized with prometheus/prometheus (See #36)

So whatever changes you're making, it will be reverted 😬

Copy link
Member Author

Choose a reason for hiding this comment

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

ok well I guess that's fine, it'll pass :)

@ArthurSens
Copy link
Member

Ah, I was about to merge #35 and realized it will create merge conflicts. Do you have a preferred order to merge these two?

@ywwg
Copy link
Member Author

ywwg commented Jun 11, 2025

go do yours first

@aknuds1 aknuds1 requested a review from Copilot June 11, 2025 13:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR removes the use of the testify library by replacing require assertions with standard testing idioms and cleans up the module dependency on testify.

  • Tests now use inline if checks with t.Errorf instead of require.*.
  • Added strings import for manual Contains checks.
  • Updated go.mod to drop the testify requirement.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
normalize_label_test.go Removed testify/require, replaced with manual if + t.Errorf
metric_namer_test.go Ditto for require.Equal and require.Contains, added strings
go.mod Removed github.com/stretchr/testify from require block
Comments suppressed due to low confidence (1)

normalize_label_test.go:44

  • [nitpick] The inline if checks for equality are duplicated across tests; consider extracting a small helper (with t.Helper()) to reduce repetition and improve readability.
if utf8Allowed {

Copy link
Contributor

@aknuds1 aknuds1 left a comment

Choose a reason for hiding this comment

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

Generally LGTM, but please see my question.

Fixes #37

Signed-off-by: Owen Williams <[email protected]>
@ywwg ywwg force-pushed the owilliams/untestify branch from bb7c828 to 70ddaf5 Compare June 11, 2025 13:45
@ywwg ywwg merged commit 61633f4 into main Jun 11, 2025
8 checks passed
@ywwg ywwg deleted the owilliams/untestify branch June 11, 2025 13:48
Copy link
Contributor

@pellared pellared left a comment

Choose a reason for hiding this comment

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

Minor nit comments. Thanks

// Build metric name using MetricNamer
gotMetricName := tt.namer.Build(tt.metric)
require.Equal(t, tt.expectedMetricName, gotMetricName)
if tt.expectedMetricName != gotMetricName {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: you can rename expected to want

gotMetricName := tt.namer.Build(tt.metric)
require.Equal(t, tt.expectedMetricName, gotMetricName)
if tt.expectedMetricName != gotMetricName {
t.Errorf("namer.Build(%v), got %q, want %q", tt.metric, gotMetricName, tt.expectedMetricName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
t.Errorf("namer.Build(%v), got %q, want %q", tt.metric, gotMetricName, tt.expectedMetricName)
t.Errorf("namer.Build(%q) = %q, want %q", tt.metric, gotMetricName, tt.expectedMetricName)

gotUnitName := unitNamer.Build(tt.metric.Unit)
require.Equal(t, tt.expectedUnitName, gotUnitName)
if tt.expectedUnitName != gotUnitName {
t.Errorf("unitNamer.Build(%q), got %q, want %q", tt.metric.Unit, gotUnitName, tt.expectedUnitName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
t.Errorf("unitNamer.Build(%q), got %q, want %q", tt.metric.Unit, gotUnitName, tt.expectedUnitName)
t.Errorf("unitNamer.Build(%q) = %q, want %q", tt.metric.Unit, gotUnitName, tt.expectedUnitName)

require.Contains(t, gotMetricName, gotUnitName,
"Metric name '%s' should contain unit name '%s' when WithMetricSuffixes=true",
gotMetricName, gotUnitName)
if !strings.Contains(gotMetricName, gotUnitName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We can simply add && !strings.Contains(gotMetricName, gotUnitName) to line 1119
I also think that gotUnitName != "" can be omitted.
Then we would have

if tt.namer.WithMetricSuffixes && !strings.Contains(gotMetricName, gotUnitName) {

"Metric name '%s' should contain unit name '%s' when WithMetricSuffixes=true",
gotMetricName, gotUnitName)
if !strings.Contains(gotMetricName, gotUnitName) {
t.Errorf("Metric name '%q' should contain unit name '%s' when WithMetricSuffixes=true", gotMetricName, gotUnitName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
t.Errorf("Metric name '%q' should contain unit name '%s' when WithMetricSuffixes=true", gotMetricName, gotUnitName)
t.Errorf("Metric name %q should contain unit name %q when WithMetricSuffixes=true", gotMetricName, gotUnitName)

if utf8Allowed {
require.Equal(t, test.label, result)
if test.label != result {
t.Errorf("labelNamer.Build(%q), got %q, want %q", test.label, result, test.label)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
t.Errorf("labelNamer.Build(%q), got %q, want %q", test.label, result, test.label)
t.Errorf("labelNamer.Build(%q) = %q, want %q", test.label, result, test.label)

} else {
require.Equal(t, test.expected, result)
if test.expected != result {
t.Errorf("labelNamer.Build(%q), got %q, want %q", test.label, result, test.expected)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
t.Errorf("labelNamer.Build(%q), got %q, want %q", test.label, result, test.expected)
t.Errorf("labelNamer.Build(%q) = %q, want %q", test.label, result, test.expected)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove usage of testify

5 participants