Skip to content

Commit 3af1084

Browse files
committed
Add CI tests
1 parent a0c4caf commit 3af1084

File tree

6 files changed

+324
-1
lines changed

6 files changed

+324
-1
lines changed

.github/workflows/MiniPlex.yml

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,60 @@ jobs:
5858
README.md
5959
RELEASE_NOTES
6060
3rdPartyLicenses/LICENSE_1_0.txt
61+
62+
- if: contains(matrix.os,'windows')
63+
name: Start Windows MiniPlex
64+
run: |
65+
start /b ${{github.workspace}}/build/**/MiniPlex.exe -H -p 20000
66+
start /b ${{github.workspace}}/build/**/MiniPlex.exe -T -p 20001 -r 172.17.0.2 -t 50000
67+
start /b ${{github.workspace}}/build/**/MiniPlex.exe -P -p 20002 -r 172.17.0.2 -t 50000
68+
start /b ${{github.workspace}}/build/**/MiniPlex.exe -P -p 20003 -r 172.17.0.2 -t 50000 -B 172.17.0.2 -b 50001
69+
70+
- if: !contains(matrix.os,'windows')
71+
name: Start MiniPlex
72+
run: |
73+
${{github.workspace}}/build/MiniPlex -H -p 20000 &
74+
${{github.workspace}}/build/MiniPlex -T -p 20001 -r 172.17.0.2 -t 50000 &
75+
${{github.workspace}}/build/MiniPlex -P -p 20002 -r 172.17.0.2 -t 50000 &
76+
${{github.workspace}}/build/MiniPlex -P -p 20003 -r 172.17.0.2 -t 50000 -B 172.17.0.2 -b 50001 &
77+
78+
- if: always()
79+
name: Test Hub Mode
80+
shell: bash
81+
run: |
82+
docker build --build-arg SCRIPT_NAME=Test/HubMode.sh -t miniplex-test -f DockerFiles/Test .
83+
docker run --add-host=host.docker.internal:host-gateway miniplex-test host.docker.internal 20000
84+
85+
- if: always()
86+
name: Test Trunk Mode
87+
shell: bash
88+
run: |
89+
docker build --build-arg SCRIPT_NAME=Test/TrunkMode.sh -t miniplex-test -f DockerFiles/Test .
90+
docker run --add-host=host.docker.internal:host-gateway miniplex-test 50000 host.docker.internal 20001
91+
92+
- if: always()
93+
name: Test Prune Mode
94+
shell: bash
95+
run: |
96+
docker build --build-arg SCRIPT_NAME=Test/PruneMode.sh -t miniplex-test -f DockerFiles/Test .
97+
docker run --add-host=host.docker.internal:host-gateway miniplex-test 50000 host.docker.internal 20002
98+
99+
- if: always()
100+
name: Test Permanent Branches
101+
shell: bash
102+
run: |
103+
docker build --build-arg SCRIPT_NAME=Test/PermanentBranches.sh -t miniplex-test -f DockerFiles/Test .
104+
docker run --add-host=host.docker.internal:host-gateway miniplex-test 50000 50001 host.docker.internal 20003
105+
106+
- if: contains(matrix.os,'windows')
107+
name: Stop Windows MiniPlex
108+
run: |
109+
taskkill /F /IM "MiniPlex.exe"
110+
111+
- if: !contains(matrix.os,'windows')
112+
name: Stop MiniPlex
113+
run: |
114+
killall MiniPlex || true
61115
62116
musl-build-job:
63117
name: linux-static ${{matrix.build-type}}
@@ -138,7 +192,7 @@ jobs:
138192

139193
clean-job:
140194
if: always()
141-
needs: [build-job]
195+
needs: [build-job,musl-build-job]
142196
runs-on: ubuntu-latest
143197
steps:
144198
- name: Remove old artifacts

DockerFiles/Test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM alpine:latest
2+
3+
ARG SCRIPT_NAME=
4+
5+
RUN apk add --no-cache bash nmap-ncat
6+
7+
WORKDIR /app
8+
9+
COPY ${SCRIPT_NAME} /app/test_script.sh
10+
11+
RUN chmod +x /app/test_script.sh
12+
13+
ENTRYPOINT ["/app/test_script.sh"]
14+

Test/HubMode.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
3+
#Test MiniPlex 'Hub' mode
4+
5+
#Usage: <this_script> <MiniPlex host> <MiniPlex port>
6+
7+
# Check if host and port are provided
8+
if [ $# -ne 2 ]; then
9+
echo "Error: Please provide host and port arguments"
10+
echo "Usage: $0 <MiniPlex host> <MiniPlex port>"
11+
exit 1
12+
fi
13+
14+
# Execute ncat commands and capture output
15+
exec 3< <((echo -n 3 && sleep 1 && echo -n 3 && sleep 1) | ncat -u $1 $2)
16+
sleep 0.1
17+
exec 4< <((echo -n 4 && sleep 2) | ncat -u $1 $2)
18+
sleep 0.1
19+
exec 5< <((echo -n 5 && sleep 2) | ncat -u $1 $2)
20+
sleep 0.1
21+
exec 6< <((echo -n 6 && sleep 2) | ncat -u $1 $2)
22+
sleep 0.1
23+
24+
# Read outputs
25+
OUT3=$(cat <&3)
26+
OUT4=$(cat <&4)
27+
OUT5=$(cat <&5)
28+
OUT6=$(cat <&6)
29+
30+
echo "Got here"
31+
32+
# Initialize error flag
33+
ERROR_FOUND=0
34+
35+
# Check OUT3
36+
if [ "$OUT3" != "456" ]; then
37+
echo "Error: OUT3 expected '456', got '$OUT3'"
38+
ERROR_FOUND=1
39+
fi
40+
41+
# Check OUT4
42+
if [ "$OUT4" != "563" ]; then
43+
echo "Error: OUT4 expected '563', got '$OUT4'"
44+
ERROR_FOUND=1
45+
fi
46+
47+
# Check OUT5
48+
if [ "$OUT5" != "63" ]; then
49+
echo "Error: OUT5 expected '63', got '$OUT5'"
50+
ERROR_FOUND=1
51+
fi
52+
53+
# Check OUT6
54+
if [ "$OUT6" != "3" ]; then
55+
echo "Error: OUT6 expected '3', got '$OUT6'"
56+
ERROR_FOUND=1
57+
fi
58+
59+
# Exit with appropriate status
60+
if [ $ERROR_FOUND -eq 1 ]; then
61+
exit 1
62+
else
63+
echo "All tests passed."
64+
exit 0
65+
fi

Test/PermanentBranches.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
3+
#Test MiniPlex permanent branches
4+
# Same as prune mode, except the trunk speaks first, to prove the perm branch still gets it
5+
6+
#Usage: <this_script> <MiniPlex trunk port> <MiniPlex perm port> <MiniPlex host> <MiniPlex port>
7+
8+
# Check if host and port are provided
9+
if [ $# -ne 4 ]; then
10+
echo "Error: Please provide trunk-port perm-port host and port arguments"
11+
echo "Usage: $0 <MiniPlex trunk port> <MiniPlex perm port> <MiniPlex host> <MiniPlex port>"
12+
exit 1
13+
fi
14+
15+
# Execute ncat commands and capture output
16+
exec 3< <((sleep 1 && echo -n 3 && sleep 2) | ncat -u -p $1 $3 $4)
17+
sleep 0.1
18+
exec 4< <((sleep 1.5 && echo -n 4 && sleep 1.5) | ncat -u -p $2 $3 $4)
19+
sleep 0.1
20+
exec 5< <((sleep 2 && echo -n 5 && sleep 1) | ncat -u $3 $4)
21+
sleep 0.1
22+
exec 6< <((sleep 2 && echo -n 6 && sleep 1) | ncat -u $3 $4)
23+
sleep 0.1
24+
25+
# Read outputs
26+
OUT3=$(cat <&3)
27+
OUT4=$(cat <&4)
28+
OUT5=$(cat <&5)
29+
OUT6=$(cat <&6)
30+
31+
# Initialize error flag
32+
ERROR_FOUND=0
33+
34+
# Check OUT3
35+
if [ "$OUT3" != "4" ]; then
36+
echo "Error: OUT3 expected '4', got '$OUT3'"
37+
ERROR_FOUND=1
38+
fi
39+
40+
# Check OUT4
41+
if [ "$OUT4" != "3" ]; then
42+
echo "Error: OUT4 expected '3', got '$OUT4'"
43+
ERROR_FOUND=1
44+
fi
45+
46+
# Check OUT5
47+
if [ "$OUT5" != "" ]; then
48+
echo "Error: OUT5 expected '', got '$OUT5'"
49+
ERROR_FOUND=1
50+
fi
51+
52+
# Check OUT6
53+
if [ "$OUT6" != "" ]; then
54+
echo "Error: OUT6 expected '', got '$OUT6'"
55+
ERROR_FOUND=1
56+
fi
57+
58+
# Exit with appropriate status
59+
if [ $ERROR_FOUND -eq 1 ]; then
60+
exit 1
61+
else
62+
echo "All tests passed."
63+
exit 0
64+
fi

Test/PruneMode.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
3+
#Test MiniPlex 'Prune' mode
4+
5+
#Usage: <this_script> <MiniPlex trunk port> <MiniPlex host> <MiniPlex port>
6+
7+
# Check if host and port are provided
8+
if [ $# -ne 3 ]; then
9+
echo "Error: Please provide trunk-port host and port arguments"
10+
echo "Usage: $0 <MiniPlex trunk port> <MiniPlex host> <MiniPlex port>"
11+
exit 1
12+
fi
13+
14+
# Execute ncat commands and capture output
15+
exec 3< <((echo -n 3 && sleep 1 && echo -n 3 && sleep 1) | ncat -u -p $1 $2 $3)
16+
sleep 0.1
17+
exec 4< <((echo -n 4 && sleep 2) | ncat -u $2 $3)
18+
sleep 0.1
19+
exec 5< <((echo -n 5 && sleep 2) | ncat -u $2 $3)
20+
sleep 0.1
21+
exec 6< <((echo -n 6 && sleep 2) | ncat -u $2 $3)
22+
sleep 0.1
23+
24+
# Read outputs
25+
OUT3=$(cat <&3)
26+
OUT4=$(cat <&4)
27+
OUT5=$(cat <&5)
28+
OUT6=$(cat <&6)
29+
30+
# Initialize error flag
31+
ERROR_FOUND=0
32+
33+
# Check OUT3
34+
if [ "$OUT3" != "4" ]; then
35+
echo "Error: OUT3 expected '4', got '$OUT3'"
36+
ERROR_FOUND=1
37+
fi
38+
39+
# Check OUT4
40+
if [ "$OUT4" != "3" ]; then
41+
echo "Error: OUT4 expected '3', got '$OUT4'"
42+
ERROR_FOUND=1
43+
fi
44+
45+
# Check OUT5
46+
if [ "$OUT5" != "" ]; then
47+
echo "Error: OUT5 expected '', got '$OUT5'"
48+
ERROR_FOUND=1
49+
fi
50+
51+
# Check OUT6
52+
if [ "$OUT6" != "" ]; then
53+
echo "Error: OUT6 expected '', got '$OUT6'"
54+
ERROR_FOUND=1
55+
fi
56+
57+
# Exit with appropriate status
58+
if [ $ERROR_FOUND -eq 1 ]; then
59+
exit 1
60+
else
61+
echo "All tests passed."
62+
exit 0
63+
fi

Test/TrunkMode.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
3+
#Test MiniPlex 'Trunk' mode
4+
5+
#Usage: <this_script> <MiniPlex trunk port> <MiniPlex host> <MiniPlex port>
6+
7+
# Check if host and port are provided
8+
if [ $# -ne 3 ]; then
9+
echo "Error: Please provide trunk-port host and port arguments"
10+
echo "Usage: $0 <MiniPlex trunk port> <MiniPlex host> <MiniPlex port>"
11+
exit 1
12+
fi
13+
14+
# Execute ncat commands and capture output
15+
exec 3< <((echo -n 3 && sleep 1 && echo -n 3 && sleep 1) | ncat -u -p $1 $2 $3)
16+
sleep 0.1
17+
exec 4< <((echo -n 4 && sleep 2) | ncat -u $2 $3)
18+
sleep 0.1
19+
exec 5< <((echo -n 5 && sleep 2) | ncat -u $2 $3)
20+
sleep 0.1
21+
exec 6< <((echo -n 6 && sleep 2) | ncat -u $2 $3)
22+
sleep 0.1
23+
24+
# Read outputs
25+
OUT3=$(cat <&3)
26+
OUT4=$(cat <&4)
27+
OUT5=$(cat <&5)
28+
OUT6=$(cat <&6)
29+
30+
# Initialize error flag
31+
ERROR_FOUND=0
32+
33+
# Check OUT3
34+
if [ "$OUT3" != "456" ]; then
35+
echo "Error: OUT3 expected '456', got '$OUT3'"
36+
ERROR_FOUND=1
37+
fi
38+
39+
# Check OUT4
40+
if [ "$OUT4" != "3" ]; then
41+
echo "Error: OUT4 expected '3', got '$OUT4'"
42+
ERROR_FOUND=1
43+
fi
44+
45+
# Check OUT5
46+
if [ "$OUT5" != "3" ]; then
47+
echo "Error: OUT5 expected '3', got '$OUT5'"
48+
ERROR_FOUND=1
49+
fi
50+
51+
# Check OUT6
52+
if [ "$OUT6" != "3" ]; then
53+
echo "Error: OUT6 expected '3', got '$OUT6'"
54+
ERROR_FOUND=1
55+
fi
56+
57+
# Exit with appropriate status
58+
if [ $ERROR_FOUND -eq 1 ]; then
59+
exit 1
60+
else
61+
echo "All tests passed."
62+
exit 0
63+
fi

0 commit comments

Comments
 (0)