Skip to content

Commit

Permalink
Add bats test scripts
Browse files Browse the repository at this point in the history
This adds `bats` versions of the old Aruba test scripts.
  • Loading branch information
NicMcPhee committed Oct 20, 2016
1 parent 8d3e94a commit 567255d
Showing 4 changed files with 175 additions and 15 deletions.
65 changes: 65 additions & 0 deletions test/Echo_client.bats
100644 → 100755
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bats

setup() {
BATS_TMPDIR=`mktemp --directory`
cd test/sampleBin
java echoserver.EchoServer &
cd ../..
}

teardown() {
rm -rf "$BATS_TMPDIR"
kill %1
# This sleep is crucial to ensure that the server shuts down completely
# and relinquishes the port before we move on to the next test.
sleep 1
}

@test "Your client code compiles" {
cd src
rm -f echoserver/EchoClient.class
run javac echoserver/EchoClient.java
cd ..
[ "$status" -eq 0 ]
}

@test "Your client runs successfully" {
cd src
java echoserver.EchoClient < ../test/etc/textTest.txt
status=$?
cd ..
[ "$status" -eq 0 ]
}

@test "Your client handles a small bit of text" {
cd src
rm -f echoserver/*.class
javac echoserver/EchoClient.java
java echoserver.EchoClient < ../test/etc/textTest.txt > "$BATS_TMPDIR"/textTest.txt
run diff ../test/etc/textTest.txt "$BATS_TMPDIR"/textTest.txt
cd ..

[ "$status" -eq 0 ]
}

@test "Your client handles a large chunk of text" {
cd src
rm -f echoserver/*.class
javac echoserver/EchoClient.java
java echoserver.EchoClient < ../test/etc/words.txt > "$BATS_TMPDIR"/words.txt
run diff ../test/etc/words.txt "$BATS_TMPDIR"/words.txt
cd ..

[ "$status" -eq 0 ]
}

@test "Your client handles binary content" {
cd src
rm -f echoserver/*.class
javac echoserver/EchoClient.java
java echoserver.EchoClient < ../test/etc/pumpkins.jpg > "$BATS_TMPDIR"/pumpkins.jpg
run diff ../test/etc/pumpkins.jpg "$BATS_TMPDIR"/pumpkins.jpg
cd ..

[ "$status" -eq 0 ]
}
Empty file removed test/Echo_client_and_server.bats
Empty file.
80 changes: 65 additions & 15 deletions test/Echo_server.bats
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,21 +1,71 @@
#!/usr/bin/env bats

Scenario: Sending text: premade client, your server
Given a server from "../bin/echoserver/EchoServer.class" and a client from "sampleBin/echoserver/EchoClient.class"
When I run the echo client with the file "etc/textTest.txt" outputting to "output.txt"
Then the file "output.txt" exists
And the file "output.txt" should differ from "etc/textTest.txt" only by whitespace

Scenario: Sending images: premade client, your server
Given a server from "../bin/echoserver/EchoServer.class" and a client from "sampleBin/echoserver/EchoClient.class"
When I run the echo client with the file "etc/pumpkins.jpg" outputting to "output.jpg"
Then the file "output.jpg" exists
And the file "output.jpg" should differ from "etc/pumpkins.jpg" only by whitespace

@setup {
mktemp
setup() {
BATS_TMPDIR=`mktemp --directory`
}

@test {
teardown() {
rm -rf "$BATS_TMPDIR"
}

@test "Your server code compiles" {
cd src
rm -f echoserver/EchoServer.class
run javac echoserver/EchoServer.java
cd ..
[ "$status" -eq 0 ]
}

@test "Your server starts successfully" {
cd src
java echoserver.EchoServer &
status=$?
kill %1
cd ..
[ "$status" -eq 0 ]
}

@test "Your server handles a small bit of text" {
cd src
rm -f echoserver/*.class
javac echoserver/EchoServer.java
java echoserver.EchoServer &
cd ..

cd test/sampleBin
java echoserver.EchoClient < ../etc/textTest.txt > "$BATS_TMPDIR"/textTest.txt
run diff ../etc/textTest.txt "$BATS_TMPDIR"/textTest.txt
cd ../..
kill %1
[ "$status" -eq 0 ]
}

@test "Your server handles a large chunk of text" {
cd src
rm -f echoserver/*.class
javac echoserver/EchoServer.java
java echoserver.EchoServer &
cd ..

cd test/sampleBin
java echoserver.EchoClient < ../etc/words.txt > "$BATS_TMPDIR"/words.txt
run diff ../etc/words.txt "$BATS_TMPDIR"/words.txt
cd ../..
kill %1
[ "$status" -eq 0 ]
}

@test "Your server handles binary content" {
cd src
rm -f echoserver/*.class
javac echoserver/EchoServer.java
java echoserver.EchoServer &
cd ..

cd test/sampleBin
java echoserver.EchoClient < ../etc/pumpkins.jpg > "$BATS_TMPDIR"/pumpkins.jpg
run diff ../etc/pumpkins.jpg "$BATS_TMPDIR"/pumpkins.jpg
cd ../..
kill %1
[ "$status" -eq 0 ]
}
45 changes: 45 additions & 0 deletions test/Echo_servers_and_client.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bats

setup() {
BATS_TMPDIR=`mktemp --directory`
cd src
rm -f echoserver/EchoServer.class
javac echoserver/*.java
java echoserver.EchoServer &
cd ..
}

teardown() {
rm -rf "$BATS_TMPDIR"
kill %1
# This sleep is crucial to ensure that the server shuts down completely
# and relinquishes the port before we move on to the next test.
sleep 1
}

@test "Your client/server pair handles a small bit of text" {
cd src
java echoserver.EchoClient < ../test/etc/textTest.txt > "$BATS_TMPDIR"/textTest.txt
run diff ../test/etc/textTest.txt "$BATS_TMPDIR"/textTest.txt
cd ..

[ "$status" -eq 0 ]
}

@test "Your client/server pair handles a large chunk of text" {
cd src
java echoserver.EchoClient < ../test/etc/words.txt > "$BATS_TMPDIR"/words.txt
run diff ../test/etc/words.txt "$BATS_TMPDIR"/words.txt
cd ..

[ "$status" -eq 0 ]
}

@test "Your client/server pair handles binary content" {
cd src
java echoserver.EchoClient < ../test/etc/pumpkins.jpg > "$BATS_TMPDIR"/pumpkins.jpg
run diff ../test/etc/pumpkins.jpg "$BATS_TMPDIR"/pumpkins.jpg
cd ..

[ "$status" -eq 0 ]
}

0 comments on commit 567255d

Please sign in to comment.