summaryrefslogtreecommitdiffhomepage
path: root/test/unit/applications/lang/go.py
diff options
context:
space:
mode:
authorKonstantin Pavlov <thresh@nginx.com>2022-06-02 16:51:49 +0400
committerKonstantin Pavlov <thresh@nginx.com>2022-06-02 16:51:49 +0400
commitd9fddee1dbfc1f5d49c8f40386289d7188030952 (patch)
tree842a62b343ac33eba10e7a426a10b55bb1c46aed /test/unit/applications/lang/go.py
parent420395ee2e7cd464e157c49bea3d74f15bf25f30 (diff)
parent0d48fe73c4450901622373e35f6ff3a944ec13d6 (diff)
downloadunit-d9fddee1dbfc1f5d49c8f40386289d7188030952.tar.gz
unit-d9fddee1dbfc1f5d49c8f40386289d7188030952.tar.bz2
Merged with the default branch.1.27.0-1
Diffstat (limited to 'test/unit/applications/lang/go.py')
-rw-r--r--test/unit/applications/lang/go.py44
1 files changed, 33 insertions, 11 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}},