|
| 1 | +""" |
| 2 | +Unit tests for the Deis example-[language] projects. |
| 3 | +
|
| 4 | +Run these tests with "python -m unittest client.tests.test_examples" |
| 5 | +or with "./manage.py test client.ExamplesTest". |
| 6 | +""" |
| 7 | + |
| 8 | +from __future__ import unicode_literals |
| 9 | +from unittest import TestCase |
| 10 | +from uuid import uuid4 |
| 11 | + |
| 12 | +import pexpect |
| 13 | +from .utils import DEIS |
| 14 | +from .utils import DEIS_TEST_FLAVOR |
| 15 | +from .utils import EXAMPLES |
| 16 | +from .utils import clone |
| 17 | +from .utils import purge |
| 18 | +from .utils import register |
| 19 | + |
| 20 | + |
| 21 | +class ExamplesTest(TestCase): |
| 22 | + |
| 23 | + @classmethod |
| 24 | + def setUpClass(cls): |
| 25 | + cls.username, cls.password = register() |
| 26 | + # create a new formation |
| 27 | + cls.formation = "{}-test-formation-{}".format( |
| 28 | + cls.username, uuid4().hex[:4]) |
| 29 | + child = pexpect.spawn("{} formations:create {} --flavor={}".format( |
| 30 | + DEIS, cls.formation, DEIS_TEST_FLAVOR)) |
| 31 | + child.expect("created {}.*to scale a basic formation".format( |
| 32 | + cls.formation)) |
| 33 | + child.expect(pexpect.EOF) |
| 34 | + # TODO: scale the formation runtime=1 |
| 35 | + |
| 36 | + @classmethod |
| 37 | + def tearDownClass(cls): |
| 38 | + # TODO: scale formation runtime=0 |
| 39 | + # destroy the formation |
| 40 | + child = pexpect.spawn("{} formations:destroy {} --confirm={}".format( |
| 41 | + DEIS, cls.formation, cls.formation)) |
| 42 | + child.expect('done in ', timeout=5*60) |
| 43 | + child.expect(pexpect.EOF) |
| 44 | + purge(cls.username, cls.password) |
| 45 | + |
| 46 | + def _test_example(self, repo_name): |
| 47 | + # `git clone` the example app repository |
| 48 | + repo_type, repo_url = EXAMPLES[repo_name] |
| 49 | + # print repo_name, repo_type, repo_url |
| 50 | + clone(repo_url, repo_name) |
| 51 | + # create an App |
| 52 | + child = pexpect.spawn("{} create --formation={}".format( |
| 53 | + DEIS, self.formation)) |
| 54 | + child.expect('done, created (?P<name>[-_\w]+)') |
| 55 | + app = child.match.group('name') |
| 56 | + try: |
| 57 | + child.expect('Git remote deis added') |
| 58 | + child.expect(pexpect.EOF) |
| 59 | + child = pexpect.spawn('git push deis master') |
| 60 | + # 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"` |
| 67 | + # then re-fetch the URL with curl and recheck the output |
| 68 | + finally: |
| 69 | + # destroy the app |
| 70 | + child = pexpect.spawn( |
| 71 | + "{} apps:destroy --app={} --confirm={}".format(DEIS, app, app), |
| 72 | + timeout=5*60) |
| 73 | + child.expect('Git remote deis removed') |
| 74 | + child.expect(pexpect.EOF) |
| 75 | + |
| 76 | + def test_clojure_ring(self): |
| 77 | + self._test_example('example-clojure-ring') |
| 78 | + |
| 79 | + def test_dart(self): |
| 80 | + self._test_example('example-dart') |
| 81 | + |
| 82 | + def test_go(self): |
| 83 | + self._test_example('example-go') |
| 84 | + |
| 85 | + def test_java_jetty(self): |
| 86 | + self._test_example('example-java-jetty') |
| 87 | + |
| 88 | + def test_nodejs_express(self): |
| 89 | + self._test_example('example-nodejs-express') |
| 90 | + |
| 91 | + def test_perl(self): |
| 92 | + self._test_example('example-perl') |
| 93 | + |
| 94 | + def test_php(self): |
| 95 | + self._test_example('example-php') |
| 96 | + |
| 97 | + def test_play(self): |
| 98 | + self._test_example('example-play') |
| 99 | + |
| 100 | + def test_python_flask(self): |
| 101 | + self._test_example('example-python-flask') |
| 102 | + |
| 103 | + def test_ruby_sinatra(self): |
| 104 | + self._test_example('example-ruby-sinatra') |
| 105 | + |
| 106 | + def test_scala(self): |
| 107 | + self._test_example('example-scala') |
0 commit comments