[test] Add test coverage for NewInfoMetrics#8168
[test] Add test coverage for NewInfoMetrics#8168chethanm99 wants to merge 15 commits intojaegertracing:mainfrom
Conversation
Signed-off-by: chethanm99 <chethanm1399@gmail.com>
There was a problem hiding this comment.
Pull request overview
Adds unit test coverage for internal/version.NewInfoMetrics, which initializes a build_info metric tagged with build/version metadata.
Changes:
- Add
TestNewInfoMetricsininternal/version/build_test.go. - Add
testify/requireimport 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>
There was a problem hiding this comment.
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
TestNewInfoMetricsforNewInfoMetrics. - Introduces usage of
internal/metricstesttest 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.
internal/version/build_test.go
Outdated
| 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>
Head branch was pushed to by a user without write access
There was a problem hiding this comment.
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
TestNewInfoMetricscoveringNewInfoMetrics. - Use
internal/metricstestfactory to assert thebuild_infogauge and its tags.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
internal/version/build_test.go
Outdated
| 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>
Head branch was pushed to by a user without write access
There was a problem hiding this comment.
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
NewInfoMetricsexports thebuild_infogauge with correct tags. - Introduced use of
internal/metricstestfactory 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>
There was a problem hiding this comment.
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
NewInfoMetricsvalidating the exportedbuild_infogauge and its tags. - Adds per-test cleanup to restore
commitSHA,latestVersion, anddateafter 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>
There was a problem hiding this comment.
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
setupBuildForTesthelper to set/resetcommitSHA,latestVersion, anddatein tests. - Update
TestGet/TestStringto use the helper. - Add
TestNewInfoMetricsverifying the emittedbuild_infogauge and tags viametricstest.Factory.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
internal/version/build_test.go
Outdated
| 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", | ||
| }, |
internal/version/build_test.go
Outdated
| @@ -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>
There was a problem hiding this comment.
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
TestNewInfoMetricsto validate the emittedbuild_infogauge and its tag set. - Add
setupBuildForTesthelper usingt.Cleanupto restorecommitSHA,latestVersion, anddateafter each test. - Update existing
TestGetandTestStringto use the new helper.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
internal/version/build_test.go
Outdated
| commitSHA = "foobar" | ||
| latestVersion = "v1.2.3" | ||
| date = "2024-01-04" | ||
| func setupBuildForTest(t *testing.T, commit, version, buildDate string) { |
internal/version/build_test.go
Outdated
| 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>
There was a problem hiding this comment.
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
setupBuildForTesthelper with cleanup to restore global build variables. - Adds
TestNewInfoMetricsto assertbuild_infogauge value and tags viainternal/metricstest.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
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
setupBuildForTesthelper to set/reset build globals (commitSHA,latestVersion,date) safely within tests. - Refactors existing
TestGetandTestStringto use the helper for cleaner test isolation. - Adds
TestNewInfoMetricsusinginternal/metricstestto assert thebuild_infogauge and its tags.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hi @yurishkuro , could you please have a look at this? |
Which problem is this PR solving?
Description of the changes
How was this change tested?
go tool cover -func=coverage.outto check coverage. This is the result:github.com/jaegertracing/jaeger/internal/version/build.go:45: NewInfoMetrics 100.0%Checklist
make lint testAI Usage in this PR (choose one)
See AI Usage Policy.