-
Notifications
You must be signed in to change notification settings - Fork 433
/
Makefile
126 lines (103 loc) · 5.16 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
SHELL := /bin/bash -e
VENV := ../.venv
NODE_MODULES := ../node_modules
PIPENV := PIPENV_VENV_IN_PROJECT=true PIPENV_NOSPIN=true PIPENV_HIDE_EMOJIS=true pipenv
BANDIT := $(PIPENV) run bandit
COVERAGE := $(PIPENV) run coverage
PYTEST := $(PIPENV) run py.test
YAPF := $(PIPENV) run yapf
FUTURIZE := $(PIPENV) run ./test-futurize
include ../defines.make
.PHONY: help pipenv-check test-bandit test-docker test-format-python \
test-format-shell test-gui-crawl test-integration test-agent-integration test-packaging \
test-pylint test-python-futurize test-shellcheck test-unit \
list-unit-tests test-unit-one-by-one test-unit-coverage-html
help:
echo $(MAKE) -C $(dir $(VENV)) $(notdir $(VENV))
@echo "pipenv-check - Checks for security vulnerabilities/PEP 508 markers"
@echo "test-bandit - Run bandit (security) tests"
@echo "test-format-python - Test the python formatting"
@echo "test-format-shell - Run the shell formatting"
@echo "test-gui-crawl - Run GUI crawl test"
@echo "test-integration - Run integration tests"
@echo "test-agent-integration - Run agent (plugin) related integration tests"
@echo "test-format-python - Test the python formatting"
@echo "test-packaging - Run packaging tests"
@echo "test-pylint - Run pylint based tests"
@echo "test-python-futurize - Run python futurize tests"
@echo "test-shellcheck - Run shellcheck tests"
@echo "test-unit - Run unit tests"
@echo "test-unit-one-by-one - Run unit tests one by one"
@echo "test-unit-coverage-html - Create HTML coverage report for unit tests"
# These target need to be phony so it is run every time because only the other
# makefile can determine that there's nothing to be done.
# TODO: Move everything to top level makefile?
.PHONY: $(VENV) bandit.ini
$(VENV):
$(MAKE) -C $(dir $(VENV)) $(notdir $(VENV))
$(NODE_MODULES):
$(MAKE) -C $(dir $(NODE_MODULES)) $(notdir $(NODE_MODULES))
bandit.ini:
echo -e "[bandit]\ntargets: $$(./find-python-files | tr '\n' ',' | sed 's/,$$//')" > bandit.ini
pipenv-check: $(VENV)
$(PIPENV) check
test-bandit: $(VENV) bandit.ini
# Currently only care about high severity reported issues. Once this is reached,
# go and enable the medium/low checks.
$(BANDIT) -c ../bandit.yaml -r -lll --ini bandit.ini $(BANDIT_OUTPUT_ARGS)
test-format-python: $(VENV) ../.style.yapf
# Explicitly specify --style [FILE] to prevent costly searching in parent directories
# for each file specified via command line
#
# There are some mixed up lines on stdout caused by the --parallel option.
# Nevertheless, we keep that option to get a big performance boost. GitHub issue
# opened for this problem: https://github.com/google/yapf/issues/644.
@PYTHON_FILES=$${PYTHON_FILES-$$(./find-python-files)} ; \
$(YAPF) --parallel --style ../.style.yapf --verbose --diff $$PYTHON_FILES | \
grep '^+++ .*(reformatted)$$' | \
sed -e 's/^+++ //' -e 's/[[:blank:]]*(reformatted)$$/:1:1: error: file needs formatting/'
test-format-shell:
sudo docker run --rm -v "$(realpath ..):/sh" -w /sh peterdavehello/shfmt shfmt -d -i 4 -ci $(SHELL_FILES)
test-gui-crawl: $(VENV) $(NODE_MODULES)
$(PYTEST) -T gui_crawl $(realpath integration/cmk/gui/test_crawl.py)
test-integration: $(VENV) $(NODE_MODULES)
$(PYTEST) -T integration $(realpath integration)
test-agent-integration: $(VENV)
$(PYTEST) -T agent-integration $(realpath agent-integration)
test-composition: $(VENV) $(NODE_MODULES)
$(PYTEST) -T composition $(realpath composition)
test-packaging: $(VENV)
$(PYTEST) -T packaging packaging
test-pylint: $(VENV)
$(PYTEST) -T pylint pylint
test-python-futurize: $(VENV)
$(FUTURIZE)
test-shellcheck:
@CMK_DIR="$(realpath ..)" ; \
ENTERPRISE_DIR="$(realpath ../enterprise)" ; \
shellcheck \
$(SHELLCHECK_OUTPUT_ARGS) \
$$(grep -l '^#!/.*sh' $$CMK_DIR/agents/* $$CMK_DIR/agents/plugins/* $$CMK_DIR/agents/special/* 2>/dev/null) \
"$$ENTERPRISE_DIR/agents/mk-remote-alert-handler"
test-unit: $(VENV)
$(PYTEST) -T unit unit
# Probably a noteworthy entry for any "obfuscated bash/make/sed contest"...
list-unit-tests: $(VENV)
@$(PYTEST) -T unit unit --collect-only `# list tests in tree form` | \
grep '^\(<Module\| <Function\) ' `# remove docstring lines` | \
sed 's/\[.*\]>/>/' `# remove test parameters` | \
uniq `# keep only one line from parameterized tests` | \
sed 's,^<Module tests/\(.*\)>$$,#\1,' `# keep file name plus a leading marker` | \
sed 's,^ <Function \(.*\)>$$,\1,' `# keep function name` | \
sed -e '/^#/{h;d};G' `# precede every function name line with a file name line` \
-e 's/^\(.*\)\n#\(.*\)/\2::\1/' `# glue the line pairs together`
test-unit-one-by-one: $(VENV)
@set -e ; \
for i in $$($(MAKE) --silent --no-print-directory list-unit-tests); do \
$(PYTEST) -T unit $$i ; \
done
# TODO: We should perhaps use the pytest --cov/--cov-report options, which the
# pytest-cov plugin package adds to pyttest.
test-unit-coverage-html: $(VENV)
$(COVERAGE) run --rcfile=.coveragerc_unit -m pytest -T unit unit
$(COVERAGE) html