Skip to content

Commit

Permalink
test /etc/hosts aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
mixmix committed Oct 15, 2024
1 parent f436834 commit 3b3c766
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
41 changes: 41 additions & 0 deletions dev/bin/test-hosts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

# For local tests to work, we need to have aliases set up to point to 127.0.0.1
# see: dev/README.md

ALIASES=(
"alice-tss-server"
"bob-tss-server"
"charlie-tss-server"
"dave-tss-server"
)
EXPECTED_IP="127.0.0.1" # IP for localhost
ERROR=0

GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color

printf "
\e[4m/etc/hosts\e[0m
"

# Check each alias
for ALIAS in "${ALIASES[@]}"; do
resolved_ip=$(getent hosts "$ALIAS" | awk '{ print $1 }')

if [ "$resolved_ip" == "$EXPECTED_IP" ]; then
printf " ${GREEN}${NC} ${ALIAS}\n"
else
printf " ${RED}${ALIAS}${NC} is NOT aliased to localhost.\n"
ERROR=1
fi
done

echo ""

# Exit with an error code if any alias is incorrect
if [ $ERROR -ne 0 ]; then
exit 1
fi
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"build": "tsup",
"build:global": "tsup && npm install -g",
"lint": "eslint . --ext .ts --fix",
"test": "yarn test:types && yarn build:global && yarn test:ts && yarn test:only",
"test": "yarn test:types && yarn build:global && yarn test:hosts && yarn test:ts && yarn test:only",
"test:hosts": "./dev/bin/test-hosts.sh",
"test:only": "./dev/bin/test-only.sh",
"test:ts": "yarn removedb && ./dev/bin/test-ts.sh",
"test:types": "tsc --project tsconfig.json",
Expand Down

0 comments on commit 3b3c766

Please sign in to comment.