mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-12-03 07:59:42 +00:00
Ensure deterministic ordering of web health expectations and add unit tests
This update sorts all expectation keys alphabetically to guarantee idempotent Ansible deployments and stable systemd unit generation. Added two unit tests to validate proper key ordering for canonical domains, aliases, redirects, and WWW mappings. Reference: https://chatgpt.com/share/692ae99b-dd88-800f-8fad-2ff62666e295
This commit is contained in:
@@ -397,5 +397,30 @@ class TestWebHealthExpectationsFilter(unittest.TestCase):
|
||||
self.assertEqual(out["v1.l11.example.org"], [301, 307]) # per-key list
|
||||
self.assertEqual(out["v2.l11.example.org"], [301, 307])
|
||||
|
||||
def test_expectations_keys_are_sorted_alphabetically (self ):
|
||||
apps ={"app-sort":{}}
|
||||
self ._configure_returns ({
|
||||
("app-sort","server.domains.canonical"):["b.example.org","a.example.org","c.example.org"],
|
||||
("app-sort","server.domains.aliases"):["alias.example.org"],
|
||||
("app-sort","server.status_codes"):{"default":200 },
|
||||
})
|
||||
out =self .mod .web_health_expectations (apps ,group_names =["app-sort"])
|
||||
|
||||
keys =list (out .keys ())
|
||||
self .assertEqual (keys ,sorted (keys ))
|
||||
|
||||
|
||||
def test_expectations_keys_sorted_with_redirects_and_www (self ):
|
||||
apps ={}
|
||||
out =self .mod .web_health_expectations (
|
||||
apps ,
|
||||
group_names =["dummy-app"],
|
||||
www_enabled =True ,
|
||||
redirect_maps =[{"source":"redir-b.example.org"},{"source":"redir-a.example.org"}],
|
||||
)
|
||||
|
||||
keys =list (out .keys ())
|
||||
self .assertEqual (keys ,sorted (keys ))
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user