-
Notifications
You must be signed in to change notification settings - Fork 16
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
1 parent
4410a26
commit 84ede2c
Showing
3 changed files
with
107 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,6 @@ language: clojure | |
jdk: | ||
- oraclejdk9 | ||
- oraclejdk10 | ||
|
||
after_success: | ||
- python3 integration-tests/run.py |
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,15 @@ | ||
{ | ||
"host": "localhost", | ||
"port": 7777, | ||
"protocol": "http", | ||
"tests": [ | ||
{ | ||
"name": "Status Check", | ||
"path": "/api/can-we-build-it", | ||
"method": "GET", | ||
"response": { | ||
"message": "Yes we can! 🔨 🔨" | ||
} | ||
} | ||
] | ||
} |
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,89 @@ | ||
#!/usr/bin/python3 | ||
|
||
# This file is part of Bob. | ||
# | ||
# Bob is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Bob is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with Bob. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import json | ||
import subprocess | ||
from urllib import request | ||
from urllib.error import URLError | ||
from urllib.parse import urljoin | ||
|
||
import time | ||
|
||
with open("integration-tests/config.json") as json_data: | ||
CONFIG = json.load(json_data) | ||
|
||
BASE_URL = "{}://{}:{}".format( | ||
CONFIG["protocol"], CONFIG["host"], CONFIG["port"] | ||
) | ||
|
||
|
||
def start_bob(): | ||
# TODO: Store PID and kill it post test. | ||
|
||
subprocess.Popen(["lein", "run"]) | ||
print("Started bob.") | ||
|
||
|
||
def wait_for_it(): | ||
# TODO: HORRIBLE way to wait. Please improve. | ||
|
||
while True: | ||
try: | ||
req = request.Request(BASE_URL) | ||
|
||
with request.urlopen(req) as _: | ||
pass | ||
except (ConnectionRefusedError, URLError): | ||
print("Waiting for bob at {}".format(BASE_URL)) | ||
time.sleep(1) | ||
|
||
continue | ||
|
||
break | ||
|
||
|
||
def run_tests(): | ||
for test in CONFIG["tests"]: | ||
print("Testing {}.".format(test["name"])) | ||
|
||
url = urljoin(BASE_URL, test["path"]) | ||
|
||
if test["method"] == "GET": | ||
req = request.Request(url) | ||
|
||
with request.urlopen(req) as res: | ||
expected = json.loads(res.read().decode("utf-8")) | ||
|
||
assert expected == test["response"] | ||
else: | ||
raise Exception( | ||
"Unknown method {} at test {}.".format( | ||
test["method"], test["name"] | ||
) | ||
) | ||
|
||
print("{} passed.".format(test["name"])) | ||
|
||
|
||
if __name__ == "__main__": | ||
start_bob() | ||
|
||
wait_for_it() | ||
|
||
run_tests() | ||
|
||
print("All checks passed!") |
84ede2c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closes #3