mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2025-12-06 17:22:49 +01:00
Add automated CI for analyzers
This commit is contained in:
37
.github/workflows/pythontest.yml
vendored
Normal file
37
.github/workflows/pythontest.yml
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
name: python-test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ $default-branch ]
|
||||
pull_request:
|
||||
branches: [ $default-branch ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
python-version: ["3.8", "3.9", "3.10"]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v3
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
python -m pip install flake8 pytest
|
||||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
||||
- name: Lint with flake8
|
||||
run: |
|
||||
# stop the build if there are Python syntax errors or undefined names
|
||||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
|
||||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
|
||||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
||||
- name: Test with pytest
|
||||
run: |
|
||||
pytest
|
||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -56,4 +56,8 @@ $RECYCLE.BIN/
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
# End of https://www.gitignore.io/api/macos,windows
|
||||
# End of https://www.gitignore.io/api/macos,windows
|
||||
|
||||
# Pytest output
|
||||
__pycache__
|
||||
.coverage
|
||||
|
||||
8
salt/sensoroni/files/analyzers/pytest.ini
Normal file
8
salt/sensoroni/files/analyzers/pytest.ini
Normal file
@@ -0,0 +1,8 @@
|
||||
[pytest]
|
||||
python_files = *_test.py
|
||||
python_classes = Test
|
||||
python_functions = test_*
|
||||
|
||||
[report]
|
||||
exclude_lines =
|
||||
if __name__ == .__main__.:
|
||||
@@ -1,5 +0,0 @@
|
||||
def main():
|
||||
print '{"foo":"bar","summary":"something here"}'
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,5 +1,5 @@
|
||||
def main():
|
||||
print '{"result":{ "requestId": "something-generated-by-whois", "someother_field": "more data" }, "summary": "botsrv.btc-goblin.ru"}'
|
||||
print('{"result":{ "requestId": "something-generated-by-whois", "someother_field": "more data" }, "summary": "botsrv.btc-goblin.ru"}')
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
12
salt/sensoroni/files/analyzers/whois/whois_test.py
Normal file
12
salt/sensoroni/files/analyzers/whois/whois_test.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from io import StringIO
|
||||
from unittest.mock import patch
|
||||
from whois import whois
|
||||
import unittest
|
||||
|
||||
class TestWhoisMethods(unittest.TestCase):
|
||||
|
||||
def test_main(self):
|
||||
with patch('sys.stdout', new = StringIO()) as mock_stdout:
|
||||
whois.main()
|
||||
expected = '{"result":{ "requestId": "something-generated-by-whois", "someother_field": "more data" }, "summary": "botsrv.btc-goblin.ru"}\n'
|
||||
self.assertEqual(mock_stdout.getvalue(), expected)
|
||||
Reference in New Issue
Block a user