Tests: migrated to the pytest.

This commit is contained in:
Andrei Zeliankou
2020-09-16 21:31:15 +01:00
parent 77ecb6ab49
commit d5e9159340
55 changed files with 4717 additions and 6262 deletions

View File

@@ -2,17 +2,18 @@ import os
import subprocess
from unit.applications.proto import TestApplicationProto
from conftest import option
class TestApplicationGo(TestApplicationProto):
@classmethod
def setUpClass(cls, complete_check=True):
unit = super().setUpClass(complete_check=False)
def setup_class(cls, complete_check=True):
unit = super().setup_class(complete_check=False)
# check go module
go_app = TestApplicationGo()
go_app.testdir = unit.testdir
go_app.temp_dir = unit.temp_dir
proc = go_app.prepare_env('empty', 'app')
if proc and proc.returncode == 0:
cls.available['modules']['go'] = []
@@ -20,8 +21,8 @@ class TestApplicationGo(TestApplicationProto):
return unit if not complete_check else unit.complete()
def prepare_env(self, script, name, static=False):
if not os.path.exists(self.testdir + '/go'):
os.mkdir(self.testdir + '/go')
if not os.path.exists(self.temp_dir + '/go'):
os.mkdir(self.temp_dir + '/go')
env = os.environ.copy()
env['GOPATH'] = self.pardir + '/build/go'
@@ -35,16 +36,16 @@ class TestApplicationGo(TestApplicationProto):
'-ldflags',
'-extldflags "-static"',
'-o',
self.testdir + '/go/' + name,
self.current_dir + '/go/' + script + '/' + name + '.go',
self.temp_dir + '/go/' + name,
option.test_dir + '/go/' + script + '/' + name + '.go',
]
else:
args = [
'go',
'build',
'-o',
self.testdir + '/go/' + name,
self.current_dir + '/go/' + script + '/' + name + '.go',
self.temp_dir + '/go/' + name,
option.test_dir + '/go/' + script + '/' + name + '.go',
]
try:
@@ -59,8 +60,8 @@ class TestApplicationGo(TestApplicationProto):
def load(self, script, name='app', **kwargs):
static_build = False
wdir = self.current_dir + "/go/" + script
executable = self.testdir + "/go/" + name
wdir = option.test_dir + "/go/" + script
executable = self.temp_dir + "/go/" + name
if 'isolation' in kwargs and 'rootfs' in kwargs['isolation']:
wdir = "/go/"

View File

@@ -1,17 +1,19 @@
import glob
import os
import pytest
import shutil
import subprocess
from unit.applications.proto import TestApplicationProto
from conftest import option
class TestApplicationJava(TestApplicationProto):
def load(self, script, name='app', **kwargs):
app_path = self.testdir + '/java'
app_path = self.temp_dir + '/java'
web_inf_path = app_path + '/WEB-INF/'
classes_path = web_inf_path + 'classes/'
script_path = self.current_dir + '/java/' + script + '/'
script_path = option.test_dir + '/java/' + script + '/'
if not os.path.isdir(app_path):
os.makedirs(app_path)
@@ -54,7 +56,7 @@ class TestApplicationJava(TestApplicationProto):
)
if not ws_jars:
self.fail('websocket api jar not found.')
pytest.fail('websocket api jar not found.')
javac = [
'javac',
@@ -69,7 +71,7 @@ class TestApplicationJava(TestApplicationProto):
process.communicate()
except:
self.fail('Cann\'t run javac process.')
pytest.fail('Cann\'t run javac process.')
self._load_conf(
{

View File

@@ -3,12 +3,13 @@ import shutil
from urllib.parse import quote
from unit.applications.proto import TestApplicationProto
from conftest import option, public_dir
class TestApplicationNode(TestApplicationProto):
@classmethod
def setUpClass(cls, complete_check=True):
unit = super().setUpClass(complete_check=False)
def setup_class(cls, complete_check=True):
unit = super().setup_class(complete_check=False)
# check node module
@@ -21,17 +22,17 @@ class TestApplicationNode(TestApplicationProto):
# copy application
shutil.copytree(
self.current_dir + '/node/' + script, self.testdir + '/node'
option.test_dir + '/node/' + script, self.temp_dir + '/node'
)
# copy modules
shutil.copytree(
self.pardir + '/node/node_modules',
self.testdir + '/node/node_modules',
self.temp_dir + '/node/node_modules',
)
self.public_dir(self.testdir + '/node')
public_dir(self.temp_dir + '/node')
self._load_conf(
{
@@ -42,7 +43,7 @@ class TestApplicationNode(TestApplicationProto):
script: {
"type": "external",
"processes": {"spare": 0},
"working_directory": self.testdir + '/node',
"working_directory": self.temp_dir + '/node',
"executable": name,
}
},

View File

@@ -1,11 +1,12 @@
from unit.applications.proto import TestApplicationProto
from conftest import option
class TestApplicationPerl(TestApplicationProto):
application_type = "perl"
def load(self, script, name='psgi.pl', **kwargs):
script_path = self.current_dir + '/perl/' + script
script_path = option.test_dir + '/perl/' + script
self._load_conf(
{

View File

@@ -1,11 +1,12 @@
from unit.applications.proto import TestApplicationProto
from conftest import option
class TestApplicationPHP(TestApplicationProto):
application_type = "php"
def load(self, script, index='index.php', **kwargs):
script_path = self.current_dir + '/php/' + script
script_path = option.test_dir + '/php/' + script
self._load_conf(
{

View File

@@ -1,20 +1,23 @@
import os
import shutil
import pytest
from unit.applications.proto import TestApplicationProto
from conftest import option
class TestApplicationPython(TestApplicationProto):
application_type = "python"
def load(self, script, name=None, **kwargs):
print()
if name is None:
name = script
if script[0] == '/':
script_path = script
else:
script_path = self.current_dir + '/python/' + script
script_path = option.test_dir + '/python/' + script
if kwargs.get('isolation') and kwargs['isolation'].get('rootfs'):
rootfs = kwargs['isolation']['rootfs']
@@ -27,12 +30,17 @@ class TestApplicationPython(TestApplicationProto):
script_path = '/app/python/' + name
appication_type = self.get_appication_type()
if appication_type is None:
appication_type = self.application_type
self._load_conf(
{
"listeners": {"*:7080": {"pass": "applications/" + name}},
"applications": {
name: {
"type": self.application_type,
"type": appication_type,
"processes": {"spare": 0},
"path": script_path,
"working_directory": script_path,

View File

@@ -1,11 +1,12 @@
from unit.applications.proto import TestApplicationProto
from conftest import option
class TestApplicationRuby(TestApplicationProto):
application_type = "ruby"
def load(self, script, name='config.ru', **kwargs):
script_path = self.current_dir + '/ruby/' + script
script_path = option.test_dir + '/ruby/' + script
self._load_conf(
{