test: add unit tests for pkg/version package#198
test: add unit tests for pkg/version package#198mason5052 wants to merge 1 commit intovxcontrol:masterfrom
Conversation
Add comprehensive unit tests for GetBinaryVersion, IsDevelopMode, and GetBinaryName functions covering all code paths including default values, custom values, and combined version-revision formatting.
There was a problem hiding this comment.
Pull request overview
Adds initial unit test coverage for the backend/pkg/version package, which provides binary name/version and “develop mode” detection used across the application.
Changes:
- Adds unit tests for
GetBinaryVersion()covering default, version-only, revision-only, and version+revision cases. - Adds unit tests for
IsDevelopMode()for both develop and non-develop scenarios. - Adds unit tests for
GetBinaryName()covering default and custom binary names.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| func TestGetBinaryVersion_Default(t *testing.T) { | ||
| PackageVer = "" | ||
| PackageRev = "" | ||
|
|
||
| result := GetBinaryVersion() | ||
| assert.Equal(t, "develop", result) | ||
| } |
There was a problem hiding this comment.
This test mutates package-level globals (PackageVer/PackageRev) but doesn’t restore their previous values at the end. That makes tests order-dependent and can leak state into subsequent tests in this package. Consider capturing the original values at the start and restoring them via defer (or t.Cleanup) so the test is isolated.
| func TestGetBinaryVersion_WithVersion(t *testing.T) { | ||
| PackageVer = "1.2.0" | ||
| PackageRev = "" | ||
| defer func() { PackageVer = "" }() | ||
|
|
||
| result := GetBinaryVersion() | ||
| assert.Equal(t, "1.2.0", result) | ||
| } |
There was a problem hiding this comment.
This test sets both PackageVer and PackageRev, but the cleanup only resets PackageVer and also doesn’t restore the prior PackageRev value. To avoid cross-test leakage, save the old values of both globals and restore both in the deferred cleanup.
| func TestIsDevelopMode_True(t *testing.T) { | ||
| PackageVer = "" | ||
|
|
||
| assert.True(t, IsDevelopMode()) | ||
| } |
There was a problem hiding this comment.
PackageVer is mutated here without any cleanup. If another test relies on a different PackageVer value, this can cause flakiness depending on execution order. Save/restore the previous value (defer or t.Cleanup) to keep this test isolated.
| func TestGetBinaryName_Default(t *testing.T) { | ||
| PackageName = "" | ||
|
|
||
| result := GetBinaryName() | ||
| assert.Equal(t, "pentagi", result) | ||
| } |
There was a problem hiding this comment.
PackageName is assigned here but not restored afterwards. Restoring the previous value at the end of the test avoids leaking state into other tests in this package (especially if future tests start running in parallel).
Description of Change
Problem: The
pkg/versionpackage has no unit test coverage. The package provides binary version, name, and development mode detection used throughout the application.Solution: Add comprehensive unit tests for all three exported functions (
GetBinaryVersion,IsDevelopMode,GetBinaryName) covering all code paths including default values, custom values, and combined version-revision formatting.Type of Change
Areas Affected
Testing and Verification
Test Configuration
Test Steps
go test ./pkg/version/... -vTest Results
Checklist
go fmtandgo vetrun