diff --git a/internal/cli/app.go b/internal/cli/app.go index 5b4fb50..bd54f1d 100644 --- a/internal/cli/app.go +++ b/internal/cli/app.go @@ -90,7 +90,7 @@ func setupGlobals( // blank line. Used both from the fx hook (for subcommand invocations) and // from the root cobra Run handler (for `vaultik` with no subcommand). func writeStartupBanner(w *ui.Writer, startTime time.Time, shortCommit string) { - w.Bannerf("%s %s by %s (commit %s, built on %s) starting up at %s.", + w.Bannerf("%s %s by %s (commit %s, commit date %s) starting up at %s.", globals.Appname, globals.Version, globals.Author, shortCommit, globals.CommitDate, startTime.Format(time.RFC3339)) diff --git a/internal/cli/entry_banner_test.go b/internal/cli/entry_banner_test.go index 26015d5..412b5d0 100644 --- a/internal/cli/entry_banner_test.go +++ b/internal/cli/entry_banner_test.go @@ -13,6 +13,7 @@ import ( "github.com/adrg/xdg" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "sneak.berlin/go/vaultik/internal/globals" ) // Command words and flags used to build argument vectors below. They are @@ -112,6 +113,35 @@ func TestBannerStillPrintedWithoutSuppressingFlag(t *testing.T) { } } +// TestBannerLabelsCommitDate checks that the banner prints the commit +// and the commit date, each after its own label. Commit and CommitDate +// get different values, so printing the wrong one fails. +// +//nolint:paralleltest // sets globals.Commit and globals.CommitDate +func TestBannerLabelsCommitDate(t *testing.T) { + const ( + commit = "abc1234" + commitDate = "2026-11-09" + ) + + previousCommit, previousCommitDate := globals.Commit, globals.CommitDate + + t.Cleanup(func() { + globals.Commit = previousCommit + globals.CommitDate = previousCommitDate + }) + + globals.Commit = commit + globals.CommitDate = commitDate + + var banner bytes.Buffer + + emitStartupBanner(nil, &banner) + + assert.Contains(t, banner.String(), + "(commit "+commit+", commit date "+commitDate+")") +} + // TestBannerSuppressedInArgs covers the suppression scan directly, // including the flags that suppressed the banner before --json joined // them, so that adding --json cannot regress them. diff --git a/internal/cli/version.go b/internal/cli/version.go index 0307060..400d6eb 100644 --- a/internal/cli/version.go +++ b/internal/cli/version.go @@ -37,13 +37,13 @@ func writeVersion(out *ui.Writer) { w := out.Out() _, _ = fmt.Fprintf(w, "vaultik %s\n", globals.Version) - _, _ = fmt.Fprintf(w, " commit: %s\n", globals.Commit) - _, _ = fmt.Fprintf(w, " build date: %s\n", globals.CommitDate) - _, _ = fmt.Fprintf(w, " go: %s\n", runtime.Version()) - _, _ = fmt.Fprintf(w, " os/arch: %s/%s\n", runtime.GOOS, runtime.GOARCH) - _, _ = fmt.Fprintf(w, " author: %s\n", globals.Author) - _, _ = fmt.Fprintf(w, " homepage: %s\n", globals.Homepage) - _, _ = fmt.Fprintf(w, " license: %s\n", globals.License) + _, _ = fmt.Fprintf(w, " commit: %s\n", globals.Commit) + _, _ = fmt.Fprintf(w, " commit date: %s\n", globals.CommitDate) + _, _ = fmt.Fprintf(w, " go: %s\n", runtime.Version()) + _, _ = fmt.Fprintf(w, " os/arch: %s/%s\n", runtime.GOOS, runtime.GOARCH) + _, _ = fmt.Fprintf(w, " author: %s\n", globals.Author) + _, _ = fmt.Fprintf(w, " homepage: %s\n", globals.Homepage) + _, _ = fmt.Fprintf(w, " license: %s\n", globals.License) if globals.IsDevVersion(globals.Version) { _, _ = fmt.Fprintln(w) diff --git a/internal/cli/version_test.go b/internal/cli/version_test.go index 7068f9d..3215029 100644 --- a/internal/cli/version_test.go +++ b/internal/cli/version_test.go @@ -2,6 +2,7 @@ package cli_test import ( "bytes" + "runtime" "strings" "testing" @@ -49,6 +50,42 @@ func TestVersionCommandReportsBuildVersion(t *testing.T) { } } +// TestVersionCommandReportLines checks the label, padding and value of +// every line of the report. Commit and CommitDate get different values, +// so a line that prints the wrong one fails. +// +//nolint:paralleltest // sets globals.Commit and globals.CommitDate +func TestVersionCommandReportLines(t *testing.T) { + const ( + commit = "abc1234" + commitDate = "2026-11-09" + ) + + previousCommit, previousCommitDate := globals.Commit, globals.CommitDate + + t.Cleanup(func() { + globals.Commit = previousCommit + globals.CommitDate = previousCommitDate + }) + + globals.Commit = commit + globals.CommitDate = commitDate + + want := "vaultik " + globals.Version + "\n" + + " commit: " + commit + "\n" + + " commit date: " + commitDate + "\n" + + " go: " + runtime.Version() + "\n" + + " os/arch: " + runtime.GOOS + "/" + runtime.GOARCH + "\n" + + " author: " + globals.Author + "\n" + + " homepage: " + globals.Homepage + "\n" + + " license: " + globals.License + "\n" + + out := runVersionCommand(t) + if !strings.HasPrefix(out, want) { + t.Errorf("report:\n%s\nwant it to start with:\n%s", out, want) + } +} + // TestVersionCommandFlagsDevelopmentBuild is the regression test for // the thing this command exists to prevent: a build that is not a // release must say so. The notice used to be gated on the version