Split duplicate & regex in list tests (#161)

* Split duplicates & regex tests

* Rename test workflow & file
* Update test run on push
This commit is contained in:
Nick Spaargaren 2022-10-17 11:23:49 +02:00 committed by GitHub
parent 580d5aeff0
commit ea2ee1ef79
4 changed files with 74 additions and 48 deletions

View file

@ -1,27 +0,0 @@
name: Duplicate checker
on:
push:
branches:
- master
paths:
- 'pihole-google.txt'
pull_request:
branches:
- master
- develop
jobs:
duplicates:
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v2
name: Python setup
- uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install pytest
run: pip install pytest
- name: Check for duplicate lines
run: |
cd scripts
pytest

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

@ -0,0 +1,38 @@
name: Tests
on:
push:
paths:
- 'pihole-google.txt'
jobs:
duplicates:
name: No duplicate domains in list
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v2
name: Python setup
- uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install pytest
run: pip install pytest
- name: Check for duplicate lines
run: |
cd scripts
python3 tests.py --type duplicates
regex:
name: No regex domains in list
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v2
name: Python setup
- uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install pytest
run: pip install pytest
- name: Check if list includes regex domains
run: |
cd scripts
python3 tests.py --type regex

View file

@ -1,21 +0,0 @@
counts = { }
with open("../pihole-google.txt") as f:
for line in f:
domain = line.strip() # strip whitespace
if domain:
if domain in counts: # duplicate line, inc count
counts[domain] = counts[domain]+1
else:
counts[domain] = 1 # new entry
f.close()
for domain, count in counts.items():
if count > 1:
assert False, domain + " occurred more than one time in pihole-google.txt, please remove duplicate domains."
if ".l.google.com" in domain:
assert False, "A l.google.com domain occurred in pihole-google.txt, please remove regex domains."
if ".googlevideo.com" in domain:
assert False, "A googlevideo.com domain occurred in pihole-google.txt, please remove regex domains."
def test_succes():
assert(True)

36
scripts/tests.py Normal file
View file

@ -0,0 +1,36 @@
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--type',
nargs='?',
choices=['duplicates', 'regex'],
help='Test Type')
args = parser.parse_args()
counts = { }
with open("../pihole-google.txt") as f:
for line in f:
domain = line.strip() # strip whitespace
if domain:
if domain in counts: # duplicate line, inc count
counts[domain] = counts[domain]+1
else:
counts[domain] = 1 # new entry
f.close()
if args.type == "duplicates":
for domain, count in counts.items():
if count > 1:
assert False, domain + " occurred more than one time in pihole-google.txt, please remove duplicate domains."
if args.type == "regex":
for domain, count in counts.items():
if ".l.google.com" in domain:
assert False, "A l.google.com domain occurred in pihole-google.txt, please remove regex domains."
if ".googlevideo.com" in domain:
assert False, "A googlevideo.com domain occurred in pihole-google.txt, please remove regex domains."
def test_succes():
assert(True)