29 lines
959 B
Go
29 lines
959 B
Go
// Copyright (c) 2026 Storm Dragon
|
|
// Authors: Storm Dragon, Angus Kola
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package version
|
|
|
|
import (
|
|
"runtime/debug"
|
|
"testing"
|
|
)
|
|
|
|
func TestBuildIdentityUsesEmbeddedSettings(t *testing.T) {
|
|
info := &debug.BuildInfo{GoVersion: "go1.24.0", Settings: []debug.BuildSetting{
|
|
{Key: "vcs.revision", Value: "0123456789abcdef"},
|
|
{Key: "vcs.time", Value: "2026-10-16T12:00:00Z"},
|
|
{Key: "vcs.modified", Value: "true"},
|
|
}}
|
|
identity := build_identity(info)
|
|
if identity != (Identity{"go1.24.0", "0123456789abcdef", "2026-10-16T12:00:00Z", "true"}) {
|
|
t.Fatalf("embedded build identity = %+v", identity)
|
|
}
|
|
for _, info := range []*debug.BuildInfo{nil, {GoVersion: "go1.24.0"}} {
|
|
identity := build_identity(info)
|
|
if identity.GoVersion == "" || identity.Revision != "unknown" || identity.Time != "unknown" || identity.Modified != "unknown" {
|
|
t.Fatalf("unstamped build falsely identified: %+v", identity)
|
|
}
|
|
}
|
|
}
|