mesh/delivery superseded: a newer head of the same pull request
mesh/check failed: the composition: the manifest of pacman cannot be read: this manifest cannot be used: | 19c1d35939bc on 8c6e18e82286 | unit 4799 ru…
71 lines
3.0 KiB
Go
71 lines
3.0 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)
|
|
}
|
|
}
|
|
|
|
// The shape go gives `go build <the SDK's command>` run in a module that requires the SDK (captured with go1.27 from
|
|
// mesh-compose built in a reader's tree at bc0c25e51052: "mod git.novox.be/novox/mesh-sdk/go v0.1.14-…-bc0c25e51052",
|
|
// no vcs settings): the SDK is the main module at the pinned version, which names the SDK the binary carries.
|
|
func TestAnSDKCommandBuiltFromAReaderIsThePinnedVersion(t *testing.T) {
|
|
bi := &debug.BuildInfo{Path: sdkPath + "/cmd/mesh-compose",
|
|
Main: debug.Module{Path: sdkPath, Version: "v0.1.14-0.20261024112544-bc0c25e51052"},
|
|
Settings: []debug.BuildSetting{{Key: "-trimpath", Value: "true"}, {Key: "CGO_ENABLED", Value: "0"}}}
|
|
if got := FromBuildInfo(bi); got != "v0.1.14-0.20261024112544-bc0c25e51052" {
|
|
t.Fatalf("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")
|
|
}
|
|
}
|