Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek committed Aug 16, 2018
1 parent 3f839d6 commit b3284ae
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 13 deletions.
9 changes: 9 additions & 0 deletions datadog_checks_dev/datadog_checks/dev/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# (C) Datadog, Inc. 2018
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import sys

from .tooling.cli import ddev


sys.exit(ddev())
35 changes: 22 additions & 13 deletions datadog_checks_dev/datadog_checks/dev/tooling/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from ..constants import get_root
from ..create import create_template_files, get_valid_templates
from ..utils import normalize_package_name
from ...utils import resolve_path

HYPHEN = b'\xe2\x94\x80\xe2\x94\x80'.decode('utf-8')
PIPE = b'\xe2\x94\x82'.decode('utf-8')
Expand Down Expand Up @@ -94,17 +95,19 @@ def display_path_tree(path_tree):
default='check',
help='The type of integration to create'
)
@click.option('--location', '-l', help='Where to create the integration')
@click.option('--quiet', '-q', is_flag=True, help='Show less output')
@click.option('--dry-run', '-n', is_flag=True, help='Only show what would be created')
@click.pass_context
def create(ctx, name, integration_type, dry_run):
def create(ctx, name, integration_type, location, quiet, dry_run):
"""Create a new integration."""
check_name = normalize_package_name(name)
root = get_root()
integration_name = normalize_package_name(name)
root = resolve_path(location) if location else get_root()
path_sep = os.path.sep

check_dir = os.path.join(root, check_name)
if os.path.exists(check_dir):
abort('Path `{}` already exists!'.format(check_dir))
integration_dir = os.path.join(root, integration_name)
if os.path.exists(integration_dir):
abort('Path `{}` already exists!'.format(integration_dir))

repo_choice = ctx.obj['repo_choice']
if repo_choice == 'core':
Expand All @@ -119,9 +122,9 @@ def create(ctx, name, integration_type, dry_run):

config = {
'author': author,
'check_class': '{}Check'.format(''.join(part.capitalize() for part in check_name.split('_'))),
'check_name': check_name,
'check_name_cap': check_name.capitalize(),
'check_class': '{}Check'.format(''.join(part.capitalize() for part in integration_name.split('_'))),
'check_name': integration_name,
'check_name_cap': integration_name.capitalize(),
'email': email,
'email_packages': email_packages,
'guid': uuid.uuid4(),
Expand All @@ -141,12 +144,18 @@ def create(ctx, name, integration_type, dry_run):
branch = branch[part]

if dry_run:
echo_info('Will create in `{}`:'.format(root))
display_path_tree(path_tree)
if quiet:
echo_info('Will create `{}`'.format(integration_dir))
else:
echo_info('Will create in `{}`:'.format(root))
display_path_tree(path_tree)
return

for file in files:
file.write()

echo_info('Created in `{}`:'.format(root))
display_path_tree(path_tree)
if quiet:
echo_info('Created `{}`'.format(integration_dir))
else:
echo_info('Created in `{}`:'.format(root))
display_path_tree(path_tree)
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# (C) Datadog, Inc. {year}
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import pytest


@pytest.fixture
def instance():
return {{}}
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# (C) Datadog, Inc. {year}
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
from datadog_checks.{check_name} import {check_class}


def test_check(aggregator, instance):
check = {check_class}('{check_name}', {{}}, {{}})
check.check(instance)

aggregator.assert_all_metrics_covered()
32 changes: 32 additions & 0 deletions datadog_checks_dev/tests/tooling/test_create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# (C) Datadog, Inc. 2018
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import os
import sys

from datadog_checks.dev.subprocess import run_command
from datadog_checks.dev.utils import chdir, remove_path


HERE = os.path.dirname(os.path.abspath(__file__))
CORE_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(HERE)))


def test_new_check_test():
check_path = os.path.join(CORE_ROOT, 'my_check')

try:
run_command(
[sys.executable, '-m', 'datadog_checks.dev', 'create', '-q', '-l', CORE_ROOT, 'my-check'],
capture=True,
check=True
)
run_command(
[sys.executable, '-m', 'pip', 'install', check_path],
capture=True,
check=True
)
with chdir(check_path):
run_command([sys.executable, '-m', 'pytest'], capture=True, check=True)
finally:
remove_path(check_path)

0 comments on commit b3284ae

Please sign in to comment.