Skip to content

Commit a6139b4

Browse files
author
Gabriel Monroy
committed
Merge pull request #378 from opdemand/example-apps-tests
Fixed #371 -- examples CLI tests working again.
2 parents d5d1162 + 256084b commit a6139b4

4 files changed

Lines changed: 62 additions & 13 deletions

File tree

client/deis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1748,7 +1748,7 @@ def providers_discover(self, args): # noqa
17481748
try:
17491749
deis_codebase_folder = self._session.git_root().split('/')[-1]
17501750
except EnvironmentError:
1751-
deis_codebase_folder = None
1751+
deis_codebase_folder = 'deis'
17521752
if deis_codebase_folder and deis_codebase_folder in running_vms:
17531753
print("Discovered locally running Deis Controller VM")
17541754
# In order for the Controller to be able to boot Vagrant VMs it needs to run commands

client/tests/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
Tests for the command-line client for the Deis system.
33
"""
44

5+
try:
6+
import pexpect # noqa
7+
except ImportError:
8+
print('Please install the python pexpect library.')
9+
raise
10+
511
from .test_apps import * # noqa
612
from .test_auth import * # noqa
713
from .test_builds import * # noqa

client/tests/test_examples.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,25 @@ def setUpClass(cls):
3131
child.expect("created {}.*to scale a basic formation".format(
3232
cls.formation))
3333
child.expect(pexpect.EOF)
34-
# TODO: scale the formation runtime=1
34+
# scale the formation runtime=1
35+
child = pexpect.spawn("{} nodes:scale {} runtime=1".format(
36+
DEIS, cls.formation), timeout=10 * 60)
37+
child.expect('Scaling nodes...')
38+
child.expect(r'done in \d+s')
39+
child.expect(pexpect.EOF)
3540

3641
@classmethod
3742
def tearDownClass(cls):
38-
# TODO: scale formation runtime=0
43+
# scale formation runtime=0
44+
child = pexpect.spawn("{} nodes:scale {} runtime=0".format(
45+
DEIS, cls.formation), timeout=3 * 60)
46+
child.expect('Scaling nodes...')
47+
child.expect(r'done in \d+s')
48+
child.expect(pexpect.EOF)
3949
# destroy the formation
4050
child = pexpect.spawn("{} formations:destroy {} --confirm={}".format(
4151
DEIS, cls.formation, cls.formation))
42-
child.expect('done in ', timeout=5*60)
52+
child.expect('done in ', timeout=5 * 60)
4353
child.expect(pexpect.EOF)
4454
purge(cls.username, cls.password)
4555

@@ -51,25 +61,37 @@ def _test_example(self, repo_name):
5161
# create an App
5262
child = pexpect.spawn("{} create --formation={}".format(
5363
DEIS, self.formation))
54-
child.expect('done, created (?P<name>[-_\w]+)')
64+
child.expect('done, created (?P<name>[-_\w]+)', timeout=3 * 60)
5565
app = child.match.group('name')
5666
try:
5767
child.expect('Git remote deis added')
5868
child.expect(pexpect.EOF)
5969
child = pexpect.spawn('git push deis master')
6070
# check git output for repo_type, e.g. "Clojure app detected"
61-
child.expect("{} app detected".format(repo_type), timeout=2*60)
62-
child.expect(' -> master', timeout=10*60)
63-
child.expect(pexpect.EOF, timeout=2*60)
64-
# TODO: scale up runtime nodes in setUpClass, then
65-
# actually fetch the URL with curl and check the output
66-
# TODO: `deis config:set POWERED_BY="Automated Testing"`
71+
# TODO: for some reason, the next regex times out...
72+
# child.expect("{} app detected".format(repo_type), timeout=5 * 60)
73+
child.expect('Launching... ', timeout=10 * 60)
74+
child.expect('deployed to Deis(?P<url>.+)To learn more', timeout=3 * 60)
75+
url = child.match.group('url')
76+
child.expect(' -> master')
77+
child.expect(pexpect.EOF, timeout=2 * 60)
78+
# fetch the URL with curl and check the output
79+
child = pexpect.spawn("curl -s {}".format(url))
80+
child.expect('Powered by Deis')
81+
child.expect(pexpect.EOF)
82+
# `deis config:set POWERED_BY="Automated Testing"`
83+
child = pexpect.spawn(
84+
"{} config:set POWERED_BY='Automated Testing'".format(DEIS))
85+
child.expect(pexpect.EOF, timeout=3 * 60)
6786
# then re-fetch the URL with curl and recheck the output
87+
child = pexpect.spawn("curl -s {}".format(url))
88+
child.expect('Powered by Automated Testing')
89+
child.expect(pexpect.EOF)
6890
finally:
6991
# destroy the app
7092
child = pexpect.spawn(
7193
"{} apps:destroy --app={} --confirm={}".format(DEIS, app, app),
72-
timeout=5*60)
94+
timeout=5 * 60)
7395
child.expect('Git remote deis removed')
7496
child.expect(pexpect.EOF)
7597

client/tests/utils.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
except KeyError:
2323
DEIS_SERVER = None
2424
print '\033[35mError: env var DEIS_SERVER must point to a Deis controller URL.\033[0m'
25-
DEIS_TEST_FLAVOR = os.environ.get('DEIS_TEST_FLAVOR', 'vagrant-2048')
25+
DEIS_TEST_FLAVOR = os.environ.get('DEIS_TEST_FLAVOR', 'vagrant-512')
2626
EXAMPLES = {
2727
'example-clojure-ring': ('Clojure', 'https://github.com/opdemand/example-clojure-ring.git'),
2828
'example-dart': ('Dart', 'https://github.com/opdemand/example-dart.git'),
@@ -48,6 +48,17 @@ def clone(repo_url, repo_dir):
4848
os.chdir(repo_dir)
4949

5050

51+
def login(username, password):
52+
"""Login as an existing Deis user."""
53+
child = pexpect.spawn("{} login {}".format(DEIS, DEIS_SERVER))
54+
child.expect('username:')
55+
child.sendline(username)
56+
child.expect('password:')
57+
child.sendline(password)
58+
child.expect("Logged in as {}".format(username))
59+
child.expect(pexpect.EOF)
60+
61+
5162
def purge(username, password):
5263
"""Purge an existing Deis user."""
5364
child = pexpect.spawn("{} auth:cancel".format(DEIS))
@@ -117,11 +128,21 @@ def register():
117128
child.sendline(password)
118129
child.expect('email: ')
119130
child.sendline('autotest@opdemand.com')
131+
child.expect("Registered {}".format(username))
132+
child.expect("Logged in as {}".format(username))
133+
child.expect(pexpect.EOF)
134+
# add keys
135+
child = pexpect.spawn("{} keys:add".format(DEIS))
120136
child.expect('Which would you like to use with Deis')
121137
for index, key in re.findall('(\d)\) ([ \S]+)', child.before):
122138
if username in key:
123139
child.sendline(index)
124140
break
141+
child.expect('Uploading')
142+
child.expect('...done')
143+
child.expect(pexpect.EOF)
144+
# discover providers
145+
child = pexpect.spawn("{} providers:discover".format(DEIS))
125146
opt = child.expect(['Import EC2 credentials\? \(y/n\) :',
126147
'No EC2 credentials discovered.'])
127148
if opt == 0:

0 commit comments

Comments
 (0)