Rewrite the test suite for better compat and stability
[tinc] / test / invite-tinc-up.test
index 55123b8..6cf280b 100755 (executable)
@@ -1,59 +1,53 @@
 #!/bin/sh
 
+# shellcheck source=testlib.sh
 . "${0%/*}/testlib.sh"
 
-# Initialize one node
+echo [STEP] Initialize one node
 
-$tinc $c1 <<EOF
+tinc foo <<EOF
 init foo
 set DeviceType dummy
 set Address localhost
-set Port 32756
-start $r1
+set Port 30030
 EOF
 
-# Generate an invitation and let another node join the VPN
+create_script foo tinc-up
+start_tinc foo
+wait_script foo tinc-up
 
-sleep 1
+echo [STEP] Generate an invitation and let another node join the VPN
 
-cat >$d1/invitation-created <<EOF
-#!/bin/sh
-echo Name = \$NODE >\$INVITATION_FILE
-echo Ifconfig = 93.184.216.34/24 >>\$INVITATION_FILE
-echo Route = 2606:2800:220:1::/64 2606:2800:220:1:248:1893:25c8:1946 >>\$INVITATION_FILE
-echo Route = 1.2.3.4 1234:: >>\$INVITATION_FILE
-$tinc $c1 export >>\$INVITATION_FILE
-EOF
-
-cat >$d1/invitation-created.cmd <<EOF
-echo Name = %NODE% >%INVITATION_FILE%
-echo Ifconfig = 93.184.216.34/24 >>%INVITATION_FILE%
-echo Route = 2606:2800:220:1::/64 2606:2800:220:1:248:1893:25c8:1946 >>%INVITATION_FILE%
-echo Route = 1.2.3.4 1234:: >>%INVITATION_FILE%
-$tinc $c1 export >>%INVITATION_FILE%
-EOF
-
-chmod u+x $d1/invitation-created
+# shellcheck disable=SC2016
+create_script foo invitation-created '
+cat >"$INVITATION_FILE" <<INVITE
+Name = $NODE
+Ifconfig = 93.184.216.34/24
+Route = 2606:2800:220:1::/64 2606:2800:220:1:248:1893:25c8:1946
+Route = 1.2.3.4 1234::
 
-$tinc $c1 invite bar | tail -1 | $tinc $c2 --batch join
+$(tinc foo export)
+INVITE
+'
 
-# Test equivalence of host config files
+tinc foo invite bar | tail -1 | tinc bar --batch join
 
-cmp $d1/hosts/foo $d2/hosts/foo
-test "`grep ^Ed25519PublicKey $d1/hosts/bar`" = "`grep ^Ed25519PublicKey $d2/hosts/bar`"
+echo [STEP] Test equivalence of host config files
 
-# Check if the tinc-up.invitation file is created and contains the right commands
+diff -w "$DIR_FOO/hosts/foo" "$DIR_BAR/hosts/foo"
+test "$(grep ^Ed25519PublicKey "$DIR_FOO/hosts/bar")" = "$(grep ^Ed25519PublicKey "$DIR_BAR/hosts/bar")"
 
-test -f $d2/tinc-up.invitation
+echo [STEP] Check if the tinc-up.invitation file is created and contains the right commands
 
-fgrep -q "93.184.216.34/24" $d2/tinc-up.invitation
-fgrep -q "2606:2800:220:1::/64" $d2/tinc-up.invitation
-fgrep -q "2606:2800:220:1:248:1893:25c8:1946" $d2/tinc-up.invitation
-fgrep -q "1234::" $d2/tinc-up.invitation && exit 1
+bar_tinc_up="$DIR_BAR/tinc-up.invitation"
+test -f "$bar_tinc_up"
 
-# Check that no tinc-up is created and that tinc-up.invitation is not executable
+grep -F -q "93.184.216.34/24" "$bar_tinc_up"
+grep -F -q "2606:2800:220:1::/64" "$bar_tinc_up"
+grep -F -q "2606:2800:220:1:248:1893:25c8:1946" "$bar_tinc_up"
+must_fail grep -F -q "1234::" "$bar_tinc_up"
 
-test -x $d2/tinc-up.invitation && exit 1
-test -f $d2/tinc-up && exit 1
+echo [STEP] Check that no tinc-up is created and that tinc-up.invitation is not executable
 
-$tinc $c1 stop
+must_fail test -x "$bar_tinc_up"
+must_fail test -f "$DIR_BAR/tinc-up"