better test + migration
This commit is contained in:
1 parent
27b713affa
commit
ab8260a5d0
8 files changed
+202
-34
No files matched your search
+16
-6
@@ -55,7 +55,19 @@ def "main migrate" [
|
||||
# leftovers from a prior rootless-container deployment) without that
|
||||
# aborting an otherwise-successful migration - tar still warns about it,
|
||||
# it just doesn't fail the whole pipeline over it.
|
||||
^tar --ignore-failed-read -C $source -cf - . | run-argv ($ssh_base ++ [$"mkdir -p '($dest)' && tar -C '($dest)' -xf -"])
|
||||
#
|
||||
# --exclude='./.local/bin': launcher scripts in .local/bin are
|
||||
# environment-specific (Docker wrappers, old arch builds, etc.) and must
|
||||
# never be carried into the guest. hermes-install.service installs the
|
||||
# correct native binary there on first boot; an overwritten launcher from
|
||||
# the source would shadow it and fail with "docker not found on PATH".
|
||||
#
|
||||
# --exclude='./.hermes-installed': this sentinel tells hermes-install to
|
||||
# skip the native install. Migrating it from the source would prevent the
|
||||
# guest from ever installing hermes if the source's .local/bin/hermes is
|
||||
# also excluded (above). Let the install service run and place a fresh
|
||||
# binary instead.
|
||||
^tar --ignore-failed-read --exclude='./.local/bin' --exclude='./.hermes-installed' -C $source -cf - . | run-argv ($ssh_base ++ [$"mkdir -p '($dest)' && tar -C '($dest)' -xf -"])
|
||||
|
||||
step 3 "rewriting stale hostnames in the guest"
|
||||
let last_idx = ($rewrite_from | length) - 1
|
||||
@@ -168,12 +180,10 @@ def "main migrate connections" [
|
||||
gssh "true"
|
||||
|
||||
step 2 $"streaming connection files ($source) -> guest:($guest_dest)"
|
||||
# Build an include list for tar: individual files + full dir trees.
|
||||
let file_args = $existing_files | each {|f| ["--include" $f] } | flatten
|
||||
let dir_args = $existing_dirs | each {|d| ["--include" $"($d)/**"] } | flatten
|
||||
let tar_args = $file_args | append $dir_args | append ["--no-recursion" "-cf" "-" "."]
|
||||
# Pass files and dirs as positional tar arguments — no --include needed.
|
||||
let tar_targets = $existing_files | append $existing_dirs
|
||||
(
|
||||
^tar --ignore-failed-read -C $source ...$tar_args
|
||||
^tar --ignore-failed-read -C $source -cf - ...$tar_targets
|
||||
| run-argv ($ssh_base ++ [$"mkdir -p '($guest_dest)' && tar -C '($guest_dest)' -xf -"])
|
||||
)
|
||||
|
||||
|
||||
+22
-24
@@ -18,11 +18,9 @@ def build-sed-expr [from: list<string>, to: list<string>] {
|
||||
| str join "; ")
|
||||
}
|
||||
|
||||
# Reproduce the tar-args assembly (everything after `tar -C $source`).
|
||||
def build-tar-args [files: list<string>, dirs: list<string>] {
|
||||
let file_args = $files | each {|f| ["--include" $f] } | flatten
|
||||
let dir_args = $dirs | each {|d| ["--include" $"($d)/**"] } | flatten
|
||||
$file_args | append $dir_args | append ["--no-recursion" "-cf" "-" "."]
|
||||
# Reproduce the tar-targets assembly (positional args after `tar -cf -`).
|
||||
def build-tar-targets [files: list<string>, dirs: list<string>] {
|
||||
$files | append $dirs
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -42,31 +40,25 @@ def "sed expr pairs are joined with semicolons" [] {
|
||||
}
|
||||
|
||||
@test
|
||||
def "tar args: flat files produce paired --include entries" [] {
|
||||
let args = build-tar-args [config.yaml .env] []
|
||||
assert ("--include" in $args)
|
||||
assert ("config.yaml" in $args)
|
||||
assert (".env" in $args)
|
||||
def "tar targets: contains all files and dirs" [] {
|
||||
let targets = build-tar-targets [config.yaml auth.json .env] [connections]
|
||||
assert ("config.yaml" in $targets)
|
||||
assert ("auth.json" in $targets)
|
||||
assert (".env" in $targets)
|
||||
assert ("connections" in $targets)
|
||||
}
|
||||
|
||||
@test
|
||||
def "tar args: dirs produce glob --include entries" [] {
|
||||
let args = build-tar-args [] [connections]
|
||||
assert ("connections/**" in $args)
|
||||
def "tar targets: no --include flags or globs" [] {
|
||||
let targets = build-tar-targets [config.yaml] [connections]
|
||||
assert (not ("--include" in $targets))
|
||||
assert (not (($targets | any {|x| $x | str contains "**" })))
|
||||
}
|
||||
|
||||
@test
|
||||
def "tar args: always end with --no-recursion -cf - ." [] {
|
||||
let args = build-tar-args [config.yaml] [connections]
|
||||
let tail = $args | last 4
|
||||
assert equal $tail ["--no-recursion" "-cf" "-" "."]
|
||||
}
|
||||
|
||||
@test
|
||||
def "tar args: result is a flat list of strings spreadable with spread operator" [] {
|
||||
let args = build-tar-args [config.yaml auth.json] [connections]
|
||||
# Every element must be a string so `...$args` works with ^tar.
|
||||
let all_strings = $args | all {|x| ($x | describe) == "string" }
|
||||
def "tar targets: result is a flat list of strings spreadable with spread operator" [] {
|
||||
let targets = build-tar-targets [config.yaml auth.json] [connections]
|
||||
let all_strings = $targets | all {|x| ($x | describe) == "string" }
|
||||
assert $all_strings
|
||||
}
|
||||
|
||||
@@ -75,3 +67,9 @@ def "migrate connections is registered in the command tree" [] {
|
||||
let names = scope commands | where name =~ '^main' | get name
|
||||
assert ("main migrate connections" in $names)
|
||||
}
|
||||
|
||||
@test
|
||||
def "main migrate is registered in the command tree" [] {
|
||||
let names = scope commands | where name =~ '^main' | get name
|
||||
assert ("main migrate" in $names)
|
||||
}
|
||||
Reference in new issue
Block a user