Skip to content

Commit

Permalink
fix: update and re-enable test "test can read previous version's cach…
Browse files Browse the repository at this point in the history
…e" (project-stacker#463)

Commit 9671d8f disabled the caching.bats test
"test can read previous version's cache".

This re-enables that test after updating it to use a specific value
(v1.0.0-rc4) as the "previous version".

The change to use a specific version and use its released binary
improves the test. That improves the test for the following
reasons:

 * This should be faster - we don't have to build stacker twice.
 * Ultimately testing against the last released version is probably what
   you want... that is the cache that your users have, not the last
   development commit.
 * Building stacker from another version is both slow and hard to
   guarantee. This removes the assumption that the current build
   environment can build another version of stacker.
 * There was assumed knowledge about both the current and other stacker
   build systems in the 'make LXC_BRANCH=$(grep ...)' command.
 * The prior version of the test used "current/main" as "previous", but
   current/main is a moving target.  Re-running a checkout
   at a future point in time may fail as current/main has moved forward.
   (Think about using 'git bisect' to diagnose a past regression)
 * Even when working as intended, a series of PRs could still break
   re-use of the cache.  Given PRs A, B, C that all are merged to
   master.  B is tested against A, C is tested against B, but
   nothing tested C against A.

The change here *does* mean the following things are true, which are
possibly undesirable:

 * There is a requirement to update the old version string.
   v1.0.0-rc4 is an arbitrary value.
 * The old binary must run in the current build environment.  This
   may be hard to guarantee.  I'm honestly not sure if static binary
   will be more reliable than building and executing a specific old
   version of source.

Signed-off-by: Scott Moser <smoser@brickies.net>
  • Loading branch information
smoser authored Apr 28, 2023
1 parent 02cb2ac commit b4f7294
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions test/caching.bats
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,19 @@ EOF
}

@test "can read previous version's cache" {
skip "old stacker will not build because libsquashfs1-dev is not installed"
git clone https://github.com/project-stacker/stacker
(cd stacker && make LXC_BRANCH=$(grep ^LXC_BRANCH Makefile | cut -d'=' -f 2) LXC_CLONE_URL=$LXC_CLONE_URL)

# some additional testing that the cache can be read by older versions of
# stacker (cache_test.go has the full test for the type, this just checks
# the mechanics of filepaths and such)
local relurl="https://github.com/project-stacker/stacker/releases/download"
local oldver="v1.0.0-rc4"
local oldbin="./stacker-$oldver"
if [ "$PRIVILEGE_LEVEL" != "priv" ]; then
skip_if_no_unpriv_overlay
fi

wget -O "$oldbin" --progress=dot:mega "$relurl/$oldver/stacker"
chmod 755 "$oldbin"

touch foo
cat > stacker.yaml <<EOF
test:
Expand All @@ -203,13 +209,7 @@ test:
run: cp /stacker/foo /foo
EOF

if [ "$PRIVILEGE_LEVEL" = "priv" ]; then
./stacker/stacker --debug build
else
skip_if_no_unpriv_overlay
sudo -u $SUDO_USER ./stacker/stacker --debug build
fi

run_as "$oldbin" --debug build
stacker build
}

Expand Down

0 comments on commit b4f7294

Please sign in to comment.