-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[test] Add test coverage for NewInfoMetrics #8168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
3ac8c75
354cb61
baf3387
4d62bae
c0892db
ffd7bf9
7167dc2
c58197b
4f17c2b
5fd3acc
3a19958
60a0642
86598fc
743646a
ffe2e57
f49b41e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,14 +6,29 @@ package version | |
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/jaegertracing/jaeger/internal/metricstest" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestGet(t *testing.T) { | ||
| commitSHA = "foobar" | ||
| latestVersion = "v1.2.3" | ||
| date = "2024-01-04" | ||
| func setupBuildForTest(t *testing.T, commit, gitversion, buildDate string) { | ||
| t.Helper() | ||
| oldCommitSHA := commitSHA | ||
| oldLatestVersion := latestVersion | ||
| oldDate := date | ||
|
|
||
| t.Cleanup(func() { | ||
| commitSHA = oldCommitSHA | ||
| latestVersion = oldLatestVersion | ||
| date = oldDate | ||
| }) | ||
yurishkuro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| commitSHA = commit | ||
| latestVersion = gitversion | ||
| date = buildDate | ||
| } | ||
|
Comment on lines
+13
to
+28
|
||
|
|
||
| func TestGet(t *testing.T) { | ||
| setupBuildForTest(t, "foobar", "v1.2.3", "2024-01-04") | ||
| info := Get() | ||
|
|
||
| assert.Equal(t, commitSHA, info.GitCommit) | ||
|
|
@@ -22,9 +37,7 @@ func TestGet(t *testing.T) { | |
| } | ||
|
|
||
| func TestString(t *testing.T) { | ||
| commitSHA = "foobar" | ||
| latestVersion = "v1.2.3" | ||
| date = "2024-01-04" | ||
| setupBuildForTest(t, "foobar", "v1.2.3", "2024-01-04") | ||
| test := Info{ | ||
| GitCommit: commitSHA, | ||
| GitVersion: latestVersion, | ||
|
|
@@ -33,3 +46,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()) | ||
| } | ||
|
|
||
| func TestNewInfoMetrics(t *testing.T) { | ||
| setupBuildForTest(t, "foobar", "v1.2.3", "2024-01-04") | ||
| 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", | ||
| }, | ||
| }) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parameter name
gitversionis inconsistent with the rest of the codebase’sGitVersion/latestVersionnaming and is harder to read in call sites. Consider renaming it togitVersion(orversion) for clarity.