diff --git a/integration/core/test_catalog.py b/integration/core/test_catalog.py new file mode 100644 index 0000000..5a281ee --- /dev/null +++ b/integration/core/test_catalog.py @@ -0,0 +1,67 @@ +import pytest +import cattle +import subprocess +import sys +import os + + +def _base(): + return os.path.dirname(__file__) + + +def _file(f): + return os.path.join(_base(), '../../{}'.format(f)) + + +class CatalogService(object): + def __init__(self, catalog_bin): + self.catalog_bin = catalog_bin + + def assert_retcode(self, ret_code, *args): + p = self.call(*args) + r_code = p.wait() + assert r_code == ret_code + + def call(self, *args, **kw): + cmd = [self.catalog_bin] + cmd.extend(args) + + kw_args = { + 'stdin': subprocess.PIPE, + 'stdout': sys.stdout, + 'stderr': sys.stderr, + 'cwd': _base(), + } + + kw_args.update(kw) + return subprocess.Popen(cmd, **kw_args) + + +@pytest.fixture(scope='session') +def catalog_bin(): + c = '/usr/bin/rancher-catalog-service' + assert os.path.exists(c) + return c + + +@pytest.fixture(scope='session') +def catalog_service(catalog_bin): + return CatalogService(catalog_bin) + + +@pytest.fixture +def client(): + url = 'http://localhost:8088/v1-catalog/schemas' + return cattle.from_env(url=url) + + +def test_validate_exits_normal(catalog_service): + catalog_service.assert_retcode( + 0, '-catalogUrl', + _file('./'), + '-validate', '-port', '18088') + + +def test_catalog_list(client): + templates = client.list_template() + assert len(templates) > 0 diff --git a/integration/requirements.txt b/integration/requirements.txt new file mode 100644 index 0000000..afcbb44 --- /dev/null +++ b/integration/requirements.txt @@ -0,0 +1,4 @@ +cattle==0.5.1 + +flake8 +pytest==2.3.5 diff --git a/integration/setup.py b/integration/setup.py new file mode 100644 index 0000000..8dc7b47 --- /dev/null +++ b/integration/setup.py @@ -0,0 +1,10 @@ +from distutils.core import setup + +setup( + name='Rancher Catalog YAML Integration Tests', + version='0.1', + packages=[ + 'core', + ], + license='ASL 2.0', +) diff --git a/integration/tox.ini b/integration/tox.ini new file mode 100644 index 0000000..f488d5e --- /dev/null +++ b/integration/tox.ini @@ -0,0 +1,12 @@ +[tox] +envlist=flake8, py27 + +[testenv] +deps=-rrequirements.txt +changedir=core +commands=py.test --duration=20 {posargs} + +[testenv:flake8] +deps=-rrequirements.txt +changedir={toxinidir} +commands=flake8 core