-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
105 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package main | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
func main() { | ||
http.HandleFunc("/home", func(writer http.ResponseWriter, request *http.Request) {}) | ||
http.HandleFunc("/index", func(writer http.ResponseWriter, request *http.Request) {}) | ||
|
||
if err := http.ListenAndServe(":8080", nil); err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/usr/bin/env bash | ||
|
||
################################################################################################################ | ||
## The purpose of this script is to make sure dirstalk basic functionalities are working as expected | ||
################################################################################################################ | ||
|
||
################################### | ||
## function to assert that the given string contains the given substring | ||
## example usage: assert_contains "error" "my_special_error: blabla" "an error is expected for XY" | ||
################################### | ||
function assert_contains { | ||
local actual=$1 | ||
local contains=$2 | ||
local msg=$3 | ||
|
||
if ! echo "$actual" | grep "$contains" > /dev/null; then | ||
echo "ERROR: $msg" | ||
echo "Failed to assert that $actual contains $contains" | ||
exit 1; | ||
fi | ||
echo "Assertion passing" | ||
} | ||
|
||
################################### | ||
## function to assert that the given string does not contain the given substring | ||
## example usage: assert_contains "error" "my_special_error: blabla" "an error is expected for XY" | ||
################################### | ||
function assert_not_contains { | ||
local actual=$1 | ||
local contains=$2 | ||
local msg=$3 | ||
|
||
if ! echo "$actual" | grep -v "$contains" > /dev/null; then | ||
echo "ERROR: $msg" | ||
echo "Failed to assert that $actual does not contain $contains" | ||
exit 1; | ||
fi | ||
echo "Assertion passing" | ||
} | ||
|
||
## Starting test server running on the 8080 port | ||
echo "Starting test server" | ||
./dist/testserver& | ||
SERVER_PID=$! | ||
sleep 1 | ||
echo "Done" | ||
|
||
function finish { | ||
echo "Killing test server $SERVER_PID" | ||
kill -9 "$SERVER_PID" | ||
echo "Done" | ||
} | ||
trap finish EXIT | ||
|
||
## Tests | ||
|
||
VERSION_RESULT=$(./dist/dirstalk version 2>&1); | ||
assert_contains "$VERSION_RESULT" "Version" "the version is expected to be printed when calling the version command" | ||
assert_contains "$VERSION_RESULT" "Built" "the build time is expected to be printed when calling the version command" | ||
|
||
SCAN_RESULT=$(./dist/dirstalk scan 2>&1 || true); | ||
assert_contains "$SCAN_RESULT" "error" "an error is expected when no argument is passed" | ||
|
||
SCAN_RESULT=$(./dist/dirstalk scan -d resources/tests/dictionary.txt http://localhost:8080 2>&1 || true); | ||
assert_contains "$SCAN_RESULT" "/index" "result expected when performing scan" | ||
assert_contains "$SCAN_RESULT" "6 requests made, 2 results found" "a recap was expected when performing a scan" | ||
assert_not_contains "$SCAN_RESULT" "error" "no error is expected for a successful scan" | ||
|
||
|
||
DICTIONARY_GENERATE_RESULT=$(./dist/dirstalk dictionary.generate resources/tests 2>&1 || true); | ||
assert_contains "$DICTIONARY_GENERATE_RESULT" "dictionary.txt" "dictionary generation should contains a file in the folder" | ||
assert_not_contains "$DICTIONARY_GENERATE_RESULT" "error" "no error is expected when generating a dictionary successfully" | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
home | ||
index |