summaryrefslogtreecommitdiffhomepage
path: root/test/unit/applications
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/applications')
-rw-r--r--test/unit/applications/lang/go.py76
-rw-r--r--test/unit/applications/lang/java.py3
-rw-r--r--test/unit/applications/lang/node.py6
-rw-r--r--test/unit/applications/lang/python.py19
-rw-r--r--test/unit/applications/proto.py1
-rw-r--r--test/unit/applications/tls.py1
-rw-r--r--test/unit/applications/websockets.py9
7 files changed, 79 insertions, 36 deletions
diff --git a/test/unit/applications/lang/go.py b/test/unit/applications/lang/go.py
index e0f83c0a..83bde4d8 100644
--- a/test/unit/applications/lang/go.py
+++ b/test/unit/applications/lang/go.py
@@ -1,5 +1,6 @@
import os
import subprocess
+
from unit.applications.proto import TestApplicationProto
@@ -18,26 +19,36 @@ class TestApplicationGo(TestApplicationProto):
return unit if not complete_check else unit.complete()
- def prepare_env(self, script, name):
+ def prepare_env(self, script, name, static=False):
if not os.path.exists(self.testdir + '/go'):
os.mkdir(self.testdir + '/go')
env = os.environ.copy()
env['GOPATH'] = self.pardir + '/build/go'
- try:
- process = subprocess.Popen(
- [
- 'go',
- 'build',
- '-o',
- self.testdir + '/go/' + name,
- self.current_dir + '/go/' + script + '/' + name + '.go',
- ],
- env=env,
- stderr=subprocess.STDOUT,
- )
+ if static:
+ args = [
+ 'go',
+ 'build',
+ '-tags',
+ 'netgo',
+ '-ldflags',
+ '-extldflags "-static"',
+ '-o',
+ self.testdir + '/go/' + name,
+ self.current_dir + '/go/' + script + '/' + name + '.go',
+ ]
+ else:
+ args = [
+ 'go',
+ 'build',
+ '-o',
+ self.testdir + '/go/' + name,
+ self.current_dir + '/go/' + script + '/' + name + '.go',
+ ]
+ try:
+ process = subprocess.Popen(args, env=env)
process.communicate()
except:
@@ -46,21 +57,28 @@ class TestApplicationGo(TestApplicationProto):
return process
def load(self, script, name='app', **kwargs):
- self.prepare_env(script, name)
-
- self._load_conf(
- {
- "listeners": {"*:7080": {"pass": "applications/" + script}},
- "applications": {
- script: {
- "type": "external",
- "processes": {"spare": 0},
- "working_directory": self.current_dir
- + "/go/"
- + script,
- "executable": self.testdir + "/go/" + name,
- }
+ static_build = False
+
+ wdir = self.current_dir + "/go/" + script
+ executable = self.testdir + "/go/" + name
+
+ if 'isolation' in kwargs and 'rootfs' in kwargs['isolation']:
+ wdir = "/go/"
+ executable = "/go/" + name
+ static_build = True
+
+ self.prepare_env(script, name, static=static_build)
+
+ conf = {
+ "listeners": {"*:7080": {"pass": "applications/" + script}},
+ "applications": {
+ script: {
+ "type": "external",
+ "processes": {"spare": 0},
+ "working_directory": wdir,
+ "executable": executable,
},
},
- **kwargs
- )
+ }
+
+ self._load_conf(conf, **kwargs)
diff --git a/test/unit/applications/lang/java.py b/test/unit/applications/lang/java.py
index a8a09ce5..c2c6dc51 100644
--- a/test/unit/applications/lang/java.py
+++ b/test/unit/applications/lang/java.py
@@ -1,7 +1,8 @@
-import os
import glob
+import os
import shutil
import subprocess
+
from unit.applications.proto import TestApplicationProto
diff --git a/test/unit/applications/lang/node.py b/test/unit/applications/lang/node.py
index d818298f..cf2a99f6 100644
--- a/test/unit/applications/lang/node.py
+++ b/test/unit/applications/lang/node.py
@@ -1,5 +1,7 @@
import os
import shutil
+from urllib.parse import quote
+
from unit.applications.proto import TestApplicationProto
@@ -33,7 +35,9 @@ class TestApplicationNode(TestApplicationProto):
self._load_conf(
{
- "listeners": {"*:7080": {"pass": "applications/" + script}},
+ "listeners": {
+ "*:7080": {"pass": "applications/" + quote(script, '')}
+ },
"applications": {
script: {
"type": "external",
diff --git a/test/unit/applications/lang/python.py b/test/unit/applications/lang/python.py
index fdda024a..31a04107 100644
--- a/test/unit/applications/lang/python.py
+++ b/test/unit/applications/lang/python.py
@@ -1,3 +1,6 @@
+import shutil
+import os
+
from unit.applications.proto import TestApplicationProto
@@ -8,7 +11,21 @@ class TestApplicationPython(TestApplicationProto):
if name is None:
name = script
- script_path = self.current_dir + '/python/' + script
+ if script[0] == '/':
+ script_path = script
+ else:
+ script_path = self.current_dir + '/python/' + script
+
+ if kwargs.get('isolation') and kwargs['isolation'].get('rootfs'):
+ rootfs = kwargs['isolation']['rootfs']
+
+ if not os.path.exists(rootfs + '/app/python/'):
+ os.makedirs(rootfs + '/app/python/')
+
+ if not os.path.exists(rootfs + '/app/python/' + name):
+ shutil.copytree(script_path, rootfs + '/app/python/' + name)
+
+ script_path = '/app/python/' + name
self._load_conf(
{
diff --git a/test/unit/applications/proto.py b/test/unit/applications/proto.py
index ae1af354..244cb5be 100644
--- a/test/unit/applications/proto.py
+++ b/test/unit/applications/proto.py
@@ -1,5 +1,6 @@
import re
import time
+
from unit.control import TestControl
diff --git a/test/unit/applications/tls.py b/test/unit/applications/tls.py
index 9213974a..e6a846b2 100644
--- a/test/unit/applications/tls.py
+++ b/test/unit/applications/tls.py
@@ -2,6 +2,7 @@ import os
import re
import ssl
import subprocess
+
from unit.applications.proto import TestApplicationProto
diff --git a/test/unit/applications/websockets.py b/test/unit/applications/websockets.py
index fc15e8e4..e0dd2c0d 100644
--- a/test/unit/applications/websockets.py
+++ b/test/unit/applications/websockets.py
@@ -1,10 +1,11 @@
-import re
-import random
import base64
-import struct
-import select
import hashlib
import itertools
+import random
+import re
+import select
+import struct
+
from unit.applications.proto import TestApplicationProto
GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"