From 19eba1730a1ca839ed62a37f34c204f580d1b653 Mon Sep 17 00:00:00 2001 From: Andrey Zelenkov Date: Thu, 28 Mar 2019 18:43:13 +0300 Subject: Tests: unit module refactoring. --- test/unit/applications/lang/__init__.py | 0 test/unit/applications/lang/go.py | 40 ++++++++++++++++++ test/unit/applications/lang/java.py | 74 +++++++++++++++++++++++++++++++++ test/unit/applications/lang/node.py | 34 +++++++++++++++ test/unit/applications/lang/perl.py | 20 +++++++++ test/unit/applications/lang/php.py | 21 ++++++++++ test/unit/applications/lang/python.py | 24 +++++++++++ test/unit/applications/lang/ruby.py | 20 +++++++++ 8 files changed, 233 insertions(+) create mode 100644 test/unit/applications/lang/__init__.py create mode 100644 test/unit/applications/lang/go.py create mode 100644 test/unit/applications/lang/java.py create mode 100644 test/unit/applications/lang/node.py create mode 100644 test/unit/applications/lang/perl.py create mode 100644 test/unit/applications/lang/php.py create mode 100644 test/unit/applications/lang/python.py create mode 100644 test/unit/applications/lang/ruby.py (limited to 'test/unit/applications/lang') diff --git a/test/unit/applications/lang/__init__.py b/test/unit/applications/lang/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/test/unit/applications/lang/go.py b/test/unit/applications/lang/go.py new file mode 100644 index 00000000..4852459c --- /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.conf( + { + "listeners": {"*:7080": {"application": 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..91bfb9ec --- /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.conf( + { + "listeners": {"*:7080": {"application": 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..f1b99cc7 --- /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.conf( + { + "listeners": {"*:7080": {"application": 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..6970873d --- /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.conf( + { + "listeners": {"*:7080": {"application": 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..c4043764 --- /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.conf( + { + "listeners": {"*:7080": {"application": 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..8c2c8707 --- /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.conf( + { + "listeners": {"*:7080": {"application": 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..94086d26 --- /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.conf( + { + "listeners": {"*:7080": {"application": script}}, + "applications": { + script: { + "type": "ruby", + "processes": {"spare": 0}, + "working_directory": script_path, + "script": script_path + '/' + name, + } + }, + } + ) -- cgit From c1a3b06d03c01e4ed40018944b90e6347ebf77d7 Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Mon, 22 Apr 2019 18:20:53 +0300 Subject: Tests: using "pass" option instead of deprecated "application". --- test/unit/applications/lang/go.py | 2 +- test/unit/applications/lang/java.py | 2 +- test/unit/applications/lang/node.py | 2 +- test/unit/applications/lang/perl.py | 2 +- test/unit/applications/lang/php.py | 2 +- test/unit/applications/lang/python.py | 2 +- test/unit/applications/lang/ruby.py | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) (limited to 'test/unit/applications/lang') diff --git a/test/unit/applications/lang/go.py b/test/unit/applications/lang/go.py index 4852459c..4e77118b 100644 --- a/test/unit/applications/lang/go.py +++ b/test/unit/applications/lang/go.py @@ -27,7 +27,7 @@ class TestApplicationGo(TestApplicationProto): self.conf( { - "listeners": {"*:7080": {"application": script}}, + "listeners": {"*:7080": {"pass": "applications/" + script}}, "applications": { script: { "type": "external", diff --git a/test/unit/applications/lang/java.py b/test/unit/applications/lang/java.py index 91bfb9ec..30d186cd 100644 --- a/test/unit/applications/lang/java.py +++ b/test/unit/applications/lang/java.py @@ -60,7 +60,7 @@ class TestApplicationJava(TestApplicationProto): self.conf( { - "listeners": {"*:7080": {"application": script}}, + "listeners": {"*:7080": {"pass": "applications/" + script}}, "applications": { script: { "unit_jars": self.pardir + '/build', diff --git a/test/unit/applications/lang/node.py b/test/unit/applications/lang/node.py index f1b99cc7..191cfed5 100644 --- a/test/unit/applications/lang/node.py +++ b/test/unit/applications/lang/node.py @@ -21,7 +21,7 @@ class TestApplicationNode(TestApplicationProto): self.conf( { - "listeners": {"*:7080": {"application": script}}, + "listeners": {"*:7080": {"pass": "applications/" + script}}, "applications": { script: { "type": "external", diff --git a/test/unit/applications/lang/perl.py b/test/unit/applications/lang/perl.py index 6970873d..d93c15e1 100644 --- a/test/unit/applications/lang/perl.py +++ b/test/unit/applications/lang/perl.py @@ -7,7 +7,7 @@ class TestApplicationPerl(TestApplicationProto): self.conf( { - "listeners": {"*:7080": {"application": script}}, + "listeners": {"*:7080": {"pass": "applications/" + script}}, "applications": { script: { "type": "perl", diff --git a/test/unit/applications/lang/php.py b/test/unit/applications/lang/php.py index c4043764..18c126d5 100644 --- a/test/unit/applications/lang/php.py +++ b/test/unit/applications/lang/php.py @@ -7,7 +7,7 @@ class TestApplicationPHP(TestApplicationProto): self.conf( { - "listeners": {"*:7080": {"application": script}}, + "listeners": {"*:7080": {"pass": "applications/" + script}}, "applications": { script: { "type": "php", diff --git a/test/unit/applications/lang/python.py b/test/unit/applications/lang/python.py index 8c2c8707..31e9b92c 100644 --- a/test/unit/applications/lang/python.py +++ b/test/unit/applications/lang/python.py @@ -10,7 +10,7 @@ class TestApplicationPython(TestApplicationProto): self.conf( { - "listeners": {"*:7080": {"application": name}}, + "listeners": {"*:7080": {"pass": "applications/" + name}}, "applications": { name: { "type": "python", diff --git a/test/unit/applications/lang/ruby.py b/test/unit/applications/lang/ruby.py index 94086d26..0417a915 100644 --- a/test/unit/applications/lang/ruby.py +++ b/test/unit/applications/lang/ruby.py @@ -7,7 +7,7 @@ class TestApplicationRuby(TestApplicationProto): self.conf( { - "listeners": {"*:7080": {"application": script}}, + "listeners": {"*:7080": {"pass": "applications/" + script}}, "applications": { script: { "type": "ruby", -- cgit From 644e6df687425f6eb23a79425a769e1ce5f5437b Mon Sep 17 00:00:00 2001 From: Andrey Zelenkov Date: Fri, 26 Apr 2019 17:35:26 +0300 Subject: Tests: check application configuration loading. --- test/unit/applications/lang/go.py | 2 +- test/unit/applications/lang/java.py | 2 +- test/unit/applications/lang/node.py | 2 +- test/unit/applications/lang/perl.py | 2 +- test/unit/applications/lang/php.py | 2 +- test/unit/applications/lang/python.py | 2 +- test/unit/applications/lang/ruby.py | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) (limited to 'test/unit/applications/lang') diff --git a/test/unit/applications/lang/go.py b/test/unit/applications/lang/go.py index 4e77118b..e4ab8ffa 100644 --- a/test/unit/applications/lang/go.py +++ b/test/unit/applications/lang/go.py @@ -25,7 +25,7 @@ class TestApplicationGo(TestApplicationProto): ) process.communicate() - self.conf( + self._load_conf( { "listeners": {"*:7080": {"pass": "applications/" + script}}, "applications": { diff --git a/test/unit/applications/lang/java.py b/test/unit/applications/lang/java.py index 30d186cd..c4390f15 100644 --- a/test/unit/applications/lang/java.py +++ b/test/unit/applications/lang/java.py @@ -58,7 +58,7 @@ class TestApplicationJava(TestApplicationProto): process = Popen(javac) process.communicate() - self.conf( + self._load_conf( { "listeners": {"*:7080": {"pass": "applications/" + script}}, "applications": { diff --git a/test/unit/applications/lang/node.py b/test/unit/applications/lang/node.py index 191cfed5..931c6596 100644 --- a/test/unit/applications/lang/node.py +++ b/test/unit/applications/lang/node.py @@ -19,7 +19,7 @@ class TestApplicationNode(TestApplicationProto): self.testdir + '/node/node_modules', ) - self.conf( + self._load_conf( { "listeners": {"*:7080": {"pass": "applications/" + script}}, "applications": { diff --git a/test/unit/applications/lang/perl.py b/test/unit/applications/lang/perl.py index d93c15e1..8aaf33a4 100644 --- a/test/unit/applications/lang/perl.py +++ b/test/unit/applications/lang/perl.py @@ -5,7 +5,7 @@ class TestApplicationPerl(TestApplicationProto): def load(self, script, name='psgi.pl'): script_path = self.current_dir + '/perl/' + script - self.conf( + self._load_conf( { "listeners": {"*:7080": {"pass": "applications/" + script}}, "applications": { diff --git a/test/unit/applications/lang/php.py b/test/unit/applications/lang/php.py index 18c126d5..99d84164 100644 --- a/test/unit/applications/lang/php.py +++ b/test/unit/applications/lang/php.py @@ -5,7 +5,7 @@ class TestApplicationPHP(TestApplicationProto): def load(self, script, name='index.php'): script_path = self.current_dir + '/php/' + script - self.conf( + self._load_conf( { "listeners": {"*:7080": {"pass": "applications/" + script}}, "applications": { diff --git a/test/unit/applications/lang/python.py b/test/unit/applications/lang/python.py index 31e9b92c..d1b5b839 100644 --- a/test/unit/applications/lang/python.py +++ b/test/unit/applications/lang/python.py @@ -8,7 +8,7 @@ class TestApplicationPython(TestApplicationProto): script_path = self.current_dir + '/python/' + script - self.conf( + self._load_conf( { "listeners": {"*:7080": {"pass": "applications/" + name}}, "applications": { diff --git a/test/unit/applications/lang/ruby.py b/test/unit/applications/lang/ruby.py index 0417a915..c2d8633e 100644 --- a/test/unit/applications/lang/ruby.py +++ b/test/unit/applications/lang/ruby.py @@ -5,7 +5,7 @@ class TestApplicationRuby(TestApplicationProto): def load(self, script, name='config.ru'): script_path = self.current_dir + '/ruby/' + script - self.conf( + self._load_conf( { "listeners": {"*:7080": {"pass": "applications/" + script}}, "applications": { -- cgit