bunkerweb/tests/main.py
2022-07-19 16:06:50 +02:00

94 lines
No EOL
3.1 KiB
Python
Executable file
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
from sys import path, argv, exit
from glob import glob
from os import getcwd, _exit
from os.path import isfile
from traceback import format_exc
from json import loads
path.append(getcwd() + "/utils")
path.append(getcwd() + "/tests")
from Test import Test
from DockerTest import DockerTest
from AutoconfTest import AutoconfTest
from SwarmTest import SwarmTest
from KubernetesTest import KubernetesTest
from LinuxTest import LinuxTest
from logger import log
if len(argv) <= 1 :
log("TESTS", "", "Missing type argument")
exit(1)
test_type = argv[1]
if not test_type in ["linux", "docker", "autoconf", "swarm", "kubernetes", "ansible"] :
log("TESTS", "", "Wrong type argument " + test_type)
exit(1)
log("TESTS", "", "Starting tests for " + test_type + " ...")
ret = False
end_fun = None
if test_type == "docker" :
ret = DockerTest.init()
end_fun = DockerTest.end
elif test_type == "autoconf" :
ret = AutoconfTest.init()
end_fun = AutoconfTest.end
elif test_type == "swarm" :
ret = SwarmTest.init()
end_fun = SwarmTest.end
elif test_type == "kubernetes" :
ret = KubernetesTest.init()
end_fun = KubernetesTest.end
elif test_type == "linux" :
distro = argv[2]
ret = LinuxTest.init(distro)
end_fun = LinuxTest.end
if not ret :
log("TESTS", "", "Test.init() failed")
exit(1)
for example in glob("./examples/*") :
if isfile(example + "/tests.json") :
try :
with open(example + "/tests.json") as f :
tests = loads(f.read())
if not test_type in tests["kinds"] :
log("TESTS", "", "Skipping tests for " + tests["name"] + " (not in kinds)")
continue
test_obj = None
if test_type == "docker" :
test_obj = DockerTest(tests["name"], tests["timeout"], tests["tests"])
elif test_type == "autoconf" :
test_obj = AutoconfTest(tests["name"], tests["timeout"], tests["tests"])
elif test_type == "swarm" :
test_obj = SwarmTest(tests["name"], tests["timeout"], tests["tests"])
elif test_type == "kubernetes" :
test_obj = KubernetesTest(tests["name"], tests["timeout"], tests["tests"])
elif test_type == "linux" :
test_obj = LinuxTest(tests["name"], tests["timeout"], tests["tests"], distro)
if not test_obj.run_tests() :
log("TESTS", "", "Tests failed for " + tests["name"])
if test_type == "linux" :
ret = end_fun(distro)
else :
ret = end_fun()
_exit(1)
except :
log("TESTS", "", "Exception while executing test for example " + example + " : " + format_exc())
if test_type == "linux" :
ret = end_fun(distro)
else :
ret = end_fun()
exit(1)
if test_type == "linux" :
ret = end_fun(distro)
else :
ret = end_fun()
if not ret :
log("TESTS", "", "Test.end() failed")
exit(1)
log("TESTS", "", "All tests finished for " + test_type + " !")