summaryrefslogtreecommitdiffhomepage
path: root/test/unit/applications/lang
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--test/unit/applications/lang/go.py16
-rw-r--r--test/unit/applications/lang/java.py29
-rw-r--r--test/unit/applications/lang/node.py13
-rw-r--r--test/unit/applications/lang/perl.py6
-rw-r--r--test/unit/applications/lang/php.py18
-rw-r--r--test/unit/applications/lang/python.py25
-rw-r--r--test/unit/applications/lang/ruby.py6
7 files changed, 69 insertions, 44 deletions
diff --git a/test/unit/applications/lang/go.py b/test/unit/applications/lang/go.py
index 7715bd6c..866dec47 100644
--- a/test/unit/applications/lang/go.py
+++ b/test/unit/applications/lang/go.py
@@ -7,8 +7,8 @@ from unit.applications.proto import TestApplicationProto
class TestApplicationGo(TestApplicationProto):
def prepare_env(self, script, name, static=False):
- if not os.path.exists(self.temp_dir + '/go'):
- os.mkdir(self.temp_dir + '/go')
+ if not os.path.exists(option.temp_dir + '/go'):
+ os.mkdir(option.temp_dir + '/go')
env = os.environ.copy()
env['GOPATH'] = option.current_dir + '/build/go'
@@ -22,7 +22,7 @@ class TestApplicationGo(TestApplicationProto):
'-ldflags',
'-extldflags "-static"',
'-o',
- self.temp_dir + '/go/' + name,
+ option.temp_dir + '/go/' + name,
option.test_dir + '/go/' + script + '/' + name + '.go',
]
else:
@@ -30,14 +30,20 @@ class TestApplicationGo(TestApplicationProto):
'go',
'build',
'-o',
- self.temp_dir + '/go/' + name,
+ option.temp_dir + '/go/' + name,
option.test_dir + '/go/' + script + '/' + name + '.go',
]
+ if option.detailed:
+ print("\n$ GOPATH=" + env['GOPATH'] + " " + " ".join(args))
+
try:
process = subprocess.Popen(args, env=env)
process.communicate()
+ except KeyboardInterrupt:
+ raise
+
except:
return None
@@ -47,7 +53,7 @@ class TestApplicationGo(TestApplicationProto):
static_build = False
wdir = option.test_dir + "/go/" + script
- executable = self.temp_dir + "/go/" + name
+ executable = option.temp_dir + "/go/" + name
if 'isolation' in kwargs and 'rootfs' in kwargs['isolation']:
wdir = "/go/"
diff --git a/test/unit/applications/lang/java.py b/test/unit/applications/lang/java.py
index 01cbfa0b..0ff85187 100644
--- a/test/unit/applications/lang/java.py
+++ b/test/unit/applications/lang/java.py
@@ -9,8 +9,10 @@ from unit.applications.proto import TestApplicationProto
class TestApplicationJava(TestApplicationProto):
- def load(self, script, name='app', **kwargs):
- app_path = self.temp_dir + '/java'
+ application_type = "java"
+
+ def prepare_env(self, script):
+ app_path = option.temp_dir + '/java'
web_inf_path = app_path + '/WEB-INF/'
classes_path = web_inf_path + 'classes/'
script_path = option.test_dir + '/java/' + script + '/'
@@ -50,7 +52,7 @@ class TestApplicationJava(TestApplicationProto):
os.makedirs(classes_path)
classpath = (
- option.current_dir + '/build/tomcat-servlet-api-9.0.13.jar'
+ option.current_dir + '/build/tomcat-servlet-api-9.0.39.jar'
)
ws_jars = glob.glob(
@@ -62,18 +64,28 @@ class TestApplicationJava(TestApplicationProto):
javac = [
'javac',
+ '-target', '8', '-source', '8', '-nowarn',
'-encoding', 'utf-8',
'-d', classes_path,
'-classpath', classpath + ':' + ws_jars[0],
]
javac.extend(src)
+ if option.detailed:
+ print("\n$ " + " ".join(javac))
+
try:
process = subprocess.Popen(javac, stderr=subprocess.STDOUT)
process.communicate()
+ except KeyboardInterrupt:
+ raise
+
except:
- pytest.fail('Cann\'t run javac process.')
+ pytest.fail('Can\'t run javac process.')
+
+ def load(self, script, **kwargs):
+ self.prepare_env(script)
self._load_conf(
{
@@ -81,10 +93,13 @@ class TestApplicationJava(TestApplicationProto):
"applications": {
script: {
"unit_jars": option.current_dir + '/build',
- "type": 'java',
+ "type": self.get_application_type(),
"processes": {"spare": 0},
- "working_directory": script_path,
- "webapp": app_path,
+ "working_directory": option.test_dir
+ + '/java/'
+ + script
+ + '/',
+ "webapp": option.temp_dir + '/java',
}
},
},
diff --git a/test/unit/applications/lang/node.py b/test/unit/applications/lang/node.py
index 877fc461..98fd9ffc 100644
--- a/test/unit/applications/lang/node.py
+++ b/test/unit/applications/lang/node.py
@@ -7,21 +7,24 @@ from unit.applications.proto import TestApplicationProto
class TestApplicationNode(TestApplicationProto):
- def load(self, script, name='app.js', **kwargs):
+ def prepare_env(self, script):
# copy application
shutil.copytree(
- option.test_dir + '/node/' + script, self.temp_dir + '/node'
+ option.test_dir + '/node/' + script, option.temp_dir + '/node'
)
# copy modules
shutil.copytree(
option.current_dir + '/node/node_modules',
- self.temp_dir + '/node/node_modules',
+ option.temp_dir + '/node/node_modules',
)
- public_dir(self.temp_dir + '/node')
+ public_dir(option.temp_dir + '/node')
+
+ def load(self, script, name='app.js', **kwargs):
+ self.prepare_env(script)
self._load_conf(
{
@@ -32,7 +35,7 @@ class TestApplicationNode(TestApplicationProto):
script: {
"type": "external",
"processes": {"spare": 0},
- "working_directory": self.temp_dir + '/node',
+ "working_directory": option.temp_dir + '/node',
"executable": name,
}
},
diff --git a/test/unit/applications/lang/perl.py b/test/unit/applications/lang/perl.py
index a27c7649..9dc24ace 100644
--- a/test/unit/applications/lang/perl.py
+++ b/test/unit/applications/lang/perl.py
@@ -7,17 +7,13 @@ class TestApplicationPerl(TestApplicationProto):
def load(self, script, name='psgi.pl', **kwargs):
script_path = option.test_dir + '/perl/' + script
- appication_type = self.get_appication_type()
-
- if appication_type is None:
- appication_type = self.application_type
self._load_conf(
{
"listeners": {"*:7080": {"pass": "applications/" + script}},
"applications": {
script: {
- "type": appication_type,
+ "type": self.get_application_type(),
"processes": {"spare": 0},
"working_directory": script_path,
"script": script_path + '/' + name,
diff --git a/test/unit/applications/lang/php.py b/test/unit/applications/lang/php.py
index 2d50df2e..3dbb32f5 100644
--- a/test/unit/applications/lang/php.py
+++ b/test/unit/applications/lang/php.py
@@ -1,4 +1,7 @@
from conftest import option
+import os
+import shutil
+
from unit.applications.proto import TestApplicationProto
@@ -7,17 +10,24 @@ class TestApplicationPHP(TestApplicationProto):
def load(self, script, index='index.php', **kwargs):
script_path = option.test_dir + '/php/' + script
- appication_type = self.get_appication_type()
- if appication_type is None:
- appication_type = self.application_type
+ if kwargs.get('isolation') and kwargs['isolation'].get('rootfs'):
+ rootfs = kwargs['isolation']['rootfs']
+
+ if not os.path.exists(rootfs + '/app/php/'):
+ os.makedirs(rootfs + '/app/php/')
+
+ if not os.path.exists(rootfs + '/app/php/' + script):
+ shutil.copytree(script_path, rootfs + '/app/php/' + script)
+
+ script_path = '/app/php/' + script
self._load_conf(
{
"listeners": {"*:7080": {"pass": "applications/" + script}},
"applications": {
script: {
- "type": appication_type,
+ "type": self.get_application_type(),
"processes": {"spare": 0},
"root": script_path,
"working_directory": script_path,
diff --git a/test/unit/applications/lang/python.py b/test/unit/applications/lang/python.py
index 47b95dac..792a86fa 100644
--- a/test/unit/applications/lang/python.py
+++ b/test/unit/applications/lang/python.py
@@ -12,7 +12,6 @@ class TestApplicationPython(TestApplicationProto):
load_module = "wsgi"
def load(self, script, name=None, module=None, **kwargs):
- print()
if name is None:
name = script
@@ -35,25 +34,25 @@ class TestApplicationPython(TestApplicationProto):
script_path = '/app/python/' + name
- appication_type = self.get_appication_type()
+ app = {
+ "type": self.get_application_type(),
+ "processes": kwargs.pop('processes', {"spare": 0}),
+ "path": script_path,
+ "working_directory": script_path,
+ "module": module,
+ }
- if appication_type is None:
- appication_type = self.application_type
+ for attr in ('callable', 'home', 'limits', 'path', 'protocol',
+ 'threads'):
+ if attr in kwargs:
+ app[attr] = kwargs.pop(attr)
self._load_conf(
{
"listeners": {
"*:7080": {"pass": "applications/" + quote(name, '')}
},
- "applications": {
- name: {
- "type": appication_type,
- "processes": {"spare": 0},
- "path": script_path,
- "working_directory": script_path,
- "module": module,
- }
- },
+ "applications": {name: app},
},
**kwargs
)
diff --git a/test/unit/applications/lang/ruby.py b/test/unit/applications/lang/ruby.py
index bc3cefc6..82d66e65 100644
--- a/test/unit/applications/lang/ruby.py
+++ b/test/unit/applications/lang/ruby.py
@@ -7,17 +7,13 @@ class TestApplicationRuby(TestApplicationProto):
def load(self, script, name='config.ru', **kwargs):
script_path = option.test_dir + '/ruby/' + script
- appication_type = self.get_appication_type()
-
- if appication_type is None:
- appication_type = self.application_type
self._load_conf(
{
"listeners": {"*:7080": {"pass": "applications/" + script}},
"applications": {
script: {
- "type": appication_type,
+ "type": self.get_application_type(),
"processes": {"spare": 0},
"working_directory": script_path,
"script": script_path + '/' + name,