diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..9e6f1ab --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,33 @@ +on: + pull_request_review: + types: [submitted] + push: + workflow_dispatch: + pull_request_target: + types: [labeled] + +name: Integration Tests + +jobs: + proxy_tests: + name: Proxy Tests + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'safe to test') + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - name: Populate .env + env: + DOTENV: ${{ secrets.DOTENV }} + run: echo "$DOTENV" > .env + - name: Run tests + run: >- + pwd; + ls -la; + sudo python -m pip install -r tests/requirements.txt; + cargo build --release; + sudo python tests/tests.py \ No newline at end of file diff --git a/tests/requirements.txt b/tests/requirements.txt new file mode 100644 index 0000000..d44fe44 --- /dev/null +++ b/tests/requirements.txt @@ -0,0 +1,2 @@ +requests +python-dotenv \ No newline at end of file diff --git a/tests/tests.py b/tests/tests.py index 076411a..0ec0891 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -1,12 +1,12 @@ import glob -import logging -import os -import unittest -import subprocess -import requests -import dotenv -import time import itertools +import os +import subprocess +import time +import unittest + +import dotenv +import requests dotenv.load_dotenv() @@ -34,21 +34,16 @@ def get_tool_path(): return os.environ.get('TOOL_PATH', default) -def start_process(*args): - pass - - class Tun2ProxyTest(unittest.TestCase): @staticmethod def _test(ip_version, dns, proxy_var): ip_noproxy = get_ip(ip_version) - print(ip_noproxy) additional = ['-6'] if ip_version == 6 else [] - p = subprocess.Popen([get_tool_path(), "--proxy", os.getenv(proxy_var), '--setup', '-v', 'trace', '--dns', dns, *additional]) + p = subprocess.Popen( + [get_tool_path(), "--proxy", os.getenv(proxy_var), '--setup', '-v', 'trace', '--dns', dns, *additional]) try: time.sleep(1) ip_withproxy = get_ip(ip_version) - print(ip_withproxy) assert ip_noproxy != ip_withproxy except Exception as e: @@ -59,8 +54,13 @@ class Tun2ProxyTest(unittest.TestCase): @classmethod def add_tests(cls): - for ip_version, dns, proxy_var in itertools.product([None, 4, 6], ['virtual', 'over-tcp'], ['SOCKS5_PROXY', 'HTTP_PROXY']): - setattr(cls, 'test_ipv%s_dns%s_proxy%s' % (ip_version, dns, proxy_var), lambda self: cls._test(ip_version, dns, proxy_var)) + ip_options = [None, 4] + if bool(int(os.environ.get('IPV6', 1))): + ip_options.append(6) + for ip_version, dns, proxy_var in itertools.product(ip_options, ['virtual', 'over-tcp'], + ['SOCKS5_PROXY', 'HTTP_PROXY']): + setattr(cls, 'test_ipv%s_dns%s_proxy%s' % (ip_version, dns, proxy_var), + lambda self: cls._test(ip_version, dns, proxy_var)) if __name__ == '__main__':