File tree Expand file tree Collapse file tree 2 files changed +52
-1
lines changed Expand file tree Collapse file tree 2 files changed +52
-1
lines changed Original file line number Diff line number Diff line change @@ -101,8 +101,12 @@ boilerplate-update: ## Update boilerplate version
101
101
coverage :
102
102
hack/codecov.sh
103
103
104
+ .PHONY : investigation-unit-tested
105
+ investigation-unit-tested :
106
+ hack/investigation-test-coverage.sh
107
+
104
108
.PHONY : validate
105
- validate : isclean
109
+ validate : isclean investigation-unit-tested
106
110
107
111
# ## Prerequisites
108
112
# ## It is assumed that 'make' is already installed
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ # Text colors for output
5
+ GREEN=' \033[0;32m'
6
+ RED=' \033[0;31m'
7
+ NC=' \033[0m'
8
+
9
+ BASE_SHA=$( git ls-remote " https://github.com/openshift/configuration-anomaly-detection.git" " refs/heads/main" | awk ' {print $1}' )
10
+
11
+ PR_SHA=$( git rev-parse HEAD)
12
+
13
+ # Obtaining instances of files added in the PR
14
+ diff_files=$( git diff --name-status " $BASE_SHA " " $PR_SHA " | grep ' ^A' | awk ' {print $2}' )
15
+
16
+ # Filter to relevant directory (investigations folder)
17
+ investigations=$( echo " $diff_files " | grep ' ^pkg/investigations/' || true)
18
+ if [ -z " $investigations " ]; then
19
+ echo -e " ${GREEN} [PASS] PR does not contain any new files within the \` pkg/investigations\` directory${NC} "
20
+ exit 0
21
+ fi
22
+
23
+ for file in $investigations ; do
24
+ if [[ " $file " =~ ^pkg/investigations/([^/]+)/([^/]+)\. go$ ]]; then
25
+
26
+ if echo " $file " | grep -q " test" ; then
27
+ break
28
+ fi
29
+
30
+ inv_name=" ${BASH_REMATCH[1]} "
31
+ inv_dir=$( dirname " $file " )
32
+ expected_test_file=" ${inv_dir} /${inv_name} _test.go"
33
+
34
+ echo " Found new investigation file: $file , expecting unit test: $expected_test_file "
35
+
36
+ if echo " $diff_files " | grep -xq " $expected_test_file " ; then
37
+ echo " Successfully found test file."
38
+ else
39
+ echo " Failed to locate test file"
40
+ echo -e " ${RED} [FAIL] Added investigation '$inv_name ' is missing a \` ${inv_name} _test.go\` file.${NC} "
41
+ exit 1
42
+ fi
43
+ fi
44
+ done
45
+
46
+ echo -e " ${GREEN} [PASS] Added investigation(s) have a corresponding test file${NC} "
47
+ exit 0
You can’t perform that action at this time.
0 commit comments