Tests: unit module refactoring.
This commit is contained in:
0
test/unit/applications/lang/__init__.py
Normal file
0
test/unit/applications/lang/__init__.py
Normal file
40
test/unit/applications/lang/go.py
Normal file
40
test/unit/applications/lang/go.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import os
|
||||
from subprocess import Popen
|
||||
from unit.applications.proto import TestApplicationProto
|
||||
|
||||
|
||||
class TestApplicationGo(TestApplicationProto):
|
||||
def load(self, script, name='app'):
|
||||
|
||||
if not os.path.isdir(self.testdir + '/go'):
|
||||
os.mkdir(self.testdir + '/go')
|
||||
|
||||
go_app_path = self.current_dir + '/go/'
|
||||
|
||||
env = os.environ.copy()
|
||||
env['GOPATH'] = self.pardir + '/go'
|
||||
process = Popen(
|
||||
[
|
||||
'go',
|
||||
'build',
|
||||
'-o',
|
||||
self.testdir + '/go/' + name,
|
||||
go_app_path + script + '/' + name + '.go',
|
||||
],
|
||||
env=env,
|
||||
)
|
||||
process.communicate()
|
||||
|
||||
self.conf(
|
||||
{
|
||||
"listeners": {"*:7080": {"application": script}},
|
||||
"applications": {
|
||||
script: {
|
||||
"type": "external",
|
||||
"processes": {"spare": 0},
|
||||
"working_directory": go_app_path + script,
|
||||
"executable": self.testdir + '/go/' + name,
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
74
test/unit/applications/lang/java.py
Normal file
74
test/unit/applications/lang/java.py
Normal file
@@ -0,0 +1,74 @@
|
||||
import os
|
||||
import shutil
|
||||
from subprocess import Popen
|
||||
from unit.applications.proto import TestApplicationProto
|
||||
|
||||
|
||||
class TestApplicationJava(TestApplicationProto):
|
||||
def load(self, script, name='app'):
|
||||
|
||||
app_path = self.testdir + '/java'
|
||||
web_inf_path = app_path + '/WEB-INF/'
|
||||
classes_path = web_inf_path + 'classes/'
|
||||
|
||||
script_path = self.current_dir + '/java/' + script + '/'
|
||||
|
||||
if not os.path.isdir(app_path):
|
||||
os.makedirs(app_path)
|
||||
|
||||
src = []
|
||||
|
||||
for f in os.listdir(script_path):
|
||||
if f.endswith('.java'):
|
||||
src.append(script_path + f)
|
||||
continue
|
||||
|
||||
if f.startswith('.') or f == 'Makefile':
|
||||
continue
|
||||
|
||||
if os.path.isdir(script_path + f):
|
||||
if f == 'WEB-INF':
|
||||
continue
|
||||
|
||||
shutil.copytree(script_path + f, app_path + '/' + f)
|
||||
continue
|
||||
|
||||
if f == 'web.xml':
|
||||
if not os.path.isdir(web_inf_path):
|
||||
os.makedirs(web_inf_path)
|
||||
|
||||
shutil.copy2(script_path + f, web_inf_path)
|
||||
else:
|
||||
shutil.copy2(script_path + f, app_path)
|
||||
|
||||
if src:
|
||||
if not os.path.isdir(classes_path):
|
||||
os.makedirs(classes_path)
|
||||
|
||||
tomcat_jar = self.pardir + '/build/tomcat-servlet-api-9.0.13.jar'
|
||||
|
||||
javac = [
|
||||
'javac',
|
||||
'-encoding', 'utf-8',
|
||||
'-d', classes_path,
|
||||
'-classpath', tomcat_jar,
|
||||
]
|
||||
javac.extend(src)
|
||||
|
||||
process = Popen(javac)
|
||||
process.communicate()
|
||||
|
||||
self.conf(
|
||||
{
|
||||
"listeners": {"*:7080": {"application": script}},
|
||||
"applications": {
|
||||
script: {
|
||||
"unit_jars": self.pardir + '/build',
|
||||
"type": "java",
|
||||
"processes": {"spare": 0},
|
||||
"working_directory": script_path,
|
||||
"webapp": app_path,
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
34
test/unit/applications/lang/node.py
Normal file
34
test/unit/applications/lang/node.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import os
|
||||
import shutil
|
||||
from unit.applications.proto import TestApplicationProto
|
||||
|
||||
|
||||
class TestApplicationNode(TestApplicationProto):
|
||||
def load(self, script, name='app.js'):
|
||||
|
||||
# copy application
|
||||
|
||||
shutil.copytree(
|
||||
self.current_dir + '/node/' + script, self.testdir + '/node'
|
||||
)
|
||||
|
||||
# link modules
|
||||
|
||||
os.symlink(
|
||||
self.pardir + '/node/node_modules',
|
||||
self.testdir + '/node/node_modules',
|
||||
)
|
||||
|
||||
self.conf(
|
||||
{
|
||||
"listeners": {"*:7080": {"application": script}},
|
||||
"applications": {
|
||||
script: {
|
||||
"type": "external",
|
||||
"processes": {"spare": 0},
|
||||
"working_directory": self.testdir + '/node',
|
||||
"executable": name,
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
20
test/unit/applications/lang/perl.py
Normal file
20
test/unit/applications/lang/perl.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from unit.applications.proto import TestApplicationProto
|
||||
|
||||
|
||||
class TestApplicationPerl(TestApplicationProto):
|
||||
def load(self, script, name='psgi.pl'):
|
||||
script_path = self.current_dir + '/perl/' + script
|
||||
|
||||
self.conf(
|
||||
{
|
||||
"listeners": {"*:7080": {"application": script}},
|
||||
"applications": {
|
||||
script: {
|
||||
"type": "perl",
|
||||
"processes": {"spare": 0},
|
||||
"working_directory": script_path,
|
||||
"script": script_path + '/' + name,
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
21
test/unit/applications/lang/php.py
Normal file
21
test/unit/applications/lang/php.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from unit.applications.proto import TestApplicationProto
|
||||
|
||||
|
||||
class TestApplicationPHP(TestApplicationProto):
|
||||
def load(self, script, name='index.php'):
|
||||
script_path = self.current_dir + '/php/' + script
|
||||
|
||||
self.conf(
|
||||
{
|
||||
"listeners": {"*:7080": {"application": script}},
|
||||
"applications": {
|
||||
script: {
|
||||
"type": "php",
|
||||
"processes": {"spare": 0},
|
||||
"root": script_path,
|
||||
"working_directory": script_path,
|
||||
"index": name,
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
24
test/unit/applications/lang/python.py
Normal file
24
test/unit/applications/lang/python.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from unit.applications.proto import TestApplicationProto
|
||||
|
||||
|
||||
class TestApplicationPython(TestApplicationProto):
|
||||
def load(self, script, name=None):
|
||||
if name is None:
|
||||
name = script
|
||||
|
||||
script_path = self.current_dir + '/python/' + script
|
||||
|
||||
self.conf(
|
||||
{
|
||||
"listeners": {"*:7080": {"application": name}},
|
||||
"applications": {
|
||||
name: {
|
||||
"type": "python",
|
||||
"processes": {"spare": 0},
|
||||
"path": script_path,
|
||||
"working_directory": script_path,
|
||||
"module": "wsgi",
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
20
test/unit/applications/lang/ruby.py
Normal file
20
test/unit/applications/lang/ruby.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from unit.applications.proto import TestApplicationProto
|
||||
|
||||
|
||||
class TestApplicationRuby(TestApplicationProto):
|
||||
def load(self, script, name='config.ru'):
|
||||
script_path = self.current_dir + '/ruby/' + script
|
||||
|
||||
self.conf(
|
||||
{
|
||||
"listeners": {"*:7080": {"application": script}},
|
||||
"applications": {
|
||||
script: {
|
||||
"type": "ruby",
|
||||
"processes": {"spare": 0},
|
||||
"working_directory": script_path,
|
||||
"script": script_path + '/' + name,
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user