1// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
2//
3// SPDX-License-Identifier: LicenseRef-MutuaL-1.2
4
5package main
6
7import (
8 "runtime/debug"
9 "testing"
10)
11
12func TestVersionFromBuildInfoPrefersModuleVersion(t *testing.T) {
13 got := versionFromBuildInfo(&debug.BuildInfo{Main: debug.Module{Version: "1.2.3"}})
14 if got != "1.2.3" {
15 t.Fatalf("versionFromBuildInfo() = %q, want 1.2.3", got)
16 }
17}
18
19func TestVersionFromBuildInfoFallsBackToVCSRevision(t *testing.T) {
20 got := versionFromBuildInfo(&debug.BuildInfo{
21 Main: debug.Module{Version: "(devel)"},
22 Settings: []debug.BuildSetting{
23 {Key: "vcs.revision", Value: "abc123"},
24 {Key: "vcs.modified", Value: "true"},
25 },
26 })
27 if got != "abc123-dirty" {
28 t.Fatalf("versionFromBuildInfo() = %q, want abc123-dirty", got)
29 }
30}