3
3
4
4
"""Integration tests for WordPress charm ingress integration."""
5
5
6
- import socket
7
- import unittest .mock
8
-
9
6
import kubernetes
10
7
import pytest
11
8
import requests
@@ -21,37 +18,6 @@ async def test_ingress(wordpress: WordpressApp):
21
18
and WordPress charm.
22
19
assert: A Kubernetes ingress should be created and the ingress should accept HTTPS connections.
23
20
"""
24
-
25
- def gen_patch_getaddrinfo (host : str , resolve_to : str ):
26
- """Generate patched getaddrinfo function.
27
-
28
- This function is used to generate a patched getaddrinfo function that will resolve to the
29
- resolve_to address without having to actually register a host.
30
-
31
- Args:
32
- host: intended hostname of a given application.
33
- resolve_to: destination address for host to resolve to.
34
-
35
- Returns:
36
- A patching function for getaddrinfo.
37
- """
38
- original_getaddrinfo = socket .getaddrinfo
39
-
40
- def patched_getaddrinfo (* args ):
41
- """Patch getaddrinfo to point to desired ip address.
42
-
43
- Args:
44
- args: original arguments to getaddrinfo when creating network connection.
45
-
46
- Returns:
47
- Patched getaddrinfo function.
48
- """
49
- if args [0 ] == host :
50
- return original_getaddrinfo (resolve_to , * args [1 :])
51
- return original_getaddrinfo (* args )
52
-
53
- return patched_getaddrinfo
54
-
55
21
response = requests .get ("http://127.0.0.1" , headers = {"Host" : wordpress .name }, timeout = 5 )
56
22
assert (
57
23
response .status_code == 200 and "wordpress" in response .text .lower ()
@@ -60,13 +26,12 @@ def patched_getaddrinfo(*args):
60
26
new_hostname = "wordpress.test"
61
27
await wordpress .set_config ({"blog_hostname" : new_hostname })
62
28
await wordpress .model .wait_for_idle (status = "active" )
63
- with unittest .mock .patch .multiple (
64
- socket , getaddrinfo = gen_patch_getaddrinfo (new_hostname , "127.0.0.1" )
65
- ):
66
- response = requests .get (f"https://{ new_hostname } " , timeout = 5 , verify = False ) # nosec
67
- assert (
68
- response .status_code == 200 and "wordpress" in response .text .lower ()
69
- ), "Ingress should update the server name indication based routing after blog_hostname updated"
29
+ response = requests .get (
30
+ "https://127.0.0.1" , headers = {"Host" : new_hostname }, timeout = 5 , verify = False
31
+ ) # nosec
32
+ assert (
33
+ response .status_code == 200 and "wordpress" in response .text .lower ()
34
+ ), "Ingress should update the server name indication based routing after blog_hostname updated"
70
35
71
36
72
37
@pytest .mark .usefixtures ("prepare_mysql" , "prepare_nginx_ingress" , "prepare_swift" )
0 commit comments