aboutsummaryrefslogtreecommitdiff
path: root/test/integration_test.py
diff options
context:
space:
mode:
authorflu0r1ne <flu0r1ne@flu0r1ne.net>2024-06-05 13:35:20 -0700
committerflu0r1ne <flu0r1ne@flu0r1ne.net>2024-06-05 13:35:20 -0700
commit23a37100f121edd0c1291c4a78901662eae5d58b (patch)
tree1b16a2f5b53746b0bef8f5f7f92729f128d2baaa /test/integration_test.py
parent24ac246d85115396489f970d2396acdbad93431b (diff)
downloadwg2nd-23a37100f121edd0c1291c4a78901662eae5d58b.tar.xz
wg2nd-23a37100f121edd0c1291c4a78901662eae5d58b.zip
Integration tests and "\r\n" DOS-style line feedsHEADv0.2.1main
- Parse \r\n line feeds - Add simple integration tests to ensure regressions do not occur - Add test "wg1" for \r\n parsing
Diffstat (limited to 'test/integration_test.py')
-rw-r--r--test/integration_test.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/integration_test.py b/test/integration_test.py
new file mode 100644
index 0000000..2616986
--- /dev/null
+++ b/test/integration_test.py
@@ -0,0 +1,61 @@
+from pathlib import Path
+from enum import Enum
+import subprocess
+import sys
+
+WG2ND_EXECUTABLE = "./wg2nd"
+TEST_DIRECTORY = './test/example_config'
+TESTS = [
+ 'wg0',
+ 'wg1', # same as wg0 except with \r\n
+]
+
+def die(*args, code: int = 1, **kwargs):
+ print(*args, **kwargs, file=sys.stderr)
+ sys.exit(code)
+
+class Wg2ndFileType( Enum ):
+ NETWORK = 'network'
+ NETDEV = 'netdev'
+ KEYFILE = 'keyfile'
+ NFT = 'nft'
+
+def wg2nd_generate(filetype: Wg2ndFileType, path: Path):
+
+ try:
+ result = subprocess.run([
+ WG2ND_EXECUTABLE, 'generate', '-t', filetype.value, str(path)
+ ], capture_output=True, check=True)
+ except FileNotFoundError:
+ die(f'Failed to find executable "{WG2ND_EXECUTABLE}"')
+ except subprocess.CalledProcessError as e:
+ die(f'Failed to generate config with wg2nd: {e}')
+
+ return str(result.stdout, encoding='utf-8')
+
+def read_config(path: str) -> str:
+
+ with open(path, 'r') as f:
+ return f.read()
+
+for test in TESTS:
+
+ test_directory = Path(TEST_DIRECTORY) / test
+
+ wg_config = test_directory / f'{test}.conf'
+
+ expected_netdev = read_config(test_directory / f'{test}.netdev')
+ expected_network = read_config(test_directory / f'{test}.network')
+ expected_nftables = read_config(test_directory / 'nftables.conf')
+
+ network = wg2nd_generate(Wg2ndFileType.NETWORK, wg_config)
+ netdev = wg2nd_generate(Wg2ndFileType.NETDEV, wg_config)
+ nftables = wg2nd_generate(Wg2ndFileType.NFT, wg_config)
+
+ print(f'testing {test}')
+
+ assert network == expected_network
+ assert netdev == expected_netdev
+ assert nftables == expected_nftables
+
+ print('pass')