Skip to content

Commit

Permalink
end-to-end acceptance test.
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseshieh committed Apr 29, 2017
1 parent 0099e9b commit 9b62a6b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ If you don't have pip install, see https://pip.pypa.io/en/stable/installing/

## Testing

pip install -e .[dev]
python setup.py test

# e2e tests
pip install pytest
export GIGALIXIR_EMAIL=foo
export GIGALIXIR_PASSWORD=bar
pytest -s e2e/test.py

## Distribute

python setup.py sdist upload -r pypitest
Expand Down
64 changes: 64 additions & 0 deletions e2e/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# This Python file uses the following encoding: utf-8
import os
import time
import subprocess
import gigalixir
import click
from click.testing import CliRunner
import contextlib
import logging
import requests

def test_everything():
logging.basicConfig(format='%(message)s', level=logging.DEBUG)

email = os.environ['GIGALIXIR_EMAIL']
password = os.environ['GIGALIXIR_PASSWORD']
runner = CliRunner()

with runner.isolated_filesystem():
os.environ['HOME'] = os.getcwd()
result = runner.invoke(gigalixir.cli, ['login', '--email=%s' % email], input="%s\ny\n" % password)
assert result.exit_code == 0
gigalixir.shell.cast("git clone https://github.com/gigalixir/gigalixir-getting-started.git")
with cd("gigalixir-getting-started"):
result = runner.invoke(gigalixir.cli, ['create'])
assert result.exit_code == 0
app_name = result.output.rstrip()
gigalixir.shell.cast("git push gigalixir")
logging.info('Completed Deploy.')
url = 'https://%s.gigalixirapp.com/' % app_name
for i in range(30):
try:
logging.info('Attempt: %s/30: Checking %s' % (i, url))
r = requests.get(url)
if r.status_code != 200:
# wait 5 seconds
logging.info('Received %s' % r.status_code)
logging.info('Waiting 30 seconds to try again.')
time.sleep(30)
else:
logging.info('Pass.')
break
except requests.exceptions.ConnectionError as e:
# wait 5 seconds
logging.info('ConnectionError: %s' % e)
logging.info('Waiting 30 seconds to try again.')
time.sleep(30)
else:
logging.info('Exhausted retries.')
assert False

# TODO: scale down to 0
# TODO: delete?

@contextlib.contextmanager
def cd(newdir, cleanup=lambda: True):
prevdir = os.getcwd()
os.chdir(os.path.expanduser(newdir))
try:
yield
finally:
os.chdir(prevdir)
cleanup()

0 comments on commit 9b62a6b

Please sign in to comment.