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.py44
-rw-r--r--test/unit/applications/tls.py15
-rw-r--r--test/unit/applications/websockets.py10
3 files changed, 39 insertions, 30 deletions
diff --git a/test/unit/applications/lang/go.py b/test/unit/applications/lang/go.py
index 367059e6..04af26e1 100644
--- a/test/unit/applications/lang/go.py
+++ b/test/unit/applications/lang/go.py
@@ -1,4 +1,5 @@
import os
+import shutil
import subprocess
from unit.applications.proto import TestApplicationProto
@@ -6,14 +7,25 @@ from unit.option import option
class TestApplicationGo(TestApplicationProto):
- def prepare_env(self, script, name, static=False):
- if not os.path.exists(option.temp_dir + '/go'):
- os.mkdir(option.temp_dir + '/go')
+ @staticmethod
+ def prepare_env(script, name='app', static=False):
+ temp_dir = option.temp_dir + '/go/'
+
+ if not os.path.exists(temp_dir):
+ os.mkdir(temp_dir)
+
+ cache_dir = option.cache_dir + '/go-build'
+
+ if not os.path.exists(cache_dir):
+ os.mkdir(cache_dir)
env = os.environ.copy()
env['GOPATH'] = option.current_dir + '/build/go'
- env['GOCACHE'] = option.cache_dir + '/go'
- env['GO111MODULE'] = 'auto'
+ env['GOCACHE'] = cache_dir
+
+ shutil.copy2(
+ option.test_dir + '/go/' + script + '/' + name + '.go', temp_dir
+ )
if static:
args = [
@@ -24,23 +36,33 @@ class TestApplicationGo(TestApplicationProto):
'-ldflags',
'-extldflags "-static"',
'-o',
- option.temp_dir + '/go/' + name,
- option.test_dir + '/go/' + script + '/' + name + '.go',
+ temp_dir + name,
+ temp_dir + name + '.go',
]
else:
args = [
'go',
'build',
'-o',
- option.temp_dir + '/go/' + name,
- option.test_dir + '/go/' + script + '/' + name + '.go',
+ temp_dir + name,
+ temp_dir + name + '.go',
]
+ replace_path = option.current_dir + '/build/go/src/unit.nginx.org/go'
+
+ with open(temp_dir + 'go.mod', 'w') as f:
+ f.write(
+ f"""module test/app
+require unit.nginx.org/go v0.0.0
+replace unit.nginx.org/go => {replace_path}
+"""
+ )
+
if option.detailed:
print("\n$ GOPATH=" + env['GOPATH'] + " " + " ".join(args))
try:
- process = subprocess.run(args, env=env)
+ process = subprocess.run(args, env=env, cwd=temp_dir)
except KeyboardInterrupt:
raise
@@ -61,7 +83,7 @@ class TestApplicationGo(TestApplicationProto):
executable = "/go/" + name
static_build = True
- self.prepare_env(script, name, static=static_build)
+ TestApplicationGo.prepare_env(script, name, static=static_build)
conf = {
"listeners": {"*:7080": {"pass": "applications/" + script}},
diff --git a/test/unit/applications/tls.py b/test/unit/applications/tls.py
index c7254235..93400328 100644
--- a/test/unit/applications/tls.py
+++ b/test/unit/applications/tls.py
@@ -52,21 +52,6 @@ class TestApplicationTLS(TestApplicationProto):
def post_ssl(self, **kwargs):
return self.post(wrapper=self.context.wrap_socket, **kwargs)
- def get_server_certificate(self, addr=('127.0.0.1', 7080)):
-
- ssl_list = dir(ssl)
-
- if 'PROTOCOL_TLS' in ssl_list:
- ssl_version = ssl.PROTOCOL_TLS
-
- elif 'PROTOCOL_TLSv1_2' in ssl_list:
- ssl_version = ssl.PROTOCOL_TLSv1_2
-
- else:
- ssl_version = ssl.PROTOCOL_TLSv1_1
-
- return ssl.get_server_certificate(addr, ssl_version=ssl_version)
-
def openssl_conf(self, rewrite=False, alt_names=[]):
conf_path = option.temp_dir + '/openssl.conf'
diff --git a/test/unit/applications/websockets.py b/test/unit/applications/websockets.py
index aa83339c..d647ce9b 100644
--- a/test/unit/applications/websockets.py
+++ b/test/unit/applications/websockets.py
@@ -43,7 +43,11 @@ class TestApplicationWebsocket(TestApplicationProto):
'Sec-WebSocket-Version': 13,
}
- _, sock = self.get(headers=headers, no_recv=True, start=True,)
+ _, sock = self.get(
+ headers=headers,
+ no_recv=True,
+ start=True,
+ )
resp = ''
while True:
@@ -218,9 +222,7 @@ class TestApplicationWebsocket(TestApplicationProto):
while pos < message_len:
end = min(pos + fragmention_size, message_len)
fin = end == message_len
- self.frame_write(
- sock, op_code, message[pos:end], fin=fin, **kwargs
- )
+ self.frame_write(sock, op_code, message[pos:end], fin=fin, **kwargs)
op_code = self.OP_CONT
pos = end