cram/integration_test.sh

118 lines
3.7 KiB
Bash
Raw Permalink Normal View History

2022-07-29 05:38:26 +00:00
#!/usr/bin/env bash
set -ex
dest=$(mktemp -d)
2022-09-14 05:21:18 +00:00
PATH="$PATH:$(realpath .)"
PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
2022-07-29 05:38:26 +00:00
2022-09-14 05:21:18 +00:00
cram --help
root="test/integration"
function ,scrub() {
rm -rf "${dest}"/* .cram.log
}
2022-07-29 05:38:26 +00:00
# Should be able to list all packages
2022-09-14 05:21:18 +00:00
cram list "${root}" | grep "packages.d/p1"
,scrub
2022-07-29 05:38:26 +00:00
# P3 depends on P1, should show up in the listing
2022-09-14 05:21:18 +00:00
cram list "${root}" packages.d/p3 | grep "packages.d/p1"
,scrub
2022-07-29 05:38:26 +00:00
# P4 depends on P3, should show up in the listing
2022-09-14 05:21:18 +00:00
cram list "${root}" packages.d/p4 | grep "packages.d/p3"
,scrub
2022-07-29 05:38:26 +00:00
# The default profile should depend on its subpackage
2022-09-14 05:21:18 +00:00
cram list "${root}" profiles.d/default | grep "profiles.d/default/subpackage"
,scrub
2022-07-29 05:38:26 +00:00
# And the subpackage has a dep
2022-09-14 05:21:18 +00:00
cram list "${root}" profiles.d/default/subpackage | grep "packages.d/p3"
,scrub
2022-07-29 05:38:26 +00:00
# Install one package
2022-09-14 05:21:18 +00:00
cram apply --no-optimize --require packages.d/p1 --execute "${root}" "${dest}"
2022-07-29 05:38:26 +00:00
[ -L "${dest}"/foo ]
2022-09-14 05:21:18 +00:00
cram state "$root" | grep "${dest}/foo"
,scrub
2022-07-29 05:38:26 +00:00
# Install two transitively (legacy)
2022-09-14 05:21:18 +00:00
cram apply --no-optimize --require packages.d/p3 --execute "${root}" "${dest}"
2022-07-29 05:38:26 +00:00
[ -L "${dest}"/foo ]
[ -L "${dest}"/bar ]
2022-09-14 05:21:18 +00:00
cram state "$root" | grep "${dest}/foo"
cram state "$root" | grep "${dest}/bar"
,scrub
2022-07-29 05:38:26 +00:00
# Install two transitively (current)
2022-09-14 05:21:18 +00:00
cram apply --no-optimize --require packages.d/p4 --execute "${root}" "${dest}"
2022-07-29 05:38:26 +00:00
[ -L "${dest}"/foo ]
[ -L "${dest}"/bar ]
2022-09-14 05:21:18 +00:00
,scrub
2022-07-29 05:38:26 +00:00
# Install two transitively (current)
2022-09-14 05:21:18 +00:00
cram apply --no-optimize --require packages.d/p4 --execute "${root}" "${dest}"
2022-07-29 05:38:26 +00:00
[ -L "${dest}"/foo ]
[ -L "${dest}"/bar ]
2022-09-14 05:21:18 +00:00
,scrub
2022-07-29 05:38:26 +00:00
# Install two transitively (current)
2022-09-14 05:21:18 +00:00
cram apply --no-optimize --require hosts.d/test --require profiles.d/default --execute "${root}" "${dest}"
tree "${dest}"
2022-07-29 05:38:26 +00:00
[ -L "${dest}"/foo ]
[ -L "${dest}"/bar ]
2022-09-14 05:21:18 +00:00
,scrub
2022-07-29 05:38:26 +00:00
# INSTALL scripts get run as-is
2022-09-14 05:21:18 +00:00
cram list "${root}" packages.d/p5 | grep "packages.d/p5/INSTALL"
,scrub
2022-07-29 05:38:26 +00:00
# Inline scripts get pulled out repeatably
2022-09-14 05:21:18 +00:00
cram list "${root}" packages.d/p6 | grep "b5bea41b6c623f7c09f1bf24dcae58ebab3c0cdd90ad966bc43a45b44867e12b"
,scrub
2022-07-29 05:38:26 +00:00
# Inline scripts get pulled out repeatably, even from the list format
2022-09-14 05:21:18 +00:00
cram list "${root}" packages.d/p7 | grep "b5bea41b6c623f7c09f1bf24dcae58ebab3c0cdd90ad966bc43a45b44867e12b"
,scrub
2022-07-29 05:38:26 +00:00
# Test log-based optimization
2022-09-14 05:21:18 +00:00
cram apply --no-optimize --require packages.d/p4 --execute "${root}" "${dest}"
2022-07-29 05:38:26 +00:00
[ -L "${dest}"/foo ]
[ -L "${dest}"/bar ]
# These paths were already linked, they shouldn't be re-linked when optimizing.
2022-09-14 05:21:18 +00:00
! cram apply --require packages.d/p4 --optimize --execute "${root}" "${dest}" | grep "${dest}/foo"
! cram apply --require packages.d/p4 --optimize --execute "${root}" "${dest}" | grep "${dest}/bar"
,scrub
2022-07-29 05:38:26 +00:00
# Likewise, if we've exec'd this once we shouldn't do it again
2022-09-14 05:21:18 +00:00
cram apply --no-optimize --require packages.d/p5 --execute "${root}" "${dest}"
! cram apply --require packages.d/p5 --execute "${root}" "${dest}" | grep "exec"
,scrub
2022-07-29 05:38:26 +00:00
# ... unless the user tells us to
2022-09-14 05:21:18 +00:00
cram apply --no-optimize --require packages.d/p5 --execute "${root}" "${dest}"
cram apply --exec-always --require packages.d/p5 --execute "${root}" "${dest}" | grep "exec"
,scrub
2022-07-29 05:38:26 +00:00
# If multiple packages provide the same _effective_ script, do it once
2022-09-14 05:21:18 +00:00
cram apply --require packages.d/p6 --require packages.d/p7 --execute "${root}" "${dest}" | sort | uniq -c | grep "/tmp/stow/b5bea41b6c623f7c09f1bf24dcae58ebab3c0cdd90ad966bc43a45b44867e12b.sh" | grep "1 - exec"
,scrub
2022-07-29 05:38:26 +00:00
# Test log-based cleanup
2022-09-14 05:21:18 +00:00
cram apply --require packages.d/p1 --require packages.d/p2 --execute "${root}" "${dest}"
cram apply --require packages.d/p1 --require packages.d/p2 --execute "${root}" "${dest}"
2022-07-29 05:38:26 +00:00
[ -L "${dest}"/foo ]
[ -L "${dest}"/bar ]
2022-09-14 05:21:18 +00:00
2022-07-29 05:38:26 +00:00
# And how bar shouldn't be installed...
2022-09-14 05:21:18 +00:00
cram apply --require packages.d/p1 --execute "${root}" "${dest}"
cram state "${root}"
2022-07-29 05:38:26 +00:00
[ -L "${dest}"/foo ]
[ ! -L "${dest}"/bar ]
2022-09-14 05:21:18 +00:00
,scrub