Created
November 5, 2013 20:24
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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