-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·51 lines (44 loc) · 1 KB
/
test.sh
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
#!/bin/bash
execute () {
$1
if [ $? -eq 1 ]
then
exit 1
fi
}
run_test () {
package=$1
exit_code=$2
(
cd "testdata/$package" || exit 1
"$pwd/gonforce"
if [ $? -ne "$exit_code" ]
then
echo "$package test case failed"
exit 1
else
echo "$package test case passed"
fi
cd ../..
)
}
execute "go test ./..."
execute "golint ./..."
execute "goimports -w -d $(find . -type f -name '*.go' -not -path './testdata/*')"
execute "gofmt -w -d $(find . -type f -name '*.go' -not -path './testdata/*')"
execute "go run main.go"
pwd=$(pwd)
echo "$pwd"
go build -o gonforce
run_test "no_gonforce_file" 1
run_test "invalid_gonforce_file" 1
run_test "using_blocklisted_import" 1
run_test "using_not_allowlisted_import" 1
run_test "using_allowlist_exception" 1
run_test "failed_allowlist_exception" 1
run_test "invalid_rule_structure" 1
run_test "invalid_import_in_subdir" 1
run_test "subfolder_using_invalid_import" 1
run_test "valid" 0
rm gonforce
echo "All tests passed..."