59 lines
2.2 KiB
Go
59 lines
2.2 KiB
Go
package sdkversion
|
|
|
|
import (
|
|
"runtime/debug"
|
|
"testing"
|
|
)
|
|
|
|
const sdkPath = "git.novox.be/novox/mesh-sdk/go"
|
|
|
|
// The build infos are constructed in the shape runtime/debug.ReadBuildInfo gives a binary that imports the SDK
|
|
// (go.mod pins like mesh-controller's v0.1.14-0.20261019091011-aa68b67389c9).
|
|
func TestAPinnedDependencyIsItsPseudoVersion(t *testing.T) {
|
|
bi := &debug.BuildInfo{Main: debug.Module{Path: "github.com/novox/mesh-controller", Version: "(devel)"},
|
|
Deps: []*debug.Module{{Path: "example.org/other", Version: "v1.0.0"}, {Path: sdkPath, Version: "v0.1.14-0.20261019091011-aa68b67389c9"}}}
|
|
if got := FromBuildInfo(bi); got != "v0.1.14-0.20261019091011-aa68b67389c9" {
|
|
t.Fatalf("got %q", got)
|
|
}
|
|
}
|
|
|
|
func TestAReplacedDependencyIsTheReplacement(t *testing.T) {
|
|
bi := &debug.BuildInfo{Main: debug.Module{Path: "x"}, Deps: []*debug.Module{{Path: sdkPath, Version: "v0.1.14",
|
|
Replace: &debug.Module{Path: sdkPath, Version: "v0.2.0-0.20261020000000-abcdef123456"}}}}
|
|
if got := FromBuildInfo(bi); got != "v0.2.0-0.20261020000000-abcdef123456" {
|
|
t.Fatalf("got %q", got)
|
|
}
|
|
local := &debug.BuildInfo{Main: debug.Module{Path: "x"}, Deps: []*debug.Module{{Path: sdkPath, Version: "v0.1.14",
|
|
Replace: &debug.Module{Path: "../mesh-sdk/go"}}}}
|
|
if got := FromBuildInfo(local); got != "../mesh-sdk/go" {
|
|
t.Fatalf("a local replacement: got %q", got)
|
|
}
|
|
}
|
|
|
|
func TestTheMainModuleIsDevelWithItsRevision(t *testing.T) {
|
|
bi := &debug.BuildInfo{Main: debug.Module{Path: sdkPath, Version: "(devel)"},
|
|
Settings: []debug.BuildSetting{{Key: "vcs", Value: "git"}, {Key: "vcs.revision", Value: "5786ba190c69bcee983223dbbc149bfb18fe01ed"}}}
|
|
if got := FromBuildInfo(bi); got != "(devel) 5786ba190c69bcee983223dbbc149bfb18fe01ed" {
|
|
t.Fatalf("got %q", got)
|
|
}
|
|
bare := &debug.BuildInfo{Main: debug.Module{Path: sdkPath, Version: "(devel)"}}
|
|
if got := FromBuildInfo(bare); got != "(devel)" {
|
|
t.Fatalf("no stamp: got %q", got)
|
|
}
|
|
}
|
|
|
|
func TestNoBuildInfoIsUnknown(t *testing.T) {
|
|
if got := FromBuildInfo(nil); got != "unknown" {
|
|
t.Fatalf("got %q", got)
|
|
}
|
|
if got := FromBuildInfo(&debug.BuildInfo{Main: debug.Module{Path: "x"}}); got != "unknown" {
|
|
t.Fatalf("an SDK-less binary: got %q", got)
|
|
}
|
|
}
|
|
|
|
func TestVersionIsNeverEmpty(t *testing.T) {
|
|
if Version() == "" {
|
|
t.Fatal("empty")
|
|
}
|
|
}
|