check / check (push) Failing after 17m39s
The value is the commit's date, which the Makefile and the Dockerfile stamp in, not the time of the build. The other labels gain one space so every value still starts in one column. Model: opus-5-5
97 lines
2.8 KiB
Go
97 lines
2.8 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")
|
|
}
|
|
}
|
|
|
|
// TestVersionCommandLabelsCommitDate checks that the date line is
|
|
// labelled as the commit's date, which is what the build stamps into
|
|
// it, and that its value starts in the same column as the commit's.
|
|
//
|
|
//nolint:paralleltest // executes a command that reads the global rootFlags
|
|
func TestVersionCommandLabelsCommitDate(t *testing.T) {
|
|
out := runVersionCommand(t)
|
|
|
|
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)
|
|
}
|
|
}
|
|
|
|
// 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)
|
|
}
|
|
}
|