Skip to content

Commit

Permalink
Merge pull request #294 from junpataleta/validateContinuousReleaseDate
Browse files Browse the repository at this point in the history
Validate release date on continuous queues manager
  • Loading branch information
stronk7 authored Mar 13, 2024
2 parents 8399dca + fc09900 commit ca456fc
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 12 deletions.
88 changes: 88 additions & 0 deletions tests/3-continuous_manage_queues_validation.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/env bats

load libs/shared_setup

setup () {
export WORKSPACE=$gitdir

# Some dummy variables just for the sake of the letting the script proceed through the validation.
export jiraclicmd=jiracli
export jiraserver=https://tracker.moodle.org
export jirauser=jirauser
export jirapass=jirapass
}

@test "tracker_automations/continuous_manage_queues/continuous_manage_queues.sh: Current date < release date" {
releasedate=$(date -d "+10day" +%Y-%m-%d)
lastweekdate=$(date -d "${releasedate} -7day" +%Y-%m-%d)

source $PWD/tracker_automations/continuous_manage_queues/lib.sh

run run_param_validation $releasedate $lastweekdate

# Assert result.
assert_success
assert_output --partial "Parameters validated"
}

@test "tracker_automations/continuous_manage_queues/continuous_manage_queues.sh: Current date = on-sync date" {
releasedate=$(date -d "-28day" +%Y-%m-%d)
lastweekdate=$(date -d "${releasedate} -7day" +%Y-%m-%d)

source $PWD/tracker_automations/continuous_manage_queues/lib.sh

run run_param_validation $releasedate $lastweekdate

# Assert result.
assert_success
assert_output --partial "Parameters validated"
}

@test "tracker_automations/continuous_manage_queues/continuous_manage_queues.sh: Current date > on-sync date" {
releasedate=$(date -d "-29day" +%Y-%m-%d)
lastweekdate=$(date -d "${releasedate} -7day" +%Y-%m-%d)

source $PWD/tracker_automations/continuous_manage_queues/lib.sh

run run_param_validation $releasedate $lastweekdate

# Assert result.
assert_failure
assert_output --partial "ERROR: The current date is already past the on-sync period. Please make sure the Release date (${releasedate}) is configured correctly"
}

@test "tracker_automations/continuous_manage_queues/continuous_manage_queues.sh: Invalid release date format" {
releasedate=$(date +%m-%d-%Y)
lastweekdate=$(date +%Y-%m-%d)
source $PWD/tracker_automations/continuous_manage_queues/lib.sh

run run_param_validation $releasedate $lastweekdate

# Assert result.
assert_failure
assert_output --partial "ERROR: \$releasedate. Incorrect YYYY-MM-DD format detected: ${releasedate}"
}

@test "tracker_automations/continuous_manage_queues/continuous_manage_queues.sh: Invalid last week date format" {
releasedate=$(date -d "+7day" +%Y-%m-%d)
lastweekdate=$(date +%m-%d-%Y)
source $PWD/tracker_automations/continuous_manage_queues/lib.sh

run run_param_validation $releasedate $lastweekdate

# Assert result.
assert_failure
assert_output --partial "ERROR: \$lastweekdate. Incorrect YYYY-MM-DD format detected: ${lastweekdate}"
}

@test "tracker_automations/continuous_manage_queues/continuous_manage_queues.sh: Last week date is after the release date" {
releasedate=$(date -d "+7day" +%Y-%m-%d)
lastweekdate=$(date -d "+8day" +%Y-%m-%d)
source $PWD/tracker_automations/continuous_manage_queues/lib.sh

run run_param_validation $releasedate $lastweekdate

# Assert result.
assert_failure
assert_output --partial "ERROR: The value set for \$lastweekdate ($lastweekdate) is after the \$releasedate ($releasedate)"
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,11 @@ movemax=${movemax:-3}
lastweekdate=${lastweekdate:-$(date -d "${releasedate} -7day" +%Y-%m-%d)}
dryrun=${dryrun:-}

# Verify that $releasedata has a correct YYYY-MM-DD format
if [[ ! ${releasedate} =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
echo "ERROR: \$releasedate. Incorrect YYYY-MM-DD format detected: ${releasedate}"
exit 1
fi

# Verify that $lastweekdate has a correct YYYY-MM-DD format
if [[ ! ${lastweekdate} =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
echo "ERROR: \$lastweekdate. Incorrect YYYY-MM-DD format detected: ${lastweekdate}"
exit 1
fi

# Today
nowdate=$(date +%Y%m%d)

run_param_validation $releasedate $lastweekdate

# Decide if we are going to proceed with behaviour A (before release) or behaviour B (after release)
behaviorAB=
if [ $nowdate -lt $(date -d "${releasedate}" +%Y%m%d) ]; then
Expand Down
35 changes: 35 additions & 0 deletions tracker_automations/continuous_manage_queues/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,38 @@ function run_C() {
echo "$BUILD_NUMBER $BUILD_TIMESTAMP ${issue} moved out from current: held" >> "${logfile}"
done
}

function run_param_validation() {
releasedate=$1
lastweekdate=$2

# Verify that $releasedate has a correct YYYY-MM-DD format
if [[ ! ${releasedate} =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
echo "ERROR: \$releasedate. Incorrect YYYY-MM-DD format detected: ${releasedate}"
exit 1
fi

# Verify that $lastweekdate has a correct YYYY-MM-DD format
if [[ ! ${lastweekdate} =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
echo "ERROR: \$lastweekdate. Incorrect YYYY-MM-DD format detected: ${lastweekdate}"
exit 1
fi

# Verify that the last week date is not after the release date.
releasedateint=$(date -d "${releasedate}" +%Y%m%d)
lastweekdateint=$(date -d "${lastweekdate}" +%Y%m%d)
if [ $releasedateint -lt $lastweekdateint ]; then
echo "ERROR: The value set for \$lastweekdate ($lastweekdate) is after the \$releasedate ($releasedate)"
exit 1
fi

# Verify that the current date is not well past the on-sync period. (Normally 2 weeks but making it 4 weeks just in case).
nowdate=$(date +%Y%m%d)
onsyncenddate=$(date -d "${releasedate} +28day" +%Y%m%d)
if [ $nowdate -gt $onsyncenddate ]; then
echo "ERROR: The current date is already past the on-sync period. Please make sure the Release date ($releasedate) is configured correctly"
exit 1
fi

echo "Parameters validated"
}

0 comments on commit ca456fc

Please sign in to comment.