Skip to content

[test] Add test coverage for NewInfoMetrics#8168

Open
chethanm99 wants to merge 15 commits intojaegertracing:mainfrom
chethanm99:add_unit_test
Open

[test] Add test coverage for NewInfoMetrics#8168
chethanm99 wants to merge 15 commits intojaegertracing:mainfrom
chethanm99:add_unit_test

Conversation

@chethanm99
Copy link

@chethanm99 chethanm99 commented Mar 13, 2026

Which problem is this PR solving?

  • This PR adds test coverage for NewInfoMetrics function.

Description of the changes

  • This PR increase the unit test coverage by adding unit test for NewInfoMetrics function.

How was this change tested?

  • This change was tested by running make fmt, make lint and make test. Also additionally ran: go tool cover -func=coverage.out to check coverage. This is the result: github.com/jaegertracing/jaeger/internal/version/build.go:45: NewInfoMetrics 100.0%

Checklist

AI Usage in this PR (choose one)

See AI Usage Policy.

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

Signed-off-by: chethanm99 <chethanm1399@gmail.com>
@chethanm99 chethanm99 requested a review from a team as a code owner March 13, 2026 11:39
Copilot AI review requested due to automatic review settings March 13, 2026 11:39
Copy link
Contributor

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

Adds unit test coverage for internal/version.NewInfoMetrics, which initializes a build_info metric tagged with build/version metadata.

Changes:

  • Add TestNewInfoMetrics in internal/version/build_test.go.
  • Add testify/require import to support the new test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: chethanm99 <chethanm1399@gmail.com>
@yurishkuro yurishkuro requested a review from Copilot March 13, 2026 20:14
@yurishkuro yurishkuro added the changelog:test Change that's adding missing tests or correcting existing tests label Mar 13, 2026
@yurishkuro yurishkuro enabled auto-merge March 13, 2026 20:15
Copy link
Contributor

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

Adds unit test coverage for NewInfoMetrics in internal/version, ensuring the build-info gauge is emitted with the expected tags and value.

Changes:

  • Adds a new unit test TestNewInfoMetrics for NewInfoMetrics.
  • Introduces usage of internal/metricstest test factory to snapshot recorded metrics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +48 to +55
snapshot, _ := f.Snapshot()

key := "build_info|build_date=2024-01-04,revision=foobar,version=v1.2.3"
value, ok := snapshot[key]

if assert.True(t, ok, "expected build_info gauge with key %q", key) {
assert.EqualValues(t, 1, value)
}
Signed-off-by: chethanm99 <chethanm1399@gmail.com>
auto-merge was automatically disabled March 14, 2026 02:56

Head branch was pushed to by a user without write access

@yurishkuro yurishkuro enabled auto-merge March 14, 2026 03:27
Copilot AI review requested due to automatic review settings March 14, 2026 07:03
Copy link
Contributor

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

Adds unit test coverage for NewInfoMetrics in internal/version, validating that the build_info gauge is emitted with the expected value and build tags.

Changes:

  • Add a new unit test TestNewInfoMetrics covering NewInfoMetrics.
  • Use internal/metricstest factory to assert the build_info gauge and its tags.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

f := metricstest.NewFactory(0)
defer f.Stop()

_ = NewInfoMetrics(f)
Signed-off-by: chethanm99 <chethanm1399@gmail.com>
Signed-off-by: chethanm99 <chethanm1399@gmail.com>
Signed-off-by: chethanm99 <chethanm1399@gmail.com>
Copilot AI review requested due to automatic review settings March 14, 2026 07:17
auto-merge was automatically disabled March 14, 2026 07:17

Head branch was pushed to by a user without write access

Copy link
Contributor

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 adds unit test coverage for the NewInfoMetrics function in internal/version, ensuring build info metrics are emitted with the expected tags and value.

Changes:

  • Added a new unit test validating NewInfoMetrics exports the build_info gauge with correct tags.
  • Introduced use of internal/metricstest factory to assert emitted gauge metrics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: chethanm99 <chethanm1399@gmail.com>
