go.py (1477:b93d1acf81bd) go.py (1490:cecf6b11a1e3)
1import os
2import subprocess
3
4from unit.applications.proto import TestApplicationProto
5
6
7class TestApplicationGo(TestApplicationProto):
8 @classmethod

--- 5 unchanged lines hidden (view full) ---

14 go_app = TestApplicationGo()
15 go_app.testdir = unit.testdir
16 proc = go_app.prepare_env('empty', 'app')
17 if proc and proc.returncode == 0:
18 cls.available['modules']['go'] = []
19
20 return unit if not complete_check else unit.complete()
21
1import os
2import subprocess
3
4from unit.applications.proto import TestApplicationProto
5
6
7class TestApplicationGo(TestApplicationProto):
8 @classmethod

--- 5 unchanged lines hidden (view full) ---

14 go_app = TestApplicationGo()
15 go_app.testdir = unit.testdir
16 proc = go_app.prepare_env('empty', 'app')
17 if proc and proc.returncode == 0:
18 cls.available['modules']['go'] = []
19
20 return unit if not complete_check else unit.complete()
21
22 def prepare_env(self, script, name):
22 def prepare_env(self, script, name, static=False):
23 if not os.path.exists(self.testdir + '/go'):
24 os.mkdir(self.testdir + '/go')
25
26 env = os.environ.copy()
27 env['GOPATH'] = self.pardir + '/build/go'
28
23 if not os.path.exists(self.testdir + '/go'):
24 os.mkdir(self.testdir + '/go')
25
26 env = os.environ.copy()
27 env['GOPATH'] = self.pardir + '/build/go'
28
29 try:
30 process = subprocess.Popen(
31 [
32 'go',
33 'build',
34 '-o',
35 self.testdir + '/go/' + name,
36 self.current_dir + '/go/' + script + '/' + name + '.go',
37 ],
38 env=env,
39 stderr=subprocess.STDOUT,
40 )
29 if static:
30 args = [
31 'go',
32 'build',
33 '-tags',
34 'netgo',
35 '-ldflags',
36 '-extldflags "-static"',
37 '-o',
38 self.testdir + '/go/' + name,
39 self.current_dir + '/go/' + script + '/' + name + '.go',
40 ]
41 else:
42 args = [
43 'go',
44 'build',
45 '-o',
46 self.testdir + '/go/' + name,
47 self.current_dir + '/go/' + script + '/' + name + '.go',
48 ]
41
49
50 try:
51 process = subprocess.Popen(args, env=env)
42 process.communicate()
43
44 except:
45 return None
46
47 return process
48
49 def load(self, script, name='app', **kwargs):
52 process.communicate()
53
54 except:
55 return None
56
57 return process
58
59 def load(self, script, name='app', **kwargs):
50 self.prepare_env(script, name)
60 static_build = False
51
61
52 self._load_conf(
53 {
54 "listeners": {"*:7080": {"pass": "applications/" + script}},
55 "applications": {
56 script: {
57 "type": "external",
58 "processes": {"spare": 0},
59 "working_directory": self.current_dir
60 + "/go/"
61 + script,
62 "executable": self.testdir + "/go/" + name,
63 }
62 wdir = self.current_dir + "/go/" + script
63 executable = self.testdir + "/go/" + name
64
65 if 'isolation' in kwargs and 'rootfs' in kwargs['isolation']:
66 wdir = "/go/"
67 executable = "/go/" + name
68 static_build = True
69
70 self.prepare_env(script, name, static=static_build)
71
72 conf = {
73 "listeners": {"*:7080": {"pass": "applications/" + script}},
74 "applications": {
75 script: {
76 "type": "external",
77 "processes": {"spare": 0},
78 "working_directory": wdir,
79 "executable": executable,
64 },
65 },
80 },
81 },
66 **kwargs
67 )
82 }
83
84 self._load_conf(conf, **kwargs)