Last active
September 29, 2020 01:37
-
-
Save ilrudie/43823733444ba7976b2f567f30706620 to your computer and use it in GitHub Desktop.
Template script for pre/post/between scripting mechanism in the functional testing of rego in tmobile/magtape
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
#!/usr/bin/env bash | |
# Copyright 2020 T-Mobile, USA, Inc. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
# | |
# Trademark Disclaimer: Neither the name of T-Mobile, USA, Inc. nor the names of | |
# its contributors may be used to endorse or promote products derived from this | |
# software without specific prior written permission. | |
### Make a copy of this file and name it something meaningful. Copy the | |
### file into "testing/<resource>/scripts/<user_script>" | |
### and then reference that filename, not full path, the functional-tests.yaml | |
### manifest in order to run setup, teardown, and in between code required for | |
### your functional tests to work. | |
### Be a good neighbor and make sure you clean up after yourself in teardown so | |
### that your changes don't pollute the name space and impact other test that | |
### follow in the manifest. | |
################################################################################ | |
#### Variables, Arrays, and Hashes ############################################# | |
################################################################################ | |
ACTION="${1}" | |
NAME_SPACE="${2}" | |
################################################################################ | |
#### Functions ################################################################# | |
################################################################################ | |
# ********************************************** | |
# Check the argument being passed to script | |
# ********************************************** | |
help_message() { | |
echo "You need to specify the proper arguments:" | |
echo " Actions Type: (\"setup\", \"teardown\", or \"between\")" | |
echo " Test Namespace: (\"test1\")" | |
} | |
# ********************************************** | |
# Check the argument being passed to script | |
# ********************************************** | |
check_arguments() { | |
if [[ "${ACTION}" == "" ]] || [[ "${NAME_SPACE}" == "" ]]; then | |
help_message | |
exit 1 | |
elif [[ "${ACTION}" != "setup" ]] && [[ "${ACTION}" != "teardown" ]] && [[ "${ACTION}" != "between" ]] ; then | |
help_message | |
exit 1 | |
fi | |
} | |
# ********************************************** | |
# Run setup | |
# ********************************************** | |
run_setup() { | |
# local name space variable | |
local name_space="${1}" | |
# ********************************************** | |
# Place code to be run prior to processing the | |
# associated manifests here. | |
# ********************************************** | |
} | |
# ********************************************** | |
# Run teatdown | |
# ********************************************** | |
run_teardown() { | |
# local name space variable | |
local name_space="${1}" | |
# ********************************************** | |
# Place code to be run after processing the | |
# associated manifests here. | |
# ********************************************** | |
} | |
# ********************************************** | |
# Run in between | |
# ********************************************** | |
run_between() { | |
# local name space variable | |
local name_space="${1}" | |
# ********************************************** | |
# Place code to be run in between processing of | |
# each manifest here. | |
# ********************************************** | |
} | |
################################################################################ | |
#### Main ###################################################################### | |
################################################################################ | |
check_arguments | |
case ${ACTION} in | |
setup) | |
run_setup "${NAME_SPACE}" | |
;; | |
teardown) | |
run_teardown "${NAME_SPACE}" | |
;; | |
between) | |
run_between "${NAME_SPACE}" | |
;; | |
*) | |
help_message | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment