Skip to content

Commit 8639fb1

Browse files
author
Justin Boswell
authored
Made a proper test suite out of integration tests (#40)
* 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
1 parent 8c70506 commit 8639fb1

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

integration-testing/http_client_test.py

+19-11
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
import subprocess
1515
import sys
1616
import urllib.request
17+
import unittest
1718

18-
elasticurl_path = sys.argv[1]
19+
elasticurl_path = sys.argv.pop()
1920
shell = sys.platform.startswith('win')
2021

2122
if elasticurl_path == None:
@@ -25,20 +26,27 @@
2526
def run_command(args):
2627
subprocess.check_call(args, shell=shell)
2728

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

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

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

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

42-
if not filecmp.cmp('elastigirl.png', 'elastigirl_expected.png'):
43-
print('downloaded files do not match, exiting with error....')
44-
sys.exit(-1)
48+
if not filecmp.cmp('elastigirl.png', 'elastigirl_expected.png', shallow=False):
49+
raise RuntimeError('downloaded files do not match')
50+
51+
if __name__ == '__main__':
52+
unittest.main()

0 commit comments

Comments
 (0)