Got a testing library setup to show that all parts are working

This commit is contained in:
Tristan Ancelet 2023-11-12 18:08:22 -06:00
parent 77d8e3dd7c
commit 788f4c6173
3 changed files with 87 additions and 1 deletions

40
utils/pools.sh Executable file
View File

@ -0,0 +1,40 @@
#!/bin/bash
get_pool_declerations () {
local SECTION_CONTENT SECTION_NAME
local -n ARRAY="${1:?"get_pool_declerations: Array was not provided"}"
local CONTENT="${2:?"get_pool_declerations: Content to be parsed was not provided"}"
get_sections $POOL_BEGIN_REGEX ARRAY "$CONTENT"
}
get_pool_ranges () {
local -n ARRAY="${1:?"get_pool_range: Variable not passed in"}"
local CONTENT="${2:?"get_pool_range: Content not provided"}"
while read line; do
RANGE="${line/range /}"
RANGE="${RANGE/;/}"
ARRAY+=( "$RANGE" )
done <<< "$( grep -Eo $POOL_RANGE_REGEX <<< "$CONTENT" )"
}
test_pools () {
local -a POOLS
local CONTENT="${1:?"test_pools: Content not provided"}"
get_pool_declerations POOLS "$CONTENT"
for pool in ${!POOLS[@]}; do
echo "POOL: $pool"
POOL_CONTENT="${POOLS[$pool]}"
local -a RANGES
get_pool_ranges RANGES "$POOL_CONTENT"
for range in ${!RANGES[@]}; do
echo " RANGE: ${RANGES[$range]}"
done
unset RANGES
done
}

View File

@ -12,6 +12,6 @@ get_subnet_declerations () {
for i in ${!SECTIONS[@]}; do for i in ${!SECTIONS[@]}; do
SECTION_CONTENT="${SECTIONS[$i]}" SECTION_CONTENT="${SECTIONS[$i]}"
SECTION_NAME=`grep -Eo $IP_REGEX <<< "$SECTION_CONTENT" | head -n 1` SECTION_NAME=`grep -Eo $IP_REGEX <<< "$SECTION_CONTENT" | head -n 1`
HASH_TABLE["$SECTION_NAME"]="${SECTION_CONTENT}" HASH_TABLE["$SECTION_NAME"]="$SECTION_CONTENT"
done done
} }

46
utils/test.sh Normal file
View File

@ -0,0 +1,46 @@
#!/bin/bash
test_all () {
local -A SHARED_NETWORKS
get_shared_network_declarations SHARED_NETWORKS "$CONTENTS"
for network in "${!SHARED_NETWORKS[@]}"; do
echo "Network: $network"
NETWORK_CONTENTS="${SHARED_NETWORKS[$network]}"
local -A SUBNETS
get_subnet_declerations SUBNETS "$NETWORK_CONTENTS"
for subnet in "${!SUBNETS[@]}"; do
SUBNET_CONTENTS="${SUBNETS[$subnet]}"
echo " SUBNET: $subnet"
local -a POOLS
get_pool_declerations POOLS "$SUBNET_CONTENTS"
for pool in ${!POOLS[@]}; do
POOL_CONTENT="${POOLS[$pool]}"
echo " POOL: $pool"
local -a RANGES
get_pool_ranges RANGES "$POOL_CONTENT"
for range in ${!RANGES[@]}; do
RANGE="${RANGES[$range]}"
echo " RANGE: $RANGE"
done
unset RANGES
done
local -A HOSTS
get_host_declerations HOSTS "$SUBNET_CONTENTS"
for host in ${!HOSTS[@]}; do
echo " HOST: $host"
done
unset POOLS
unset HOSTS
done
unset SUBNETS
done
unset SHARED_NETWORKS
}