Skip to content

Commit

Permalink
clean up toml test files (#571)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamarrow committed Apr 14, 2016
1 parent bd90576 commit 56a8690
Show file tree
Hide file tree
Showing 15 changed files with 145 additions and 144 deletions.
1 change: 1 addition & 0 deletions ccm/tests_ccm_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ set -x
# run tests
CLI_TEST_MASTER_PROXY=true \
CLI_TEST_SSH_KEY_PATH=/dcos-cli/mesosphere-aws.key \
echo "dcos_acs_token = \"$DCOS_ACS_TOKEN\"" >> /dcos-cli/cli/tests/data/dcos.toml && \
./bin/start_tests.sh
3 changes: 0 additions & 3 deletions cli/tests/data/analytics/dcos_no_reporting.toml

This file was deleted.

4 changes: 0 additions & 4 deletions cli/tests/data/analytics/dcos_reporting.toml

This file was deleted.

3 changes: 0 additions & 3 deletions cli/tests/data/analytics/dcos_reporting_with_url.toml

This file was deleted.

2 changes: 0 additions & 2 deletions cli/tests/data/auth/dcos_with_credentials.toml

This file was deleted.

2 changes: 0 additions & 2 deletions cli/tests/data/auth/dcos_without_credentials.toml

This file was deleted.

4 changes: 0 additions & 4 deletions cli/tests/data/config/missing_params_dcos.toml

This file was deleted.

5 changes: 0 additions & 5 deletions cli/tests/data/marathon/missing_marathon_params.toml

This file was deleted.

6 changes: 0 additions & 6 deletions cli/tests/data/ssl/ssl.toml

This file was deleted.

38 changes: 38 additions & 0 deletions cli/tests/integrations/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,44 @@ def app(path, app_id, wait=True):
watch_all_deployments()


@contextlib.contextmanager
def update_config(name, value, env=None):
""" Context manager for altering config for tests
:param key: <key>
:type key: str
:param value: <value>
:type value: str
;param env: env vars
:type env: dict
:rtype: None
"""

returncode, stdout, _ = exec_command(
['dcos', 'config', 'show', name], env)

result = None
# config param already exists
if returncode == 0:
result = json.loads('"' + stdout.decode('utf-8').strip() + '"')

# if we are setting a value
if value is not None:
config_set(name, value, env)
# only unset if the config param already exists
elif result is not None:
config_unset(name, env)

try:
yield
finally:
# return config to previous state
if result is not None:
config_set(name, result, env)
else:
exec_command(['dcos', 'config', 'unset', name], env)


@contextlib.contextmanager
def package(package_name, deploy=False, args=[]):
"""Context manager that deploys an app on entrance, and removes it on
Expand Down
35 changes: 17 additions & 18 deletions cli/tests/integrations/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest

from .common import assert_command, config_set, exec_command
from .common import assert_command, exec_command, update_config


@pytest.fixture
Expand All @@ -31,23 +31,22 @@ def test_version():


def test_logout_no_token(env):
exec_command(['dcos', 'config', 'unset', 'core.dcos_acs_token'], env=env)

returncode, _, stderr = exec_command(
['dcos', 'config', 'show', 'core.dcos_acs_token'], env=env)
assert returncode == 1
assert stderr == b"Property 'core.dcos_acs_token' doesn't exist\n"
with update_config("core.dcos_acs_token", None, env):
returncode, _, stderr = exec_command(
['dcos', 'config', 'show', 'core.dcos_acs_token'], env=env)
assert returncode == 1
assert stderr == b"Property 'core.dcos_acs_token' doesn't exist\n"


def test_logout_with_token(env):
config_set('core.dcos_acs_token', "foobar", env=env)
stderr = b"[core.dcos_acs_token]: changed\n"
assert_command(
['dcos', 'config', 'set', 'core.dcos_acs_token', 'faketoken'],
stderr=stderr,
env=env)

stderr = b'Removed [core.dcos_acs_token]\n'
assert_command(['dcos', 'auth', 'logout'],
stderr=stderr,
env=env)
with update_config("core.dcos_acs_token", "foobar", env):
stderr = b"[core.dcos_acs_token]: changed\n"
assert_command(
['dcos', 'config', 'set', 'core.dcos_acs_token', 'faketoken'],
stderr=stderr,
env=env)

stderr = b'Removed [core.dcos_acs_token]\n'
assert_command(['dcos', 'auth', 'logout'],
stderr=stderr,
env=env)
54 changes: 22 additions & 32 deletions cli/tests/integrations/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

import pytest

from .common import assert_command, config_set, config_unset, exec_command
from .common import (assert_command, config_set, config_unset,
exec_command, update_config)


@pytest.fixture
Expand All @@ -20,17 +21,6 @@ def env():
return r


@pytest.fixture
def missing_env():
r = os.environ.copy()
r.update({
constants.PATH_ENV: os.environ[constants.PATH_ENV],
constants.DCOS_CONFIG_ENV:
os.path.join("tests", "data", "config", "missing_params_dcos.toml")
})
return r


def test_help():
with open('tests/data/help/config.txt') as content:
assert_command(['dcos', 'config', '--help'],
Expand Down Expand Up @@ -80,13 +70,15 @@ def test_invalid_dcos_url(env):
stderr = b'Please check url \'abc.com\'. Missing http(s)://\n'
assert_command(['dcos', 'config', 'set', 'core.dcos_url', 'abc.com'],
stderr=stderr,
returncode=1)
returncode=1,
env=env)


def test_get_top_property(env):
stderr = (
b"Property 'core' doesn't fully specify a value - "
b"possible properties are:\n"
b"core.dcos_acs_token\n"
b"core.dcos_url\n"
b"core.reporting\n"
b"core.ssl_verify\n"
Expand All @@ -95,18 +87,19 @@ def test_get_top_property(env):

assert_command(['dcos', 'config', 'show', 'core'],
stderr=stderr,
returncode=1)
returncode=1,
env=env)


def test_set_package_sources_property(env):
def test_set_package_sources_property():
notice = (b"This config property has been deprecated. "
b"Please add your repositories with `dcos package repo add`\n")
assert_command(['dcos', 'config', 'set', 'package.sources', '[\"foo\"]'],
stderr=notice,
returncode=1)


def test_set_core_email_property(env):
def test_set_core_email_property():
notice = (b"This config property has been deprecated.\n")
assert_command(['dcos', 'config', 'set', 'core.email', '[email protected]'],
stderr=notice,
Expand Down Expand Up @@ -189,6 +182,7 @@ def test_unset_top_property(env):
stderr = (
b"Property 'core' doesn't fully specify a value - "
b"possible properties are:\n"
b"core.dcos_acs_token\n"
b"core.dcos_url\n"
b"core.reporting\n"
b"core.ssl_verify\n"
Expand Down Expand Up @@ -216,10 +210,10 @@ def test_set_property_key(env):
env=env)


def test_set_missing_property(missing_env):
config_set('core.dcos_url', 'http://localhost:8080', missing_env)
_get_value('core.dcos_url', 'http://localhost:8080', missing_env)
config_unset('core.dcos_url', missing_env)
def test_set_missing_property(env):
with update_config("core.dcos_url", None, env=env):
config_set('core.dcos_url', 'http://localhost:8080', env)
_get_value('core.dcos_url', 'http://localhost:8080', env)


def test_set_core_property(env):
Expand Down Expand Up @@ -272,19 +266,15 @@ def test_bad_port_fail_url_validation(env):
'http://localhost:bad_port/', env)


def test_timeout(missing_env):
config_set('marathon.url', 'http://1.2.3.4', missing_env)
config_set('core.timeout', '1', missing_env)

returncode, stdout, stderr = exec_command(
['dcos', 'marathon', 'app', 'list'], env=missing_env)

assert returncode == 1
assert stdout == b''
assert "(connect timeout=1)".encode('utf-8') in stderr
def test_timeout(env):
with update_config('marathon.url', 'http://1.2.3.4', env):
with update_config('core.timeout', '1', env):
returncode, stdout, stderr = exec_command(
['dcos', 'marathon', 'app', 'list'], env=env)

config_unset('core.timeout', missing_env)
config_unset('marathon.url', missing_env)
assert returncode == 1
assert stdout == b''
assert "(connect timeout=1)".encode('utf-8') in stderr


def test_parse_error():
Expand Down
31 changes: 16 additions & 15 deletions cli/tests/integrations/test_marathon.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

from .common import (app, assert_command, assert_lines, config_set,
config_unset, exec_command, list_deployments, popen_tty,
show_app, watch_all_deployments, watch_deployment)
show_app, update_config, watch_all_deployments,
watch_deployment)

_ZERO_INSTANCE_APP_INSTANCES = 100

Expand Down Expand Up @@ -43,24 +44,24 @@ def test_about():


@pytest.fixture
def missing_env():
env = os.environ.copy()
env.update({
def env():
r = os.environ.copy()
r.update({
constants.PATH_ENV: os.environ[constants.PATH_ENV],
constants.DCOS_CONFIG_ENV:
os.path.join("tests", "data", "marathon",
"missing_marathon_params.toml")
constants.DCOS_CONFIG_ENV: os.path.join("tests", "data", "dcos.toml"),
})
return env

return r

def test_missing_config(missing_env):
assert_command(
['dcos', 'marathon', 'app', 'list'],
returncode=1,
stderr=(b'Missing required config parameter: "core.dcos_url". '
b'Please run `dcos config set core.dcos_url <value>`.\n'),
env=missing_env)

def test_missing_config(env):
with update_config("core.dcos_url", None, env):
assert_command(
['dcos', 'marathon', 'app', 'list'],
returncode=1,
stderr=(b'Missing required config parameter: "core.dcos_url". '
b'Please run `dcos config set core.dcos_url <value>`.\n'),
env=env)


def test_empty_list():
Expand Down
Loading

0 comments on commit 56a8690

Please sign in to comment.