tests - replace example domains with test domains

This commit is contained in:
florian 2022-07-13 21:05:14 +02:00
parent dfc5f2e79e
commit e4f6017d64
3 changed files with 16 additions and 15 deletions

View File

@ -10,12 +10,12 @@
"tests": [
{
"type": "string",
"url": "https://TEST_DOMAIN1_1",
"url": "https://app1.example.com",
"string": "authelia"
},
{
"type": "string",
"url": "https://TEST_DOMAIN1_2",
"url": "https://app2.example.com",
"string": "authelia"
}
]

View File

@ -9,7 +9,7 @@ class DockerTest(Test) :
def __init__(self, name, timeout, tests) :
super().__init__(name, "docker", timeout, tests)
self.__domains = {
self._domains = {
r"www\.example\.com": getenv("TEST_DOMAIN1"),
r"auth\.example\.com": getenv("TEST_DOMAIN1"),
r"app1\.example\.com": getenv("TEST_DOMAIN1_1"),
@ -38,7 +38,7 @@ class DockerTest(Test) :
self._replace_in_file(compose, r"bunkerity/bunkerweb:.*$", "10.20.1.1:5000/bw-tests:latest")
self._replace_in_file(compose, r"\./bw\-data:/", "/tmp/bw-data:/")
self._replace_in_file(compose, r"\- bw_data:/", "/tmp/bw-data:/")
for ex_domain, test_domain in self.__domains.items() :
for ex_domain, test_domain in self._domains.items() :
self._replace_in_files(test, ex_domain, test_domain)
self._rename(test, ex_domain, test_domain)
setup = test + "/setup-docker.sh"
@ -48,14 +48,12 @@ class DockerTest(Test) :
for cp_dir in listdir(example_data) :
if isdir(join(example_data, cp_dir)) :
copytree(join(example_data, cp_dir), join("/tmp/bw-data", cp_dir))
cmd = "docker-compose pull"
proc = run(cmd.split(" "), shell=True, cwd=test)
proc = run("docker-compose pull", shell=True, cwd=test)
if proc.returncode != 0 :
raise("docker-compose pull failed")
cmd = "docker-compose up -d"
proc = run(cmd.split(" "), shell=True, cwd=test)
raise(Exception("docker-compose pull failed"))
proc = run("docker-compose up -d", shell=True, cwd=test)
if proc.returncode != 0 :
raise("docker-compose up failed")
raise(Exception("docker-compose up failed"))
except :
self._log("exception while running DockerTest._setup_test()\n" + format_exc(), error=True)
return False
@ -65,10 +63,9 @@ class DockerTest(Test) :
def _cleanup_test(self) :
try :
test = "/tmp/tests/" + self._name
cmd = "docker-compose down -v"
proc = run(cmd.split(" "), shell=True, cwd=test)
proc = run("docker-compose down -v", shell=True, cwd=test)
if proc.returncode != 0 :
raise("docker-compose down failed")
raise(Exception("docker-compose down failed"))
super()._cleanup_test()
except :
self._log("exception while running DockerTest._setup_test()\n" + format_exc(), error=True)

View File

@ -6,7 +6,7 @@ from traceback import format_exc
from shutil import rmtree, copytree
from os.path import isdir, join
from os import mkdir, makedirs, walk, chmod
from re import sub, MULTILINE
from re import sub, match, MULTILINE
from datetime import datetime
class Test(ABC) :
@ -95,11 +95,15 @@ class Test(ABC) :
def __run_test(self, test) :
try :
if test["type"] == "string" :
ex_url = test["url"]
for ex_domain, test_domain in self._domains.items() :
if match(ex_domain, ex_url) :
ex_url = sub(ex_domain, test_domain, ex_url)
r = get(test["url"], timeout=5)
return test["string"] in r.text
except :
self._log("exception while running test of type " + test["type"] + " on URL " + test["url"] + "\n" + format_exc(), error=True)
raise("unknow test type " + test["type"])
raise(Exception("unknow test type " + test["type"]))
def _replace_in_file(self, path, old, new) :
with open(path, "r") as f :