Skip to content

Commit 69a7b9a

Browse files
authored
Merge pull request #11 from controlplaneio/output-directory
feat: add results directory output options
2 parents 688ea49 + 6da94dd commit 69a7b9a

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

netassert

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
## --ssh-options Optional SSH options (for `ssh` and `gcloud compute ssh` commands)
1717
## --known-hosts A known_hosts file (default: ${HOME}/.ssh/known_hosts)
1818
##
19+
## --results-dir Directory to output results files (default: temporary directory)
20+
##
1921
## --verbose More output
2022
## --debug Debug output
2123
##
@@ -50,6 +52,7 @@ USER_KNOWN_HOSTS_FILE="${HOME}/.ssh/known_hosts"
5052
SSH_USER_OPTIONS=""
5153
SSH_DEFAULT_OPTIONS="-o ConnectTimeout=10 -o BatchMode=yes -o UserKnownHostsFile=\"${USER_KNOWN_HOSTS_FILE}\""
5254
TEMP_DIR=''
55+
RESULTS_DIR=''
5356
TEST_FAILURES=0
5457
TEST_TIMEOUT=120 # seconds, including the Docker image's initial pull
5558
IS_OFFLINE=0
@@ -71,7 +74,7 @@ main() {
7174

7275
verbose "${CONFIG}"
7376

74-
create_temp_dir
77+
create_results_dir
7578

7679
trap cleanup EXIT
7780

@@ -443,6 +446,8 @@ present_results() {
443446
fi 2>&1
444447
)
445448

449+
verbose "Results saved in: ${RESULTS_DIR}:"
450+
446451
echo "${OUTPUT_RESULT}"
447452

448453
echo "${OUTPUT_PASS}"
@@ -457,8 +462,14 @@ present_results() {
457462
fi
458463
}
459464

460-
create_temp_dir() {
461-
TEMP_DIR=$(mktemp -d) # shorthand for alpine/busybox compat
465+
create_results_dir() {
466+
if [[ "${RESULTS_DIR}" != "" ]]; then
467+
mkdir -p "${RESULTS_DIR}"
468+
TEMP_DIR="${RESULTS_DIR}"
469+
else
470+
TEMP_DIR=$(mktemp -d) # shorthand for alpine/busybox compat
471+
RESULTS_DIR="${TEMP_DIR}"
472+
fi
462473
}
463474

464475
jqc() {
@@ -532,6 +543,11 @@ parse_arguments() {
532543
not_empty_or_usage "${1:-}"
533544
SSH_USER_OPTIONS="${1}"
534545
;;
546+
--results-dir)
547+
shift
548+
not_empty_or_usage "${1:-}"
549+
RESULTS_DIR="${1}"
550+
;;
535551
--offline | --no-pull)
536552
IS_OFFLINE=1
537553
;;

0 commit comments

Comments
 (0)