Skip to content

Commit

Permalink
tests: integration tests for branching day tools
Browse files Browse the repository at this point in the history
  • Loading branch information
danilo-gemoli committed Jan 11, 2023
1 parent c8196ce commit 005d338
Show file tree
Hide file tree
Showing 26 changed files with 1,044 additions and 0 deletions.
90 changes: 90 additions & 0 deletions hack/lib/branchcuts/test-common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
readonly src_test_files_relative_dir="data"
readonly want_test_files_relative_dir="want"
readonly test_config_relative_path="test_config"

function branchcuts::read_test_config() {
local -n _cfg=$1
local _test_config_path="${2}"
for key_value in $(cat "${_test_config_path}")
do
if [[ "${key_value}" =~ (.+?)=(.*) ]]
then
_cfg["${BASH_REMATCH[1]}"]="${BASH_REMATCH[2]}"
fi
done
}
readonly -f branchcuts::read_test_config

function branchcuts::check_result() {
local _test_case_dir="${1}"
local _result_dir="${_test_case_dir}/${src_test_files_relative_dir}"
local _want_dir="${_test_case_dir}/${want_test_files_relative_dir}"

local _results=$(find "${_result_dir}" -printf '%P\n'|sort)
local _wants=$(find "${_want_dir}" -printf '%P\n'|sort)
if [[ "${_results}" != "${_wants}" ]]
then
os::log::warning $'folders structure doesn\'t match\nresults:\n'"${_results}"$'\nwants:\n'"${_wants}"
return 1
fi

local _exit_status=0
for f in $_results
do
local _result_file="${_test_case_dir}/${src_test_files_relative_dir}/${f}"
if test ! -f "${_result_file}"
then
continue
fi

local _want_file="${_test_case_dir}/${want_test_files_relative_dir}/${f}"
os::integration::compare "${_want_file}" "${_result_file}"
if test $? -ne 0
then
_exit_status=1
fi
done

return $_exit_status
}
readonly -f branchcuts::check_result

function branchcuts::run_tests_template() {
local run_cfg_manager_fn="${1}"
local _diffs=""
local _exit_status=0

for test_case in $(ls "${test_cases_dir}")
do
os::log::info "Test case: '${test_case}' - Starts"
local _src_test_files_dir="${test_cases_dir}/${test_case}/${src_test_files_relative_dir}"
local _want_test_files_dir="${test_cases_dir}/${test_case}/${want_test_files_relative_dir}"

# Read test config from file and set some vars
local _test_config_file_path="${test_cases_dir}/${test_case}/${test_config_relative_path}"
declare -A _test_config
branchcuts::read_test_config _test_config "${_test_config_file_path}"

# Function 'run_config_manager' should be defined into the caller script
if test $(type -t "${run_cfg_manager_fn}") == "function"
then
os::cmd::expect_success "${run_cfg_manager_fn} \"${_src_test_files_dir}\" _test_config"
else
os::log::error "function '${run_cfg_manager_fn}' is not defined"
exit 1
fi

_diffs=$(branchcuts::check_result "${test_cases_dir}/${test_case}")
if test $? -ne 0
then
os::log::info "${_diffs}"
_exit_status=1
os::log::error "Test case: '${test_case}' - FAILURE!"
else
os::log::info "Test case: '${test_case}' - SUCCESS"
fi
done

return $_exit_status
}
readonly -f branchcuts::run_tests_template
41 changes: 41 additions & 0 deletions test/integration/br-cuts-generated-release-jobs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash

source "$(dirname "${BASH_SOURCE}")/../../hack/lib/init.sh"

readonly release_repo_relative_dir="ci-operator/config/openshift/release"
readonly test_cases_dir="${OS_ROOT}/test/integration/branchcuts/generated-release-gating-jobs"

function cleanup() {
os::test::junit::reconcile_output
os::cleanup::processes
}
trap "cleanup" EXIT

function branchcuts::generated_release_jobs::run_config_manager() {
local _test_case_data="${1}"
local -n _cfg=$2
local _release_repo_path="${_test_case_data}/release"

local _cmd=$(printf "%s\n%s %s\n%s %s\n%s %s" \
generated-release-gating-jobs \
--release-repo "${_release_repo_path}" \
--current-release "${_cfg['current_ocp_release']}" \
--interval "${_cfg['interval']}")

os::log::info "${_cmd}"

generated-release-gating-jobs \
--release-repo "${_release_repo_path}" \
--current-release "${_cfg['current_ocp_release']}" \
--interval "${_cfg['interval']}"
}
readonly -f branchcuts::generated_release_jobs::run_config_manager

function branchcuts::generated_release_jobs::run_tests() {
branchcuts::run_tests_template branchcuts::generated_release_jobs::run_config_manager
}
readonly -f branchcuts::generated_release_jobs::run_tests

os::test::junit::declare_suite_start "integration/branchcuts/generated-release-gating-jobs"
os::cmd::expect_success "branchcuts::generated_release_jobs::run_tests"
os::test::junit::declare_suite_end
40 changes: 40 additions & 0 deletions test/integration/br-cuts-release-controller-configs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

source "$(dirname "${BASH_SOURCE}")/../../hack/lib/init.sh"

readonly release_repo_relative_dir="core-services/release-controller/_releases"
readonly test_cases_dir="${OS_ROOT}/test/integration/branchcuts/release-controller-configs"

function cleanup() {
os::test::junit::reconcile_output
os::cleanup::processes
}
trap "cleanup" EXIT

function branchcuts::release_controller_cfg::run_config_manager() {
local _test_case_data="${1}"
local -n _cfg=$2
local _release_repo_path="${_test_case_data}/release"

local _cmd=$(printf "%s\n%s %s\n%s %s" \
release-controller-config-manager \
--release-repo "${_release_repo_path}" \
--current-release "${_cfg['current_ocp_release']}")

os::log::info "${_cmd}"

release-controller-config-manager \
--release-repo "${_release_repo_path}" \
--current-release "${_cfg['current_ocp_release']}"
}
readonly -f branchcuts::release_controller_cfg::run_config_manager


function branchcuts::release_controller_cfg::run_tests() {
branchcuts::run_tests_template branchcuts::release_controller_cfg::run_config_manager
}
readonly -f branchcuts::release_controller_cfg::run_tests

os::test::junit::declare_suite_start "integration/branchcuts/release-controller-configs"
os::cmd::expect_success "branchcuts::release_controller_cfg::run_tests"
os::test::junit::declare_suite_end
41 changes: 41 additions & 0 deletions test/integration/br-cuts-rpm-mirroring-services.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash

source "$(dirname "${BASH_SOURCE}")/../../hack/lib/init.sh"

readonly release_repo_relative_dir="core-services/release-controller/_repos"
readonly test_cases_dir="${OS_ROOT}/test/integration/branchcuts/rpm-deps-mirroring-services"

function cleanup() {
os::test::junit::reconcile_output
os::cleanup::processes
}
trap "cleanup" EXIT

function branchcuts::rpm_mirroring::run_config_manager() {
local _test_case_data="${1}"
local -n _cfg=$2
local _release_repo_path="${_test_case_data}/release"
local _current_release="${_cfg['current_ocp_release']}"

local _cmd=$(printf "%s\n%s %s\n%s %s\n%s %s" \
rpm-deps-mirroring-services \
--release-repo "${_release_repo_path}" \
--current-release "${_current_release}")

os::log::info "${_cmd}"

rpm-deps-mirroring-services \
--release-repo "${_release_repo_path}" \
--current-release "${_current_release}"
}
readonly -f branchcuts::rpm_mirroring::run_config_manager


function branchcuts::rpm_mirroring::run_tests() {
branchcuts::run_tests_template branchcuts::rpm_mirroring::run_config_manager
}
readonly -f branchcuts::rpm_mirroring::run_tests

os::test::junit::declare_suite_start "integration/branchcuts/rpm-deps-mirroring-services"
os::cmd::expect_success "branchcuts::rpm_mirroring::run_tests"
os::test::junit::declare_suite_end
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
releases:
initial:
candidate:
product: ocp
relative: 1
stream: ci
version: "4.10"
latest:
candidate:
product: ocp
stream: ci
version: "4.10"
resources:
'*':
requests:
cpu: 100m
memory: 200Mi
tests:
- as: e2e-aws
interval: 24h
steps:
cluster_profile: aws-2
env:
BASE_DOMAIN: aws-2.ci.openshift.org
workflow: openshift-e2e-aws
- as: e2e-aws-techpreview
interval: 48h
steps:
cluster_profile: aws-2
env:
BASE_DOMAIN: aws-2.ci.openshift.org
workflow: openshift-e2e-aws-techpreview
zz_generated_metadata:
branch: master
org: openshift
repo: release
variant: ci-4.10
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
current_ocp_release=4.10
future_ocp_release=4.11
interval=168
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
releases:
initial:
candidate:
product: ocp
relative: 1
stream: ci
version: "4.10"
latest:
candidate:
product: ocp
stream: ci
version: "4.10"
resources:
'*':
requests:
cpu: 100m
memory: 200Mi
tests:
- as: e2e-aws
interval: 24h
steps:
cluster_profile: aws-2
env:
BASE_DOMAIN: aws-2.ci.openshift.org
workflow: openshift-e2e-aws
- as: e2e-aws-techpreview
interval: 48h
steps:
cluster_profile: aws-2
env:
BASE_DOMAIN: aws-2.ci.openshift.org
workflow: openshift-e2e-aws-techpreview
zz_generated_metadata:
branch: master
org: openshift
repo: release
variant: ci-4.10
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
releases:
initial:
candidate:
product: ocp
relative: 1
stream: ci
version: "4.11"
latest:
candidate:
product: ocp
stream: ci
version: "4.11"
resources:
'*':
requests:
cpu: 100m
memory: 200Mi
tests:
- as: e2e-aws
interval: 168h
steps:
cluster_profile: aws-2
env:
BASE_DOMAIN: aws-2.ci.openshift.org
workflow: openshift-e2e-aws
- as: e2e-aws-techpreview
interval: 168h
steps:
cluster_profile: aws-2
env:
BASE_DOMAIN: aws-2.ci.openshift.org
workflow: openshift-e2e-aws-techpreview
zz_generated_metadata:
branch: master
org: openshift
repo: release
variant: ci-4.11

0 comments on commit 005d338

Please sign in to comment.