-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added bats-lib methods from central repo (#80)
* Added bats-lib methods from central repo
- Loading branch information
1 parent
8434413
commit b4311a2
Showing
3 changed files
with
205 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
.idea | ||
|
||
# Rego | ||
policy/ | ||
|
||
# BATS | ||
_test/test_helper/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
if [[ ! -d "_test/test_helper/bats-support" ]]; then | ||
# Download bats-support dynamically so it doesnt need to be added into source | ||
git clone https://github.com/ztombol/bats-support _test/test_helper/bats-support --depth 1 | ||
fi | ||
|
||
if [[ ! -d "_test/test_helper/redhatcop-bats-library" ]]; then | ||
# Download redhat-cop/bats-library dynamically so it doesnt need to be added into source | ||
git clone https://github.com/redhat-cop/bats-library _test/test_helper/redhatcop-bats-library --depth 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,158 +1,296 @@ | ||
#!/usr/bin/env bats | ||
|
||
load bats-support-clone | ||
load test_helper/bats-support/load | ||
load test_helper/redhatcop-bats-library/load | ||
|
||
setup_file() { | ||
rm -rf /tmp/rhcop | ||
conftest_pull | ||
} | ||
|
||
@test "amq-broker" { | ||
run conftest test amq-broker --output tap | ||
if [ "$status" -ne 0 ]; then echo "$output" | grep "not ok"; fi | ||
tmp=$(split_files "amq-broker") | ||
|
||
namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
print_info "${status}" "${output}" "${cmd}" "${tmp}" | ||
[ "$status" -eq 0 ] | ||
|
||
} | ||
|
||
@test "app-build" { | ||
run conftest test app-build --output tap | ||
if [ "$status" -ne 0 ]; then echo "$output" | grep "not ok"; fi | ||
tmp=$(split_files "app-build") | ||
|
||
namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
print_info "${status}" "${output}" "${cmd}" "${tmp}" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "app-deploy" { | ||
run conftest test app-deploy --output tap | ||
if [ "$status" -ne 0 ]; then echo "$output" | grep "not ok"; fi | ||
tmp=$(split_files "app-deploy") | ||
|
||
namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
print_info "${status}" "${output}" "${cmd}" "${tmp}" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "app-example-ruby" { | ||
run conftest test app-example-ruby --output tap | ||
if [ "$status" -ne 0 ]; then echo "$output" | grep "not ok"; fi | ||
tmp=$(split_files "app-example-ruby") | ||
|
||
namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
print_info "${status}" "${output}" "${cmd}" "${tmp}" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "jenkins" { | ||
run conftest test jenkins --output tap | ||
if [ "$status" -ne 0 ]; then echo "$output" | grep "not ok"; fi | ||
tmp=$(split_files "jenkins") | ||
|
||
namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
print_info "${status}" "${output}" "${cmd}" "${tmp}" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "jenkins-s2i-build" { | ||
run conftest test jenkins-s2i-build --output tap | ||
if [ "$status" -ne 0 ]; then echo "$output" | grep "not ok"; fi | ||
tmp=$(split_files "jenkins-s2i-build") | ||
|
||
namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
print_info "${status}" "${output}" "${cmd}" "${tmp}" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "imagestreams" { | ||
run conftest test imagestreams --output tap | ||
if [ "$status" -ne 0 ]; then echo "$output" | grep "not ok"; fi | ||
tmp=$(split_files "imagestreams") | ||
|
||
namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
print_info "${status}" "${output}" "${cmd}" "${tmp}" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "jenkins-pipelines" { | ||
run conftest test jenkins-pipelines --output tap | ||
if [ "$status" -ne 0 ]; then echo "$output" | grep "not ok"; fi | ||
tmp=$(split_files "jenkins-pipelines") | ||
|
||
namespaces=$(get_rego_namespaces "(?!ocp\.deprecated.ocp4_3\.buildconfig_jenkinspipeline_strategy)ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
print_info "${status}" "${output}" "${cmd}" "${tmp}" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "jobs" { | ||
run conftest test jobs --output tap | ||
if [ "$status" -ne 0 ]; then echo "$output" | grep "not ok"; fi | ||
tmp=$(split_files "jobs") | ||
|
||
namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
print_info "${status}" "${output}" "${cmd}" "${tmp}" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "namespace" { | ||
run conftest test namespace --output tap | ||
if [ "$status" -ne 0 ]; then echo "$output" | grep "not ok"; fi | ||
tmp=$(split_files "namespace") | ||
|
||
namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
print_info "${status}" "${output}" "${cmd}" "${tmp}" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "net-namespace" { | ||
run conftest test net-namespace --output tap | ||
if [ "$status" -ne 0 ]; then echo "$output" | grep "not ok"; fi | ||
tmp=$(split_files "net-namespace") | ||
|
||
namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
print_info "${status}" "${output}" "${cmd}" "${tmp}" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "nexus" { | ||
run conftest test nexus --output tap | ||
if [ "$status" -ne 0 ]; then echo "$output" | grep "not ok"; fi | ||
tmp=$(split_files "nexus") | ||
|
||
namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
print_info "${status}" "${output}" "${cmd}" "${tmp}" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "ocp-identity-providers" { | ||
run conftest test ocp-identity-providers --output tap | ||
if [ "$status" -ne 0 ]; then echo "$output" | grep "not ok"; fi | ||
tmp=$(split_files "ocp-identity-providers") | ||
|
||
namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
print_info "${status}" "${output}" "${cmd}" "${tmp}" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "operatorhub" { | ||
run conftest test operatorhub --output tap | ||
if [ "$status" -ne 0 ]; then echo "$output" | grep "not ok"; fi | ||
tmp=$(split_files "operatorhub") | ||
|
||
namespaces=$(get_rego_namespaces "(?!ocp\.deprecated\.ocp4_2\.catalogsourceconfigs_v1)(?!ocp\.deprecated\.ocp4_2\.operatorsources_v1)ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
print_info "${status}" "${output}" "${cmd}" "${tmp}" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "pact-broker" { | ||
run conftest test pact-broker --output tap | ||
if [ "$status" -ne 0 ]; then echo "$output" | grep "not ok"; fi | ||
tmp=$(split_files "pact-broker") | ||
|
||
namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
print_info "${status}" "${output}" "${cmd}" "${tmp}" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "prometheus" { | ||
run conftest test prometheus --output tap | ||
if [ "$status" -ne 0 ]; then echo "$output" | grep "not ok"; fi | ||
tmp=$(split_files "prometheus") | ||
|
||
namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
print_info "${status}" "${output}" "${cmd}" "${tmp}" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "project-requests" { | ||
run conftest test project-requests --output tap | ||
if [ "$status" -ne 0 ]; then echo "$output" | grep "not ok"; fi | ||
tmp=$(split_files "project-requests") | ||
|
||
namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
print_info "${status}" "${output}" "${cmd}" "${tmp}" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "rhpam" { | ||
run conftest test rhpam --output tap | ||
if [ "$status" -ne 0 ]; then echo "$output" | grep "not ok"; fi | ||
tmp=$(split_files "rhpam") | ||
|
||
namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
print_info "${status}" "${output}" "${cmd}" "${tmp}" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "rhsso" { | ||
run conftest test rhsso --output tap | ||
if [ "$status" -ne 0 ]; then echo "$output" | grep "not ok"; fi | ||
tmp=$(split_files "rhsso") | ||
|
||
namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
print_info "${status}" "${output}" "${cmd}" "${tmp}" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "role-bindings" { | ||
run conftest test role-bindings --output tap | ||
if [ "$status" -ne 0 ]; then echo "$output" | grep "not ok"; fi | ||
tmp=$(split_files "role-bindings") | ||
|
||
namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
print_info "${status}" "${output}" "${cmd}" "${tmp}" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "s2i-app-build" { | ||
run conftest test s2i-app-build --output tap | ||
tmp=$(split_files "s2i-app-build") | ||
|
||
namespaces=$(get_rego_namespaces "(?!ocp\.deprecated.ocp4_3\.buildconfig_jenkinspipeline_strategy)ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
if [ "$status" -ne 0 ]; then echo "$output"; fi | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "scc" { | ||
run conftest test scc --output tap | ||
if [ "$status" -ne 0 ]; then echo "$output" | grep "not ok"; fi | ||
tmp=$(split_files "scc") | ||
|
||
namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
print_info "${status}" "${output}" "${cmd}" "${tmp}" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "secrets" { | ||
run conftest test secrets --output tap | ||
if [ "$status" -ne 0 ]; then echo "$output" | grep "not ok"; fi | ||
tmp=$(split_files "secrets") | ||
|
||
namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
print_info "${status}" "${output}" "${cmd}" "${tmp}" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "service-accounts" { | ||
run conftest test service-accounts --output tap | ||
if [ "$status" -ne 0 ]; then echo "$output" | grep "not ok"; fi | ||
tmp=$(split_files "service-accounts") | ||
|
||
namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
print_info "${status}" "${output}" "${cmd}" "${tmp}" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "sonarqube" { | ||
run conftest test sonarqube --output tap | ||
if [ "$status" -ne 0 ]; then echo "$output" | grep "not ok"; fi | ||
tmp=$(split_files "sonarqube") | ||
|
||
namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
print_info "${status}" "${output}" "${cmd}" "${tmp}" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "storage" { | ||
run conftest test storage --output tap | ||
if [ "$status" -ne 0 ]; then echo "$output" | grep "not ok"; fi | ||
tmp=$(split_files "storage") | ||
|
||
namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") | ||
cmd="conftest test ${tmp} --output tap ${namespaces}" | ||
run ${cmd} | ||
|
||
print_info "${status}" "${output}" "${cmd}" "${tmp}" | ||
[ "$status" -eq 0 ] | ||
} |