Skip to content
Snippets Groups Projects
Commit 0262dc9a authored by Joey Le's avatar Joey Le
Browse files
parents 11c1a99c 6ddb516a
Branches
No related tags found
No related merge requests found
File added
......@@ -4,6 +4,18 @@
#
# Create your unit tests suit in this file
start_server() {
./dsh -s -i 127.0.0.1 -p 5678 > /dev/null 2>&1 &
SERVER_PID=$!
sleep 1 # Give the server time to start
}
# Helper function to stop the server
stop_server() {
kill $SERVER_PID 2>/dev/null || true
wait $SERVER_PID 2>/dev/null || true
}
@test "Example: check ls runs without errors" {
run ./dsh <<EOF
ls
......@@ -12,3 +24,66 @@ EOF
# Assertions
[ "$status" -eq 0 ]
}
@test "Start server and client without errors" {
# Start the server
start_server
# Check if the server is running
run ps -p $SERVER_PID
[ "$status" -eq 0 ]
# Start the client and send a simple command
run ./dsh -c -i 127.0.0.1 -p 5678 <<EOF
echo Hello, World!
exit
EOF
# Assertions
[ "$status" -eq 0 ]
[[ "$output" == *"Hello, World!"* ]]
stop_server
}
@test "Server handles pipes" {
start_server
echo "testfile1" > testfile1.txt
echo "testfile2" >> testfile1.txt
run ./dsh -c -i 127.0.0.1 -p 5678 <<EOF
ls -1 | wc -l
exit
EOF
[ "$status" -eq 0 ]
[[ "$output" == *"2"* ]]
rm -f testfile1.txt
stop_server
}
@test "Stop server with stop-server command" {
start_server
run ps -p $SERVER_PID
[ "$status" -eq 0 ]
run ./dsh -c -i 127.0.0.1 -p 5678 <<EOF
stop-server
EOF
[ "$status" -eq 0 ]
sleep 1
run ps -p $SERVER_PID
[ "$status" -ne 0 ]
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment