summaryrefslogtreecommitdiffhomepage
path: root/test/unit/applications/lang
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/applications/lang')
-rw-r--r--test/unit/applications/lang/__init__.py0
-rw-r--r--test/unit/applications/lang/go.py40
-rw-r--r--test/unit/applications/lang/java.py74
-rw-r--r--test/unit/applications/lang/node.py34
-rw-r--r--test/unit/applications/lang/perl.py20
-rw-r--r--test/unit/applications/lang/php.py21
-rw-r--r--test/unit/applications/lang/python.py24
-rw-r--r--test/unit/applications/lang/ruby.py20
8 files changed, 233 insertions, 0 deletions
diff --git a/test/unit/applications/lang/__init__.py b/test/unit/applications/lang/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/unit/applications/lang/__init__.py
diff --git a/test/unit/applications/lang/go.py b/test/unit/applications/lang/go.py
new file mode 100644
index 00000000..e4ab8ffa
--- /dev/null
+++ b/test/unit/applications/lang/go.py
@@ -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._load_conf(
+ {
+ "listeners": {"*:7080": {"pass": "applications/" + script}},
+ "applications": {
+ script: {
+ "type": "external",
+ "processes": {"spare": 0},
+ "working_directory": go_app_path + script,
+ "executable": self.testdir + '/go/' + name,
+ }
+ },
+ }
+ )
diff --git a/test/unit/applications/lang/java.py b/test/unit/applications/lang/java.py
new file mode 100644
index 00000000..c4390f15
--- /dev/null
+++ b/test/unit/applications/lang/java.py
@@ -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._load_conf(
+ {
+ "listeners": {"*:7080": {"pass": "applications/" + script}},
+ "applications": {
+ script: {
+ "unit_jars": self.pardir + '/build',
+ "type": "java",
+ "processes": {"spare": 0},
+ "working_directory": script_path,
+ "webapp": app_path,
+ }
+ },
+ }
+ )
diff --git a/test/unit/applications/lang/node.py b/test/unit/applications/lang/node.py
new file mode 100644
index 00000000..931c6596
--- /dev/null
+++ b/test/unit/applications/lang/node.py
@@ -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._load_conf(
+ {
+ "listeners": {"*:7080": {"pass": "applications/" + script}},
+ "applications": {
+ script: {
+ "type": "external",
+ "processes": {"spare": 0},
+ "working_directory": self.testdir + '/node',
+ "executable": name,
+ }
+ },
+ }
+ )
diff --git a/test/unit/applications/lang/perl.py b/test/unit/applications/lang/perl.py
new file mode 100644
index 00000000..8aaf33a4
--- /dev/null
+++ b/test/unit/applications/lang/perl.py
@@ -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._load_conf(
+ {
+ "listeners": {"*:7080": {"pass": "applications/" + script}},
+ "applications": {
+ script: {
+ "type": "perl",
+ "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
new file mode 100644
index 00000000..99d84164
--- /dev/null
+++ b/test/unit/applications/lang/php.py
@@ -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._load_conf(
+ {
+ "listeners": {"*:7080": {"pass": "applications/" + script}},
+ "applications": {
+ script: {
+ "type": "php",
+ "processes": {"spare": 0},
+ "root": script_path,
+ "working_directory": script_path,
+ "index": name,
+ }
+ },
+ }
+ )
diff --git a/test/unit/applications/lang/python.py b/test/unit/applications/lang/python.py
new file mode 100644
index 00000000..d1b5b839
--- /dev/null
+++ b/test/unit/applications/lang/python.py
@@ -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._load_conf(
+ {
+ "listeners": {"*:7080": {"pass": "applications/" + name}},
+ "applications": {
+ name: {
+ "type": "python",
+ "processes": {"spare": 0},
+ "path": script_path,
+ "working_directory": script_path,
+ "module": "wsgi",
+ }
+ },
+ }
+ )
diff --git a/test/unit/applications/lang/ruby.py b/test/unit/applications/lang/ruby.py
new file mode 100644
index 00000000..c2d8633e
--- /dev/null
+++ b/test/unit/applications/lang/ruby.py
@@ -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._load_conf(
+ {
+ "listeners": {"*:7080": {"pass": "applications/" + script}},
+ "applications": {
+ script: {
+ "type": "ruby",
+ "processes": {"spare": 0},
+ "working_directory": script_path,
+ "script": script_path + '/' + name,
+ }
+ },
+ }
+ )