Exemple #1
0
def test_catalog_commit_message():
    config = Config("https://syn.example.com", "token",
                    "ssh://[email protected]", False)

    commit_message = _render_catalog_commit_msg(config)
    assert not commit_message.startswith('\n')
    assert commit_message.startswith(
        'Automated catalog update from Commodore\n\n')
Exemple #2
0
def test_no_customer_repo(test_patch):
    customer_id = "t-wild-fire-234"
    config = Config("https://syn.example.com", "token",
                    "ssh://[email protected]", False)
    test_patch.return_value = {'id': customer_id}
    with pytest.raises(click.ClickException) as excinfo:
        compile._fetch_customer_config(config, customer_id)
    assert customer_id in str(excinfo.value)
def _setup(tmp_path, filter):
    os.chdir(tmp_path)

    test_run_component_new_command(tmp_path=tmp_path)

    target = "target"
    targetdir = tmp_path / "compiled" / target / "test"
    os.makedirs(targetdir, exist_ok=True)
    testf = targetdir / "object.yaml"
    with open(testf, "w") as objf:
        obj = {
            "metadata": {
                "name": "test",
                "namespace": "untouched",
            },
            "kind": "Secret",
            "apiVersion": "v1",
            "stringData": {
                "content": "verysecret",
            },
        }
        yaml.dump(obj, objf)
    with open(
            tmp_path / "dependencies" / "test-component" / "postprocess" /
            "filters.yml",
            "w",
    ) as filterf:
        yaml.dump(filter, filterf)

    config = Config()
    component = Component(
        "test-component",
        Repo(tmp_path / "dependencies" / "test-component"),
        "https://fake.repo.url",
        "master",
    )
    inventory = {
        "classes": {
            "defaults.test-component",
            "global.common",
            "components.test-component",
        },
        "parameters": {
            "test_component": {
                "namespace": "syn-test-component",
            },
        },
    }
    return testf, config, inventory, target, {"test-component": component}
def _setup(tmp_path, filter):
    os.chdir(tmp_path)

    test_run_component_new_command(tmp_path=tmp_path)

    target = 'target'
    targetdir = tmp_path / 'compiled' / target / 'test'
    os.makedirs(targetdir, exist_ok=True)
    testf = targetdir / 'object.yaml'
    with open(testf, 'w') as objf:
        obj = {
            'metadata': {
                'name': 'test',
                'namespace': 'untouched',
            },
            'kind': 'Secret',
            'apiVersion': 'v1',
            'stringData': {
                'content': 'verysecret',
            },
        }
        yaml.dump(obj, objf)
    with open(
            tmp_path / 'dependencies' / 'test-component' / 'postprocess' /
            'filters.yml', 'w') as filterf:
        yaml.dump(filter, filterf)

    config = Config()
    component = Component('test-component',
                          Repo(tmp_path / 'dependencies' / 'test-component'),
                          'https://fake.repo.url', 'master')
    inventory = {
        'classes': {
            'defaults.test-component',
            'global.common',
            'components.test-component',
        },
        'parameters': {
            'test_component': {
                'namespace': 'syn-test-component',
            },
        },
    }
    return testf, config, inventory, target, {'test-component': component}
def test_fetch_components(patch_discover, patch_urls, patch_clone, data: Config, tmp_path):
    os.chdir(tmp_path)
    components = ['component-one', 'component-two']
    # Prepare minimum component directories
    for component in components:
        class_dir = Path('dependencies') / component / 'class'
        class_dir.mkdir(parents=True, exist_ok=True)
        (class_dir / 'defaults.yml').touch(exist_ok=True)
    patch_discover.return_value = components
    patch_urls.return_value = [
        Component(
            name=c,
            repo=None,
            repo_url='mock-url',
            version='master',
        ) for c in components]
    dependency_mgmt.fetch_components(data)
    print(data._components)
    for component in components:
        assert component in data._components
        assert (Path('inventory/classes/components') / f"{component}.yml").is_symlink()
        assert (Path('inventory/classes/defaults') / f"{component}.yml").is_symlink()
        assert data.get_component_repo(component) is not None
def test_no_component_compile_command():
    with pytest.raises(ClickException) as excinfo:
        compile_component(Config(), './', [], [], './')
    assert 'Could not find component class file' in str(excinfo)
Exemple #7
0
def test_no_component_compile_command():
    with pytest.raises(ClickException) as excinfo:
        compile_component(Config(), "./", [], [], "./")
    assert "Could not find component class file" in str(excinfo)
def data():
    """
    Setup test data
    """

    return Config("https://syn.example.com", "token", "ssh://[email protected]", False)