tests - DockerTest on the road
This commit is contained in:
parent
85217b57c3
commit
b64af85262
|
@ -364,9 +364,15 @@ jobs:
|
|||
ignore-unfixed: false
|
||||
severity: UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL
|
||||
|
||||
# Prepare tests
|
||||
- name: Install tests dependencies
|
||||
run: pip3 install -r ./tests/requirements.txt
|
||||
|
||||
# Run tests
|
||||
- name: Run Docker tests
|
||||
run: ./tests/docker.sh ${{ env.BUILD_MODE }}
|
||||
run: ./tests/main.py "docker"
|
||||
- name: Temp stop tests
|
||||
run: exit 1
|
||||
- name: Run autoconf tests
|
||||
run: ./tests/autoconf.sh ${{ env.BUILD_MODE }}
|
||||
- name: Run Swarm tests
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from Test import Test
|
||||
from os.path import isdir, join, isfile
|
||||
from os import chown, walk, getenv
|
||||
from os import chown, walk, getenv, listdir
|
||||
from shutil import copytree
|
||||
from traceback import format_exc
|
||||
from subprocess import run
|
||||
|
||||
|
@ -33,6 +34,7 @@ class DockerTest(Test) :
|
|||
super()._setup_test()
|
||||
test = "/tmp/tests/" + self._name
|
||||
compose = "/tmp/tests/" + self._name + "/docker-compose.yml"
|
||||
example_data = "./examples/" + self._name + "/bw-data"
|
||||
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:/")
|
||||
|
@ -42,7 +44,18 @@ class DockerTest(Test) :
|
|||
setup = test + "/setup-docker.sh"
|
||||
if isfile(setup) :
|
||||
run("./docker-setup.sh", cwd=test, shell=True, check=True)
|
||||
|
||||
if isdir(example_data) :
|
||||
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)
|
||||
if proc.returncode != 0 :
|
||||
raise("docker-compose pull failed")
|
||||
cmd = "docker-compose up -d"
|
||||
proc = run(cmd.split(" "), shell=True, cwd=test)
|
||||
if proc.returncode != 0 :
|
||||
raise("docker-compose up failed")
|
||||
except :
|
||||
self._log("exception while running DockerTest._setup_test()\n" + format_exc(), error=True)
|
||||
return False
|
||||
|
@ -50,4 +63,15 @@ class DockerTest(Test) :
|
|||
|
||||
|
||||
def _cleanup_test(self) :
|
||||
pass
|
||||
try :
|
||||
test = "/tmp/tests/" + self._name
|
||||
cmd = "docker-compose down -v"
|
||||
proc = run(cmd.split(" "), shell=True, cwd=test)
|
||||
if proc.returncode != 0 :
|
||||
raise("docker-compose down failed")
|
||||
super()._cleanup_test()
|
||||
except :
|
||||
self._log("exception while running DockerTest._setup_test()\n" + format_exc(), error=True)
|
||||
return False
|
||||
return True
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from sys import path, argv, exit
|
||||
from glob import glob
|
||||
from os import getcwd, isfile
|
||||
path.append(getcwd() + "/utils")
|
||||
path.append(getcwd() + "/tests")
|
||||
|
||||
from DockerTest import DockerTest
|
||||
from logger import log
|
||||
|
||||
if len(argv) != 2 :
|
||||
log("TESTS", "❌", "Missing type argument")
|
||||
exit(1)
|
||||
|
||||
test_type = argv[1]
|
||||
if not test_type in ["linux", "docker", "swarm", "kubernetes", "ansible"] :
|
||||
log("TESTS", "❌", "Wrong type argument " + test_type)
|
||||
exit(1)
|
||||
|
||||
log("TESTS", "ℹ️", "Starting tests for " + test_type + " ...")
|
||||
if not Test.init() :
|
||||
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
|
||||
for test in tests["tests"] :
|
||||
test_obj = None
|
||||
if test_obj == "docker" :
|
||||
test_obj = DockerTest(tests["name"], tests["timeout"], tests["tests"])
|
||||
if not test_obj.run_tests() :
|
||||
log("TESTS", "❌", "Tests failed for " + tests["name"])
|
||||
exit(1)
|
||||
except :
|
||||
log("TESTS", "❌", "Exception while executing test for example " + example + " : " + traceback.format_exc())
|
||||
|
||||
log("TESTS", "ℹ️", "All tests finished for " + test_type + " !")
|
|
@ -0,0 +1 @@
|
|||
requests
|
Loading…
Reference in New Issue