Skip to content

Commit

Permalink
Avoid test failure by not checking exact size of backup (#5594)
Browse files Browse the repository at this point in the history
* Avoid test failure by not checking exact size of backup

This is a workaround for the fact that the backup size is not exactly
the same every time. This is due to the fact that the inner gziped tar
file can vary in size due to difference in json file (key order) and
potentially also different field values (UUID, backup slug).

It seems that sorting the keys makes the actual difference today, but
this has runtime overhead and might not catch all cases.

Simply check if size property is there and a number bigger than 0
instead.

* Fix pytest
  • Loading branch information
agners authored Jan 31, 2025
1 parent 05b6486 commit 28a87db
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions tests/api/test_backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,25 +1035,22 @@ async def test_protected_backup(
assert body["data"]["backups"][0]["location"] is None
assert body["data"]["backups"][0]["locations"] == [None]
assert body["data"]["backups"][0]["protected"] is True
assert body["data"]["backups"][0]["location_attributes"] == {
".local": {
"protected": True,
"size_bytes": 10240,
}
}
assert (
body["data"]["backups"][0]["location_attributes"][".local"]["protected"] is True
)
# NOTE: It is not safe to check size exactly here, as order of keys in
# `homeassistant.json` and potentially other random data (e.g. isntance UUID,
# backup slug) does change the size of the backup (due to gzip).
assert body["data"]["backups"][0]["location_attributes"][".local"]["size_bytes"] > 0

resp = await api_client.get(f"/backups/{slug}/info")
assert resp.status == 200
body = await resp.json()
assert body["data"]["location"] is None
assert body["data"]["locations"] == [None]
assert body["data"]["protected"] is True
assert body["data"]["location_attributes"] == {
".local": {
"protected": True,
"size_bytes": 10240,
}
}
assert body["data"]["location_attributes"][".local"]["protected"] is True
assert body["data"]["location_attributes"][".local"]["size_bytes"] > 0


@pytest.mark.usefixtures(
Expand Down

0 comments on commit 28a87db

Please sign in to comment.