fix(apps): lève les remarques SonarCloud sur les tests de rétention, le script du coffre et la fumée CI
This commit is contained in:
@@ -114,7 +114,7 @@ jobs:
|
|||||||
- name: Fumée S3 sur Garage, SSE-C compris
|
- name: Fumée S3 sur Garage, SSE-C compris
|
||||||
run: |
|
run: |
|
||||||
set -a; . ./.env; set +a
|
set -a; . ./.env; set +a
|
||||||
uvx --with boto3==1.43.101 pytest==9.1.1 tests/garage -q
|
uvx --no-build --with boto3==1.43.101 pytest==9.1.1 tests/garage -q
|
||||||
|
|
||||||
- name: Journaux de Garage en cas d'échec
|
- name: Journaux de Garage en cas d'échec
|
||||||
if: failure()
|
if: failure()
|
||||||
|
|||||||
@@ -144,7 +144,10 @@ def test_serialize_csv_gzip_writes_jsonb_and_arrays_as_sorted_json() -> None:
|
|||||||
def test_serialize_csv_gzip_is_byte_for_byte_reproducible() -> None:
|
def test_serialize_csv_gzip_is_byte_for_byte_reproducible() -> None:
|
||||||
lignes = [make_row(), make_row(reading_id=2)]
|
lignes = [make_row(), make_row(reading_id=2)]
|
||||||
|
|
||||||
assert serialize_csv_gzip(lignes) == serialize_csv_gzip(lignes)
|
premier = serialize_csv_gzip(lignes)
|
||||||
|
second = serialize_csv_gzip(lignes)
|
||||||
|
|
||||||
|
assert premier == second
|
||||||
|
|
||||||
|
|
||||||
def test_serialize_csv_gzip_refuses_an_empty_export() -> None:
|
def test_serialize_csv_gzip_refuses_an_empty_export() -> None:
|
||||||
@@ -254,10 +257,10 @@ def test_decode_sse_key_decodes_the_base64_key() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_decode_sse_key_refuses_a_key_of_the_wrong_length() -> None:
|
def test_decode_sse_key_refuses_a_key_of_the_wrong_length() -> None:
|
||||||
courte = base64.b64encode(b"trop-courte").decode("ascii")
|
courte = SecretStr(base64.b64encode(b"trop-courte").decode("ascii"))
|
||||||
|
|
||||||
with pytest.raises(ValueError, match="exactement 32 octets"):
|
with pytest.raises(ValueError, match="exactement 32 octets"):
|
||||||
decode_sse_key(SecretStr(courte))
|
decode_sse_key(courte)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@@ -265,15 +268,18 @@ def test_decode_sse_key_refuses_a_key_of_the_wrong_length() -> None:
|
|||||||
["s3_endpoint_url", "s3_access_key", "s3_secret_key", "s3_bucket"],
|
["s3_endpoint_url", "s3_access_key", "s3_secret_key", "s3_bucket"],
|
||||||
)
|
)
|
||||||
def test_build_archive_store_refuses_a_missing_setting(manquant: str) -> None:
|
def test_build_archive_store_refuses_a_missing_setting(manquant: str) -> None:
|
||||||
|
reglages = settings_s3(**{manquant: None})
|
||||||
|
|
||||||
with pytest.raises(ValueError, match="APP_S3_ENDPOINT_URL"):
|
with pytest.raises(ValueError, match="APP_S3_ENDPOINT_URL"):
|
||||||
build_archive_store(settings_s3(**{manquant: None}))
|
build_archive_store(reglages)
|
||||||
|
|
||||||
|
|
||||||
def test_build_archive_store_refuses_a_sse_key_of_the_wrong_length() -> None:
|
def test_build_archive_store_refuses_a_sse_key_of_the_wrong_length() -> None:
|
||||||
courte = base64.b64encode(b"trop-courte").decode("ascii")
|
courte = base64.b64encode(b"trop-courte").decode("ascii")
|
||||||
|
reglages = settings_s3(s3_sse_key=SecretStr(courte))
|
||||||
|
|
||||||
with pytest.raises(ValueError, match="exactement 32 octets"):
|
with pytest.raises(ValueError, match="exactement 32 octets"):
|
||||||
build_archive_store(settings_s3(s3_sse_key=SecretStr(courte)))
|
build_archive_store(reglages)
|
||||||
|
|
||||||
|
|
||||||
def test_build_archive_store_configures_the_client_from_the_settings(
|
def test_build_archive_store_configures_the_client_from_the_settings(
|
||||||
@@ -549,11 +555,10 @@ async def test_archive_reading_chunks_in_dry_run_neither_writes_nor_drops(
|
|||||||
|
|
||||||
async def test_archive_reading_chunks_keeps_the_chunk_when_the_read_back_differs() -> None:
|
async def test_archive_reading_chunks_keeps_the_chunk_when_the_read_back_differs() -> None:
|
||||||
engine, store, journal = make_archive(corrompt=True)
|
engine, store, journal = make_archive(corrompt=True)
|
||||||
|
borne = datetime(2023, 10, 1, tzinfo=UTC)
|
||||||
|
|
||||||
with pytest.raises(RuntimeError, match="sha256 sha-corrompu au lieu de"):
|
with pytest.raises(RuntimeError, match="sha256 sha-corrompu au lieu de"):
|
||||||
await archive_reading_chunks(
|
await archive_reading_chunks(engine, store, older_than=borne, dry_run=False)
|
||||||
engine, store, older_than=datetime(2023, 10, 1, tzinfo=UTC), dry_run=False
|
|
||||||
)
|
|
||||||
|
|
||||||
assert "put" in journal
|
assert "put" in journal
|
||||||
assert "drop" not in journal
|
assert "drop" not in journal
|
||||||
@@ -622,15 +627,18 @@ def test_build_parser_reads_the_bound_and_the_dry_run() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_build_parser_refuses_a_non_integer_bound() -> None:
|
def test_build_parser_refuses_a_non_integer_bound() -> None:
|
||||||
|
parser = build_parser()
|
||||||
|
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
build_parser().parse_args(["--older-than-days", "un-an"])
|
parser.parse_args(["--older-than-days", "un-an"])
|
||||||
|
|
||||||
|
|
||||||
def test_build_parser_answers_help_without_settings(monkeypatch: pytest.MonkeyPatch) -> None:
|
def test_build_parser_answers_help_without_settings(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||||
monkeypatch.delenv("APP_SECRET_KEY", raising=False)
|
monkeypatch.delenv("APP_SECRET_KEY", raising=False)
|
||||||
|
parser = build_parser()
|
||||||
|
|
||||||
with pytest.raises(SystemExit) as sortie:
|
with pytest.raises(SystemExit) as sortie:
|
||||||
build_parser().parse_args(["--help"])
|
parser.parse_args(["--help"])
|
||||||
|
|
||||||
assert sortie.value.code == 0
|
assert sortie.value.code == 0
|
||||||
|
|
||||||
|
|||||||
+10
-3
@@ -98,7 +98,8 @@ poser_image() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fstab_contient() {
|
fstab_contient() {
|
||||||
awk -v cible="$1" '$1 !~ /^#/ && $2 == cible { trouve = 1 } END { exit !trouve }' /etc/fstab
|
local cible="$1"
|
||||||
|
awk -v cible="$cible" '$1 !~ /^#/ && $2 == cible { trouve = 1 } END { exit !trouve }' /etc/fstab
|
||||||
}
|
}
|
||||||
|
|
||||||
poser_persistance() {
|
poser_persistance() {
|
||||||
@@ -132,8 +133,14 @@ CONF
|
|||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
}
|
}
|
||||||
|
|
||||||
empreinte() { find "$1" -type f -printf '%s\n' | awk '{ n++; s += $1 } END { printf "%d fichiers, %d octets", n, s }'; }
|
empreinte() {
|
||||||
libre() { df -B1 --output=avail "$1" | tail -1 | tr -d ' '; }
|
local dossier="$1"
|
||||||
|
find "$dossier" -type f -printf '%s\n' | awk '{ n++; s += $1 } END { printf "%d fichiers, %d octets", n, s }'
|
||||||
|
}
|
||||||
|
libre() {
|
||||||
|
local dossier="$1"
|
||||||
|
df -B1 --output=avail "$dossier" | tail -1 | tr -d ' '
|
||||||
|
}
|
||||||
|
|
||||||
expliquer_migration() {
|
expliquer_migration() {
|
||||||
cat <<FIN
|
cat <<FIN
|
||||||
|
|||||||
Reference in New Issue
Block a user