check / check (push) Successful in 1m41s
keyfunc --version printed dev for any binary not built with make build. When no version was stamped at build time, the tool now reports the module version recorded in the binary's build info, which go install fills in. A stamped version still wins, and a local build with neither still prints dev. Model: opus-4-8 (implementation); fable-5-1 (summary)
38 lines
971 B
Go
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))
|
|
})
|
|
}
|