diff --git a/.gitignore b/.gitignore index 1c5c57e6..677b1af4 100644 --- a/.gitignore +++ b/.gitignore @@ -32,4 +32,10 @@ pom.xml.next release.properties dependency-reduced-pom.xml buildNumber.properties -.mvn/timing.properties \ No newline at end of file +.mvn/timing.properties + +# Rego +policy/ + +# BATS +_test/test_helper/ \ No newline at end of file diff --git a/_test/_helpers.bash b/_test/_helpers.bash deleted file mode 100644 index d152003c..00000000 --- a/_test/_helpers.bash +++ /dev/null @@ -1,3 +0,0 @@ -print_err() { - if [ "$1" -ne 0 ]; then echo "$2" | grep "not ok"; fi -} \ No newline at end of file diff --git a/_test/bats-support-clone.bash b/_test/bats-support-clone.bash new file mode 100644 index 00000000..da0556de --- /dev/null +++ b/_test/bats-support-clone.bash @@ -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 \ No newline at end of file diff --git a/_test/conftest.sh b/_test/conftest.sh index 7aeec684..0d6ccb34 100755 --- a/_test/conftest.sh +++ b/_test/conftest.sh @@ -1,81 +1,142 @@ #!/usr/bin/env bats -load _helpers +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 "basic-dotnet-core/.openshift" { - run conftest test basic-dotnet-core/.openshift --output tap - print_err "$status" "$output" + tmp=$(split_files "basic-dotnet-core/.openshift") + + 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 "basic-nginx/.openshift" { - run conftest test basic-nginx/.openshift --output tap - print_err "$status" "$output" - [ "$status" -eq 0 ] -} + tmp=$(split_files "basic-nginx/.openshift") -@test "basic-spring-boot-tekton/.openshift" { - run conftest test basic-spring-boot-tekton/.openshift --output tap - print_err "$status" "$output" + 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 "basic-spring-boot/.openshift basic-tomcat/.openshift" { - run conftest test basic-spring-boot/.openshift basic-tomcat/.openshift --output tap - print_err "$status" "$output" +@test "basic-spring-boot/.openshift" { + tmp=$(split_files "basic-spring-boot/.openshift") + + 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 "blue-green-spring/.openshift" { - run conftest test blue-green-spring/.openshift --output tap - print_err "$status" "$output" +@test "basic-spring-boot-tekton/.openshift" { + tmp=$(split_files "basic-spring-boot-tekton/.openshift") + + 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 "cucumber-selenium-grid/applier/projects" { - run conftest test cucumber-selenium-grid/applier/projects --output tap - print_err "$status" "$output" +@test "basic-tomcat/.openshift" { + tmp=$(split_files "basic-tomcat/.openshift") + + 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 "cucumber-selenium-grid/applier/templates" { - run conftest test cucumber-selenium-grid/applier/templates --output tap - print_err "$status" "$output" +@test "blue-green-spring/.openshift" { + tmp=$(split_files "blue-green-spring/.openshift") + + 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 "jenkins-s2i multi-cluster-multi-branch-jee/.openshift" { - run conftest test jenkins-s2i multi-cluster-multi-branch-jee/.openshift --output tap - print_err "$status" "$output" +@test "cucumber-selenium-grid/applier" { + tmp=$(split_files "cucumber-selenium-grid/applier") + + 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 "multi-cluster-spring-boot/image-mirror-example/.applier/projects" { - run conftest test multi-cluster-spring-boot/image-mirror-example/.applier/projects --output tap - print_err "$status" "$output" +@test "jenkins-s2i" { + tmp=$(split_files "jenkins-s2i") + + 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 "multi-cluster-spring-boot/image-mirror-example/.applier/templates" { - run conftest test multi-cluster-spring-boot/image-mirror-example/.applier/templates --output tap - print_err "$status" "$output" +@test "multi-cluster-multi-branch-jee/.openshift" { + tmp=$(split_files "multi-cluster-multi-branch-jee/.openshift") + + 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 "multi-cluster-spring-boot/skopeo-example/.applier/projects" { - run conftest test multi-cluster-spring-boot/skopeo-example/.applier/projects --output tap - print_err "$status" "$output" +@test "multi-cluster-spring-boot/image-mirror-example/.applier" { + tmp=$(split_files "multi-cluster-spring-boot/image-mirror-example/.applier") + + 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 "multi-cluster-spring-boot/skopeo-example/.applier/templates" { - run conftest test multi-cluster-spring-boot/skopeo-example/.applier/templates --output tap - print_err "$status" "$output" +@test "multi-cluster-spring-boot/skopeo-example/.applier" { + tmp=$(split_files "multi-cluster-spring-boot/skopeo-example/.applier") + + 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 "secure-spring-boot/.openshift-applier/templates" { - run conftest test secure-spring-boot/.openshift-applier/templates --output tap - print_err "$status" "$output" +@test "secure-spring-boot/.openshift-applier" { + tmp=$(split_files "secure-spring-boot/.openshift-applier") + + namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") + cmd="conftest test ${tmp} --output tap ${namespaces}" + run ${cmd} + + print_info "${status}" "${output}" "${cmd}" "${tmp}" [ "$status" -eq 0 ] } \ No newline at end of file