summaryrefslogtreecommitdiffhomepage
path: root/test/unit/applications/lang/go.py
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2022-01-10 16:07:31 +0300
committerMax Romanov <max.romanov@nginx.com>2022-01-10 16:07:31 +0300
commit1297e8a16a2fb0ccc195c0dd14b678bb2d7fc9fc (patch)
treea1ea5a3eb322bd8f3e8c6f222dcb7c076e11339c /test/unit/applications/lang/go.py
parent818a78d82cd9aeb6c7429ef97cd1f39f9053b909 (diff)
downloadunit-1297e8a16a2fb0ccc195c0dd14b678bb2d7fc9fc.tar.gz
unit-1297e8a16a2fb0ccc195c0dd14b678bb2d7fc9fc.tar.bz2
Tests: using modules in Go.
Diffstat (limited to '')
-rw-r--r--test/unit/applications/lang/go.py43
1 files changed, 32 insertions, 11 deletions
diff --git a/test/unit/applications/lang/go.py b/test/unit/applications/lang/go.py
index 367059e6..67501e9c 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,32 @@ 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 +82,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}},