from bundlewrap.exceptions import BundleError
from bundlewrap.utils.text import bold, green, yellow
from bundlewrap.utils.ui import io


def test_node(repo, node, **kwargs):
    if not node.has_bundle('backup-client'):
        return

    if node.metadata.get('backups/exclude_from_backups', False):
        io.stderr('{x} {node}  exclude_from_backups=True'.format(
            x=yellow("»"),
            node=bold(node.name),
        ))
        return

    if not len(node.metadata.get('backups/paths', set())):
        raise BundleError(f'{node.name} has backups configured, but no backup paths defined!')

    io.stdout('{x} {node}  backup metadata conforms to standards'.format(
        x=green("✓"),
        node=bold(node.name),
    ))
