|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -e |
| 3 | +set -x |
| 4 | +cd tests/ |
| 5 | +mkdir -p ./tmp/ |
| 6 | +cd ./tmp/ |
| 7 | +touch cfbs.json && rm cfbs.json |
| 8 | +rm -rf .git |
| 9 | + |
| 10 | +# Inspect the masterfiles module specifically, rather than grepping the whole |
| 11 | +# file (which could match a field belonging to a different module). |
| 12 | +mf() { jq -r --arg k "$1" '.build[] | select(.name == "masterfiles") | .[$k]' cfbs.json; } |
| 13 | +mf_has() { jq -r --arg k "$1" '.build[] | select(.name == "masterfiles") | has($k)' cfbs.json; } |
| 14 | + |
| 15 | +# Start on an old version of masterfiles. |
| 16 | +cfbs --non-interactive init --masterfiles=3.24.1 |
| 17 | +[ "$(mf version)" = "3.24.1" ] |
| 18 | +[ "$(mf commit)" = "1171e2e50a229d78e2fdd4357a5d07ecc19bdbf4" ] |
| 19 | + |
| 20 | +# Update to a specific intermediate version (not the latest). This must pin to |
| 21 | +# exactly 3.24.4, not jump to the newest release in the index. |
| 22 | +cfbs --non-interactive update masterfiles@3.24.4 |
| 23 | +[ "$(mf version)" = "3.24.4" ] |
| 24 | +[ "$(mf commit)" = "ed4628805e352fd68d7d72664c859df5a4bb0715" ] |
| 25 | +# Why we assert on "subdirectory" here: pinning an update to a version now routes |
| 26 | +# through index.get_module_object() *with that version*, which reads the |
| 27 | +# per-version index. That index stores an empty "subdirectory" ("") for modules |
| 28 | +# that don't have one, and an empty subdirectory is invalid and breaks validation |
| 29 | +# and build. So get_module_object() now has to drop it (matching how 'cfbs add' |
| 30 | +# cleans the module up). This asserts it does not leak into cfbs.json, and the |
| 31 | +# following 'cfbs validate' confirms the resulting module is actually valid. |
| 32 | +[ "$(mf_has subdirectory)" = "false" ] |
| 33 | +cfbs validate |
| 34 | + |
| 35 | +# Asking again for the same version is a no-op. |
| 36 | +cfbs --non-interactive update masterfiles@3.24.4 |
| 37 | +[ "$(mf version)" = "3.24.4" ] |
| 38 | + |
| 39 | +# Asking for an older version than the current one must not downgrade. |
| 40 | +cfbs --non-interactive update masterfiles@3.24.1 |
| 41 | +[ "$(mf version)" = "3.24.4" ] |
| 42 | + |
| 43 | +# A plain update (no @version) still moves to a strictly newer version than the |
| 44 | +# pin. Checking "!= 3.24.4" alone would also pass on a downgrade, so verify that |
| 45 | +# 3.24.4 sorts before the new version (i.e. the new version is the greater one). |
| 46 | +cfbs --non-interactive update masterfiles |
| 47 | +new_ver="$(mf version)" |
| 48 | +[ "$new_ver" != "3.24.4" ] |
| 49 | +[ "$(printf '%s\n%s\n' "3.24.4" "$new_ver" | sort -V | tail -1)" = "$new_ver" ] |
| 50 | + |
| 51 | +cfbs build |
0 commit comments