From 81d80fec7fcb6e8fd3387dbbc77cb1935821c8b5 Mon Sep 17 00:00:00 2001 From: garethahealy Date: Mon, 29 Jun 2020 10:03:30 +0100 Subject: [PATCH 1/2] Added bats-lib methods from central repo --- .gitignore | 8 +- _test/_helpers.bash | 3 - _test/bats-support-clone.bash | 9 +++ _test/conftest.sh | 141 ++++++++++++++++++++++++---------- 4 files changed, 117 insertions(+), 44 deletions(-) delete mode 100644 _test/_helpers.bash create mode 100644 _test/bats-support-clone.bash 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..06cdb7b2 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\.*") + 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\.*") + 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\.*") + 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\.*") + 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\.*") + 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\.*") + 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 From 9fb76c08925ccef1c1efcb062764864cf3045dc1 Mon Sep 17 00:00:00 2001 From: garethahealy Date: Tue, 4 Aug 2020 13:32:29 +0100 Subject: [PATCH 2/2] Added buildconfig_jenkinspipeline_strategy to ignore --- _test/conftest.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/_test/conftest.sh b/_test/conftest.sh index 06cdb7b2..0d6ccb34 100755 --- a/_test/conftest.sh +++ b/_test/conftest.sh @@ -23,7 +23,7 @@ setup_file() { @test "basic-nginx/.openshift" { tmp=$(split_files "basic-nginx/.openshift") - namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") + namespaces=$(get_rego_namespaces "(?!ocp\.deprecated.ocp4_3\.buildconfig_jenkinspipeline_strategy)ocp\.deprecated\.*") cmd="conftest test ${tmp} --output tap ${namespaces}" run ${cmd} @@ -56,7 +56,7 @@ setup_file() { @test "basic-tomcat/.openshift" { tmp=$(split_files "basic-tomcat/.openshift") - namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") + namespaces=$(get_rego_namespaces "(?!ocp\.deprecated.ocp4_3\.buildconfig_jenkinspipeline_strategy)ocp\.deprecated\.*") cmd="conftest test ${tmp} --output tap ${namespaces}" run ${cmd} @@ -67,7 +67,7 @@ setup_file() { @test "blue-green-spring/.openshift" { tmp=$(split_files "blue-green-spring/.openshift") - namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") + namespaces=$(get_rego_namespaces "(?!ocp\.deprecated.ocp4_3\.buildconfig_jenkinspipeline_strategy)ocp\.deprecated\.*") cmd="conftest test ${tmp} --output tap ${namespaces}" run ${cmd} @@ -78,7 +78,7 @@ setup_file() { @test "cucumber-selenium-grid/applier" { tmp=$(split_files "cucumber-selenium-grid/applier") - namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") + namespaces=$(get_rego_namespaces "(?!ocp\.deprecated.ocp4_3\.buildconfig_jenkinspipeline_strategy)ocp\.deprecated\.*") cmd="conftest test ${tmp} --output tap ${namespaces}" run ${cmd} @@ -111,7 +111,7 @@ setup_file() { @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\.*") + namespaces=$(get_rego_namespaces "(?!ocp\.deprecated.ocp4_3\.buildconfig_jenkinspipeline_strategy)ocp\.deprecated\.*") cmd="conftest test ${tmp} --output tap ${namespaces}" run ${cmd} @@ -122,7 +122,7 @@ setup_file() { @test "multi-cluster-spring-boot/skopeo-example/.applier" { tmp=$(split_files "multi-cluster-spring-boot/skopeo-example/.applier") - namespaces=$(get_rego_namespaces "ocp\.deprecated\.*") + namespaces=$(get_rego_namespaces "(?!ocp\.deprecated.ocp4_3\.buildconfig_jenkinspipeline_strategy)ocp\.deprecated\.*") cmd="conftest test ${tmp} --output tap ${namespaces}" run ${cmd}