Add CI workflow for functional tests

This commit is contained in:
B. Blechschmidt 2024-04-18 22:47:16 +02:00
parent 03f98a0741
commit c36c4ecf1b
3 changed files with 51 additions and 16 deletions

33
.github/workflows/tests.yml vendored Normal file
View file

@ -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

2
tests/requirements.txt Normal file
View file

@ -0,0 +1,2 @@
requests
python-dotenv

View file

@ -1,12 +1,12 @@
import glob import glob
import logging
import os
import unittest
import subprocess
import requests
import dotenv
import time
import itertools import itertools
import os
import subprocess
import time
import unittest
import dotenv
import requests
dotenv.load_dotenv() dotenv.load_dotenv()
@ -34,21 +34,16 @@ def get_tool_path():
return os.environ.get('TOOL_PATH', default) return os.environ.get('TOOL_PATH', default)
def start_process(*args):
pass
class Tun2ProxyTest(unittest.TestCase): class Tun2ProxyTest(unittest.TestCase):
@staticmethod @staticmethod
def _test(ip_version, dns, proxy_var): def _test(ip_version, dns, proxy_var):
ip_noproxy = get_ip(ip_version) ip_noproxy = get_ip(ip_version)
print(ip_noproxy)
additional = ['-6'] if ip_version == 6 else [] 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: try:
time.sleep(1) time.sleep(1)
ip_withproxy = get_ip(ip_version) ip_withproxy = get_ip(ip_version)
print(ip_withproxy)
assert ip_noproxy != ip_withproxy assert ip_noproxy != ip_withproxy
except Exception as e: except Exception as e:
@ -59,8 +54,13 @@ class Tun2ProxyTest(unittest.TestCase):
@classmethod @classmethod
def add_tests(cls): def add_tests(cls):
for ip_version, dns, proxy_var in itertools.product([None, 4, 6], ['virtual', 'over-tcp'], ['SOCKS5_PROXY', 'HTTP_PROXY']): ip_options = [None, 4]
setattr(cls, 'test_ipv%s_dns%s_proxy%s' % (ip_version, dns, proxy_var), lambda self: cls._test(ip_version, dns, proxy_var)) 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__': if __name__ == '__main__':