mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-04-21 22:39:08 +00:00
Add CI workflow for functional tests
This commit is contained in:
parent
03f98a0741
commit
c36c4ecf1b
3 changed files with 51 additions and 16 deletions
33
.github/workflows/tests.yml
vendored
Normal file
33
.github/workflows/tests.yml
vendored
Normal 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
2
tests/requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
requests
|
||||
python-dotenv
|
|
@ -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__':
|
||||
|
|
Loading…
Add table
Reference in a new issue