Files
keyfunc/internal/cli/version_internal_test.go
T
sneak 85890f19bc
check / check (push) Failing after 1s
Report the module version for a go install build (closes #18)
--version printed "dev" for any binary not built with make build, so a
user running a go install build could not say what version they had.

resolveVersion now falls back to the module version from
runtime/debug.ReadBuildInfo() when the build-time stamp is absent,
ignoring the "(devel)" of a local build. The stamped value still wins
when present. It takes the build info as an argument, so a test covers
the choice without a real build.

Model: opus-4-8
2026-09-21 07:33:08 +00:00

38 lines
971 B
Go

package cli
import (
"runtime/debug"
"testing"
"github.com/stretchr/testify/require"
)
func TestResolveVersion(t *testing.T) {
t.Parallel()
release := &debug.BuildInfo{Main: debug.Module{Version: "v1.2.3"}}
local := &debug.BuildInfo{Main: debug.Module{Version: "(devel)"}}
empty := &debug.BuildInfo{}
t.Run("stamped value wins over build info", func(t *testing.T) {
t.Parallel()
require.Equal(t, "v0.1.0", resolveVersion("v0.1.0", release))
})
t.Run("go install reports the module version", func(t *testing.T) {
t.Parallel()
require.Equal(t, "v1.2.3", resolveVersion(devVersion, release))
})
t.Run("a local build stays dev", func(t *testing.T) {
t.Parallel()
require.Equal(t, devVersion, resolveVersion(devVersion, local))
})
t.Run("no version anywhere stays dev", func(t *testing.T) {
t.Parallel()
require.Equal(t, devVersion, resolveVersion(devVersion, empty))
require.Equal(t, devVersion, resolveVersion(devVersion, nil))
})
}