Browse Source

Add CI workflow for functional tests

pull/119/head
B. Blechschmidt 2 years ago
parent
commit
c36c4ecf1b
  1. 33
      .github/workflows/tests.yml
  2. 2
      tests/requirements.txt
  3. 28
      tests/tests.py

33
.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

2
tests/requirements.txt

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

28
tests/tests.py

@ -1,12 +1,12 @@
import glob
import logging
import itertools
import os
import unittest
import subprocess
import requests
import dotenv
import time
import itertools
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__':

Loading…
Cancel
Save