Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d6df8c2a2 | ||
|
|
13a35a986a |
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, 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,
|
globals.Appname, globals.Version, globals.Author,
|
||||||
shortCommit, globals.CommitDate,
|
shortCommit, globals.CommitDate,
|
||||||
startTime.Format(time.RFC3339))
|
startTime.Format(time.RFC3339))
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ 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
|
||||||
@@ -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,
|
// 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.
|
||||||
|
|||||||
@@ -37,13 +37,13 @@ func writeVersion(out *ui.Writer) {
|
|||||||
w := out.Out()
|
w := out.Out()
|
||||||
|
|
||||||
_, _ = fmt.Fprintf(w, "vaultik %s\n", globals.Version)
|
_, _ = fmt.Fprintf(w, "vaultik %s\n", globals.Version)
|
||||||
_, _ = fmt.Fprintf(w, " commit: %s\n", globals.Commit)
|
_, _ = fmt.Fprintf(w, " commit: %s\n", globals.Commit)
|
||||||
_, _ = fmt.Fprintf(w, " build date: %s\n", globals.CommitDate)
|
_, _ = fmt.Fprintf(w, " commit date: %s\n", globals.CommitDate)
|
||||||
_, _ = fmt.Fprintf(w, " go: %s\n", runtime.Version())
|
_, _ = fmt.Fprintf(w, " go: %s\n", runtime.Version())
|
||||||
_, _ = fmt.Fprintf(w, " os/arch: %s/%s\n", runtime.GOOS, runtime.GOARCH)
|
_, _ = fmt.Fprintf(w, " os/arch: %s/%s\n", runtime.GOOS, runtime.GOARCH)
|
||||||
_, _ = fmt.Fprintf(w, " author: %s\n", globals.Author)
|
_, _ = fmt.Fprintf(w, " author: %s\n", globals.Author)
|
||||||
_, _ = fmt.Fprintf(w, " homepage: %s\n", globals.Homepage)
|
_, _ = fmt.Fprintf(w, " homepage: %s\n", globals.Homepage)
|
||||||
_, _ = fmt.Fprintf(w, " license: %s\n", globals.License)
|
_, _ = fmt.Fprintf(w, " license: %s\n", globals.License)
|
||||||
|
|
||||||
if globals.IsDevVersion(globals.Version) {
|
if globals.IsDevVersion(globals.Version) {
|
||||||
_, _ = fmt.Fprintln(w)
|
_, _ = fmt.Fprintln(w)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package cli_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"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
|
// TestVersionCommandFlagsDevelopmentBuild is the regression test for
|
||||||
// the thing this command exists to prevent: a build that is not a
|
// 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
|
// release must say so. The notice used to be gated on the version
|
||||||
|
|||||||
@@ -271,16 +271,18 @@ func (sm *SnapshotManager) CompleteSnapshot(
|
|||||||
return sm.MarkSnapshotComplete(ctx, snapshotID)
|
return sm.MarkSnapshotComplete(ctx, snapshotID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExportSnapshotMetadata exports snapshot metadata to S3
|
// ExportSnapshotMetadata exports snapshot metadata to the backup destination store
|
||||||
//
|
//
|
||||||
// This method executes the complete snapshot metadata export process:
|
// This method executes the complete snapshot metadata export process:
|
||||||
// 1. Creates a temporary directory for working files
|
// 1. Creates a temporary directory for working files
|
||||||
// 2. Copies the main database to preserve its state
|
// 2. Copies the main database to preserve its state
|
||||||
// 3. Cleans the copy to contain only current snapshot data
|
// 3. Cleans the copy to contain only current snapshot data
|
||||||
// 4. Dumps the cleaned database to SQL
|
// 4. Vacuums the copy to remove the deleted data
|
||||||
// 5. Compresses the SQL dump with zstd
|
// 5. Compresses the copy with zstd
|
||||||
// 6. Encrypts the compressed data with age (always; recipients are required)
|
// 6. Encrypts the compressed copy with age (always; recipients are required)
|
||||||
// 7. Uploads to S3 at: snapshots/{snapshot-id}.sql.zst[.age]
|
// 7. Builds the blob manifest from the copy, compressed but not encrypted
|
||||||
|
// 8. Uploads the database to metadata/{remote-key}/db.zst.age
|
||||||
|
// 9. Uploads the manifest to metadata/{remote-key}/manifest.json.zst
|
||||||
//
|
//
|
||||||
// The only caller (finalizeSnapshotMetadata) does not close the main database
|
// The only caller (finalizeSnapshotMetadata) does not close the main database
|
||||||
// before calling this method: the index is copied at dbPath while it is still
|
// before calling this method: the index is copied at dbPath while it is still
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ var errStorageBindingMismatch = errors.New(
|
|||||||
// nothing and return nil.
|
// nothing and return nil.
|
||||||
// - When the two differ, refuse with an error that tells the user
|
// - When the two differ, refuse with an error that tells the user
|
||||||
// how to recover (revert the config, or run `vaultik database
|
// how to recover (revert the config, or run `vaultik database
|
||||||
// purge` to discard the local index and rebuild against the new
|
// delete` to discard the local index and rebuild against the new
|
||||||
// destination on the next backup).
|
// destination on the next backup).
|
||||||
//
|
//
|
||||||
// Read-only inspection commands (remote info, snapshot list, etc.)
|
// Read-only inspection commands (remote info, snapshot list, etc.)
|
||||||
|
|||||||
Reference in new issue
Block a user