Skip to content

Commit

Permalink
Merge pull request #59 from PelionIoT/fix
Browse files Browse the repository at this point in the history
Handle the wrong parameter passing - set -e
  • Loading branch information
jenia81 authored May 15, 2024
2 parents 0ff4151 + 381950d commit 425bd54
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions fw-tools/edge-testnet
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
# allows you to use port 443 as well.
# - k8s and gateway service is available only via port 443.
#
set -eu

DEBUG=0
FAILURES=0
TEST_UDP=0
SKIP_CERT_VALID=0
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CRED_DIR="$SCRIPT_DIR/credentials"
temp=$(mktemp -d /tmp/IzumaNetTest-XXXXX)
Expand Down Expand Up @@ -224,7 +228,7 @@ test_L3() {

# Check if we're running as a snap or not and change port accordingly.
# If env variable SNAP exists, we're running as SNAP.
if [[ -n "${SNAP}" ]]; then
if [[ -n "${SNAP+x}" ]]; then
verbose "Test Layer 3 for snapcraft.io"
_url api.snapcraft.io
_url canonical-lgw01.cdn.snapcraftcontent.com
Expand Down Expand Up @@ -265,12 +269,12 @@ test_L4() {
verbose "--------------------------"

_nc_test_server_tcp_udp bootstrap
_nc_test_server_tcp_udp lwm2m
_nc_test_server_tcp_udp lwm2m

_nc edge-k8s"$DOMAIN_NAME_EDGE" 443
_nc gateways"$DOMAIN_NAME_EDGE" 443
_nc containers"$DOMAIN_NAME_EDGE" 443
if [[ -n "${SNAP}" ]]; then
if [[ -n "${SNAP+x}" ]]; then
# https://snapcraft.io/docs/network-requirements
_nc api.snapcraft.io 443
_nc dashboard.snapcraft.io 443
Expand Down Expand Up @@ -316,7 +320,7 @@ main() {
test_L3
fi

busyboxnc=$(nc 2>&1)
busyboxnc=$(nc -help 2>&1) || true
if [[ "$busyboxnc" =~ "BusyBox" ]]; then
echo "BusyBox netcat detected, skipping Layer 4 tests"
else
Expand Down Expand Up @@ -383,8 +387,9 @@ argprocessor() {
--domain) DOMAIN_NAME="$2"; shift 2 ;;
#
--) shift; break ;;
#
*) >&2 echo Unsupported option: "$1"
usage ;;
usage ;;
esac
done

Expand All @@ -393,19 +398,25 @@ argprocessor() {
set -x
fi

# Check if either --env or --domain arguments were provided
if [[ -z "$ENV" && -z "$DOMAIN_NAME" ]]; then
# If neither --env or --domain arguments are provided
# The ENV is set to production.
if [[ -z "${ENV+x}" && -z "${DOMAIN_NAME+x}" ]]; then
echo "The env will be set to production."
ENV="production"
elif [[ -n "$ENV" && -n "$DOMAIN_NAME" ]]; then
elif [[ -n "${ENV+x}" && -n "${DOMAIN_NAME+x}" ]]; then
echo "Both --env or --domain argument were supplied."
echo "Only one of them must be supplied"
usage
exit 1
fi

# If the DOMAIN_NAME was supplied then it's a sandbox
if [[ -n "${DOMAIN_NAME+x}" ]]; then
DOMAIN_NAME_EDGE="$DOMAIN_NAME"
fi

# Check if --env is integration/os2/production.
if [[ -n "$ENV" ]]; then
if [[ -n "${ENV+x}" ]]; then
if [[ "$ENV" == "integration" ]]; then
DOMAIN_NAME="-integration-lab.mbedcloudintegration.net"
DOMAIN_NAME_EDGE=".mbedcloudintegration.net"
Expand All @@ -422,10 +433,6 @@ argprocessor() {
fi
fi

if [[ -n "$DOMAIN_NAME" ]]; then
DOMAIN_NAME_EDGE="$DOMAIN_NAME"
fi

main "$@"
}
argprocessor "$@"

0 comments on commit 425bd54

Please sign in to comment.