xref: /unit/test/unit/applications/lang/go.py (revision 1041:9bdd46610ea9)
1import os
2from subprocess import Popen
3from unit.applications.proto import TestApplicationProto
4
5
6class TestApplicationGo(TestApplicationProto):
7    def load(self, script, name='app'):
8
9        if not os.path.isdir(self.testdir + '/go'):
10            os.mkdir(self.testdir + '/go')
11
12        go_app_path = self.current_dir + '/go/'
13
14        env = os.environ.copy()
15        env['GOPATH'] = self.pardir + '/go'
16        process = Popen(
17            [
18                'go',
19                'build',
20                '-o',
21                self.testdir + '/go/' + name,
22                go_app_path + script + '/' + name + '.go',
23            ],
24            env=env,
25        )
26        process.communicate()
27
28        self.conf(
29            {
30                "listeners": {"*:7080": {"pass": "applications/" + script}},
31                "applications": {
32                    script: {
33                        "type": "external",
34                        "processes": {"spare": 0},
35                        "working_directory": go_app_path + script,
36                        "executable": self.testdir + '/go/' + name,
37                    }
38                },
39            }
40        )
41