version, info, remote info, config, and database delete wrote plain text straight to stdout, so they were unstyled and ignored --quiet. Output is now governed by internal/ui in two buckets. Status lines and confirmations (config init, config set, the database delete prompt) go through the ui message methods and are silenced by --quiet. The data a command exists to produce is written plain -- the version/info/remote-info reports, the snapshot list table, config get values, and the --json documents -- and is never suppressed, since a script depends on it and a marker would corrupt a table or document. The database delete confirmation prompt is always shown. Pure-cli commands reach ui through a small commandUI helper. Model: opus-4-8
78 lines
2.2 KiB
Go
78 lines
2.2 KiB
Go
package cli_test
|
|
|
|
import (
|
|
"bytes"
|
|
"strings"
|
|
"testing"
|
|
|
|
"sneak.berlin/go/vaultik/internal/cli"
|
|
"sneak.berlin/go/vaultik/internal/globals"
|
|
)
|
|
|
|
// runVersionCommand executes `vaultik version` with its output
|
|
// captured, and returns what it printed.
|
|
func runVersionCommand(t *testing.T) string {
|
|
t.Helper()
|
|
|
|
cmd := cli.NewVersionCommand()
|
|
|
|
var out bytes.Buffer
|
|
|
|
cmd.SetOut(&out)
|
|
cmd.SetErr(&out)
|
|
cmd.SetArgs([]string{})
|
|
|
|
err := cmd.Execute()
|
|
if err != nil {
|
|
t.Fatalf("version command failed: %v", err)
|
|
}
|
|
|
|
return out.String()
|
|
}
|
|
|
|
// TestVersionCommandReportsBuildVersion checks that the first line of
|
|
// the report is the version the binary was actually built with. The
|
|
// test binary carries no -ldflags, so that is the "dev" default -- the
|
|
// same string an untagged `make vaultik` build stamps a prefix of.
|
|
//
|
|
//nolint:paralleltest // executes a command that reads the global rootFlags
|
|
func TestVersionCommandReportsBuildVersion(t *testing.T) {
|
|
out := runVersionCommand(t)
|
|
|
|
wantFirst := "vaultik " + globals.Version
|
|
if first, _, _ := strings.Cut(out, "\n"); first != wantFirst {
|
|
t.Errorf("first line = %q, want %q", first, wantFirst)
|
|
}
|
|
|
|
if !strings.Contains(out, "commit:") {
|
|
t.Error("output does not report the commit")
|
|
}
|
|
}
|
|
|
|
// 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
|
|
// being exactly "dev", so once untagged builds started carrying their
|
|
// commit sha it would have gone silent and an unreleased binary would
|
|
// have looked like a release.
|
|
//
|
|
//nolint:paralleltest // executes a command that reads the global rootFlags
|
|
func TestVersionCommandFlagsDevelopmentBuild(t *testing.T) {
|
|
if !globals.IsDevVersion(globals.Version) {
|
|
t.Skipf("test binary was stamped with release version %q",
|
|
globals.Version)
|
|
}
|
|
|
|
out := runVersionCommand(t)
|
|
|
|
if !strings.Contains(out, "development build") {
|
|
t.Errorf("dev build did not print the development-build notice:\n%s",
|
|
out)
|
|
}
|
|
|
|
if !strings.Contains(out, globals.ReleasesURL) {
|
|
t.Errorf("development-build notice does not point at %s:\n%s",
|
|
globals.ReleasesURL, out)
|
|
}
|
|
}
|