Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6da4315f57 |
No files matched your search
+1
-1
@@ -90,7 +90,7 @@ func setupGlobals(
|
|||||||
// blank line. Used both from the fx hook (for subcommand invocations) and
|
// blank line. Used both from the fx hook (for subcommand invocations) and
|
||||||
// from the root cobra Run handler (for `vaultik` with no subcommand).
|
// from the root cobra Run handler (for `vaultik` with no subcommand).
|
||||||
func writeStartupBanner(w *ui.Writer, startTime time.Time, shortCommit string) {
|
func writeStartupBanner(w *ui.Writer, startTime time.Time, shortCommit string) {
|
||||||
w.Bannerf("%s %s by %s (commit %s, commit date %s) starting up at %s.",
|
w.Bannerf("%s %s by %s (commit %s, built on %s) starting up at %s.",
|
||||||
globals.Appname, globals.Version, globals.Author,
|
globals.Appname, globals.Version, globals.Author,
|
||||||
shortCommit, globals.CommitDate,
|
shortCommit, globals.CommitDate,
|
||||||
startTime.Format(time.RFC3339))
|
startTime.Format(time.RFC3339))
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import (
|
|||||||
"github.com/adrg/xdg"
|
"github.com/adrg/xdg"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"sneak.berlin/go/vaultik/internal/globals"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Command words and flags used to build argument vectors below. They are
|
// Command words and flags used to build argument vectors below. They are
|
||||||
@@ -113,35 +112,6 @@ 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,
|
// TestBannerSuppressedInArgs covers the suppression scan directly,
|
||||||
// including the flags that suppressed the banner before --json joined
|
// including the flags that suppressed the banner before --json joined
|
||||||
// them, so that adding --json cannot regress them.
|
// them, so that adding --json cannot regress them.
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package cli_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -50,39 +49,22 @@ func TestVersionCommandReportsBuildVersion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestVersionCommandReportLines checks the label, padding and value of
|
// TestVersionCommandLabelsCommitDate checks that the date line is
|
||||||
// every line of the report. Commit and CommitDate get different values,
|
// labelled as the commit's date, which is what the build stamps into
|
||||||
// so a line that prints the wrong one fails.
|
// it, and that its value starts in the same column as the commit's.
|
||||||
//
|
//
|
||||||
//nolint:paralleltest // sets globals.Commit and globals.CommitDate
|
//nolint:paralleltest // executes a command that reads the global rootFlags
|
||||||
func TestVersionCommandReportLines(t *testing.T) {
|
func TestVersionCommandLabelsCommitDate(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)
|
out := runVersionCommand(t)
|
||||||
if !strings.HasPrefix(out, want) {
|
|
||||||
t.Errorf("report:\n%s\nwant it to start with:\n%s", out, want)
|
wantLine := " commit date: " + globals.CommitDate
|
||||||
|
if !strings.Contains(out, wantLine+"\n") {
|
||||||
|
t.Errorf("output has no line %q:\n%s", wantLine, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
wantCommit := " commit: " + globals.Commit
|
||||||
|
if !strings.Contains(out, wantCommit+"\n") {
|
||||||
|
t.Errorf("output has no line %q:\n%s", wantCommit, out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user