diff --git a/tests/access.ut b/tests/access.ut new file mode 100755 index 0000000..400d575 --- /dev/null +++ b/tests/access.ut @@ -0,0 +1,87 @@ +# OpenLAN Access UT. + +source $PWD/macro.ut + +function setup() { + docker network inspect net1 || { + docker network create net1 \ + --driver=bridge --subnet=172.255.0.0/24 --gateway=172.255.0.1 + } + + mkdir -p /opt/openlan/sw1 + mkdir -p /opt/openlan/sw1/etc/openlan/switch + cat > /opt/openlan/sw1/etc/openlan/switch/switch.yaml < /opt/openlan/sw1/etc/openlan/access/t1.yaml < /opt/openlan/sw1/etc/openlan/access/t2.yaml <> $out + done +} + +function wait() { + set +x + local cmd=$1; local match=$2 + local count=$3; local code=1 + local out=/tmp/wait.1 + + if [[ $count == "" ]]; then + count=3 + fi + + $cmd 2>&1 | flush $out & disown + local pid=$! + + for i in $(seq 1 $count); do + if [ ! -e $out ]; then + sleep 1 + continue + fi + if cat $out | grep "$match"; then + code=0; break + fi + if ! ps -p $pid > /dev/null; then + break + fi + sleep 1 + done + + if ps -p $pid > /dev/null; then + kill $pid; + fi + rm -f $out + set -x + return $code +} + +function pause() { + echo "Press ENTER to continue: " + read +} + +export VERSION=$(version) +export IMAGE="luscis/openlan:$VERSION.$ARCH.deb" \ No newline at end of file diff --git a/tests/run.sh b/tests/run.sh new file mode 100755 index 0000000..6f52eff --- /dev/null +++ b/tests/run.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -ex + +pushd $(dirname $0) + +source access.ut +source switch.ut + +popd \ No newline at end of file diff --git a/tests/switch.ut b/tests/switch.ut new file mode 100644 index 0000000..19f42a3 --- /dev/null +++ b/tests/switch.ut @@ -0,0 +1,3 @@ +# OpenLAN Switch UT + +source $PWD/macro.ut