Skip to content

Commit

Permalink
Made a proper test suite out of integration tests (#40)
Browse files Browse the repository at this point in the history
* Made example.com a compliant URI

* Upgraded http_client_test so we can jam more tests into it easily

* shallow testing might fail if access/creation times are different
  • Loading branch information
Justin Boswell authored May 3, 2019
1 parent 8c70506 commit 8639fb1
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions integration-testing/http_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
import subprocess
import sys
import urllib.request
import unittest

elasticurl_path = sys.argv[1]
elasticurl_path = sys.argv.pop()
shell = sys.platform.startswith('win')

if elasticurl_path == None:
Expand All @@ -25,20 +26,27 @@
def run_command(args):
subprocess.check_call(args, shell=shell)


class SimpleTests(unittest.TestCase):
#make a simple GET request and make sure it succeeds
simple_get_args = [elasticurl_path, '-v', 'TRACE', 'example.com']
run_command(simple_get_args)
def test_simple_get(self):
simple_get_args = [elasticurl_path, '-v', 'TRACE', 'http://example.com']
run_command(simple_get_args)

#make a simple POST request to make sure sending data succeeds
simple_post_args = [elasticurl_path, '-v', 'TRACE', '-P', '-H', 'content-type: application/json', '-i', '-d', '\"{\'test\':\'testval\'}\"', 'http://httpbin.org/post']
run_command(simple_post_args)
def test_simple_post(self):
simple_post_args = [elasticurl_path, '-v', 'TRACE', '-P', '-H', 'content-type: application/json', '-i', '-d', '\"{\'test\':\'testval\'}\"', 'http://httpbin.org/post']
run_command(simple_post_args)

#download a large file and compare the results with something we assume works (e.g. urllib)
elasticurl_download_args = [elasticurl_path, '-v', 'TRACE', '-o', 'elastigirl.png', 'https://s3.amazonaws.com/code-sharing-aws-crt/elastigirl.png']
run_command(elasticurl_download_args)
def test_simple_download(self):
elasticurl_download_args = [elasticurl_path, '-v', 'TRACE', '-o', 'elastigirl.png', 'https://s3.amazonaws.com/code-sharing-aws-crt/elastigirl.png']
run_command(elasticurl_download_args)

urllib.request.urlretrieve('https://s3.amazonaws.com/code-sharing-aws-crt/elastigirl.png', 'elastigirl_expected.png')
urllib.request.urlretrieve('https://s3.amazonaws.com/code-sharing-aws-crt/elastigirl.png', 'elastigirl_expected.png')

if not filecmp.cmp('elastigirl.png', 'elastigirl_expected.png'):
print('downloaded files do not match, exiting with error....')
sys.exit(-1)
if not filecmp.cmp('elastigirl.png', 'elastigirl_expected.png', shallow=False):
raise RuntimeError('downloaded files do not match')

if __name__ == '__main__':
unittest.main()

0 comments on commit 8639fb1

Please sign in to comment.