Copy link
Contributor

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

Adds unit tests for NewInfoMetrics in internal/version to increase coverage and verify that build metadata is emitted as build_info gauge tags.

Changes:

  • Adds a new unit test for NewInfoMetrics validating the exported build_info gauge and its tags.
  • Adds per-test cleanup to restore commitSHA, latestVersion, and date after mutations in existing tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: chethanm99 <chethanm1399@gmail.com>
Copilot AI review requested due to automatic review settings March 15, 2026 03:10
Copy link
Contributor

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

Adds unit test coverage for NewInfoMetrics in internal/version, and refactors existing version tests to use a shared setup helper that restores global build variables via t.Cleanup().

Changes:

  • Introduce setupBuildForTest helper to set/reset commitSHA, latestVersion, and date in tests.
  • Update TestGet / TestString to use the helper.
  • Add TestNewInfoMetrics verifying the emitted build_info gauge and tags via metricstest.Factory.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +50 to +63
setupBuildForTest(t, "foobar", "v1.2.3", "2024-01-01")
f := metricstest.NewFactory(0)
defer f.Stop()

NewInfoMetrics(f)

f.AssertGaugeMetrics(t, metricstest.ExpectedMetric{
Name: "build_info",
Value: 1,
Tags: map[string]string{
"build_date": "2024-01-04",
"revision": "foobar",
"version": "v1.2.3",
},
Comment on lines 39 to 46
@@ -33,3 +45,21 @@ func TestString(t *testing.T) {
expectedOutput := "git-commit=foobar, git-version=v1.2.3, build-date=2024-01-04"
assert.Equal(t, expectedOutput, test.String())
Signed-off-by: chethanm99 <chethanm1399@gmail.com>
Copy link
Contributor

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

Adds unit test coverage for NewInfoMetrics in internal/version, while refactoring existing version tests to avoid leaking global build variables across test cases.

Changes:

  • Introduce TestNewInfoMetrics to validate the emitted build_info gauge and its tag set.
  • Add setupBuildForTest helper using t.Cleanup to restore commitSHA, latestVersion, and date after each test.
  • Update existing TestGet and TestString to use the new helper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

commitSHA = "foobar"
latestVersion = "v1.2.3"
date = "2024-01-04"
func setupBuildForTest(t *testing.T, commit, version, buildDate string) {
Comment on lines +13 to +26
func setupBuildForTest(t *testing.T, commit, version, buildDate string) {
oldCommitSHA := commitSHA
oldLatestVersion := latestVersion
oldDate := date

t.Cleanup(func() {
commitSHA = oldCommitSHA
latestVersion = oldLatestVersion
date = oldDate
})

commitSHA = commit
latestVersion = version
date = buildDate
Signed-off-by: chethanm99 <chethanm1399@gmail.com>
Copy link
Contributor

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

Adds unit test coverage for NewInfoMetrics in internal/version, verifying that the build_info gauge is emitted with the expected value and build tags.

Changes:

  • Refactors existing tests to use a shared setupBuildForTest helper with cleanup to restore global build variables.
  • Adds TestNewInfoMetrics to assert build_info gauge value and tags via internal/metricstest.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings March 20, 2026 05:45
Copy link
Contributor

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

Adds unit test coverage for NewInfoMetrics in internal/version, ensuring the build-info gauge metric is emitted with the expected tags and value.

Changes:

  • Introduces setupBuildForTest helper to set/reset build globals (commitSHA, latestVersion, date) safely within tests.
  • Refactors existing TestGet and TestString to use the helper for cleaner test isolation.
  • Adds TestNewInfoMetrics using internal/metricstest to assert the build_info gauge and its tags.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@chethanm99
Copy link
Author

chethanm99 commented Mar 20, 2026

Hi @yurishkuro , could you please have a look at this?
Thanks for your time

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

Labels

changelog:test Change that's adding missing tests or correcting existing tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants