Skip to content

Instantly share code, notes, and snippets.

@mikekwright
Created November 5, 2013 20:24
Show Gist options
  • Save mikekwright/7325587 to your computer and use it in GitHub Desktop.
Save mikekwright/7325587 to your computer and use it in GitHub Desktop.
This is the final gist that demonstrates the testing that can be accomplished using shunit from post (Bash Testing)
#!/bin/bash
setUp()
{
originalPath=$PATH
PATH=$PWD:$PATH
}
tearDown()
{
PATH=$originalPath
export TEST_WGET_FAILURE=
}
testFailsWhenArgumentNotSupplied()
{
./configRetriever.sh > /dev/null
returnCode=$?
assertEquals "Script should fail when no argument" 1 $returnCode
}
testFailsWhenwgetFails()
{
export TEST_WGET_FAILURE=1
./configRetriever.sh "testUrl" > /dev/null
returnCode=$?
assertEquals "Script should fail when wget fails" 2 $returnCode
}
testSuccessAllAround()
{
response=$(./configRetriever.sh "testUrl")
echo "$response" | grep -qE "Script was a success"
returnCode=$?
assertEquals "Script was not successful" 0 $returnCode
}
. shunit2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment