Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions internal/version/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

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

Parameter name gitversion is inconsistent with the rest of the codebase’s GitVersion / latestVersion naming and is harder to read in call sites. Consider renaming it to gitVersion (or version) for clarity.

Copilot uses AI. Check for mistakes.
t.Helper()
oldCommitSHA := commitSHA
oldLatestVersion := latestVersion
oldDate := date

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

commitSHA = commit
latestVersion = gitversion
date = buildDate
}
Comment on lines +13 to +28
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

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

setupBuildForTest introduces proper cleanup for the package-level build variables, but other tests in this package (e.g., command_test.go / handler_test.go) still mutate commitSHA / latestVersion / date without restoring them. This keeps the test suite order-dependent and makes it harder to safely add t.Parallel() later. Consider moving this helper to a shared _test.go helper file and updating the other tests to use it so all tests consistently restore global state.

Copilot uses AI. Check for mistakes.

func TestGet(t *testing.T) {
setupBuildForTest(t, "foobar", "v1.2.3", "2024-01-04")
info := Get()

assert.Equal(t, commitSHA, info.GitCommit)
Expand All @@ -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,
Expand All @@ -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",
},
})
}
Loading