use assert_command in test_config.py

This commit is contained in:
Michael Gummelt
2015-04-28 18:02:36 -07:00
parent c36e45f61a
commit f6cdff6bd8
7 changed files with 227 additions and 386 deletions

View File

@@ -1,8 +1,8 @@
[core]
reporting = false
email = "test@mail.com"
[subcommand]
pip_find_links = "../dist"
[core]
email = "test@mail.com"
reporting = false
[marathon]
host = "localhost"
port = 8080

View File

@@ -8,7 +8,6 @@ from mock import Mock, patch
def test_no_browser_auth():
webbrowser.get = Mock(side_effect=webbrowser.Error())
with patch('webbrowser.open') as op:
_mock_dcos_run([util.which('dcos')], False)

View File

@@ -6,7 +6,7 @@ import six
from dcos.api import constants
import pytest
from common import exec_command
from common import assert_command, exec_command
@pytest.fixture
@@ -19,10 +19,7 @@ def env():
def test_help():
returncode, stdout, stderr = exec_command(['dcos', 'config', '--help'])
assert returncode == 0
assert stdout == b"""Get and set DCOS CLI configuration properties
stdout = b"""Get and set DCOS CLI configuration properties
Usage:
dcos config --info
@@ -44,32 +41,24 @@ Positional Arguments:
<name> The name of the property
<value> The value of the property
"""
assert stderr == b''
assert_command(['dcos', 'config', '--help'],
stdout=stdout)
def test_info():
returncode, stdout, stderr = exec_command(['dcos', 'config', '--info'])
assert returncode == 0
assert stdout == b'Get and set DCOS CLI configuration properties\n'
assert stderr == b''
stdout = b'Get and set DCOS CLI configuration properties\n'
assert_command(['dcos', 'config', '--info'],
stdout=stdout)
def test_version():
returncode, stdout, stderr = exec_command(['dcos', 'config', '--version'])
assert returncode == 0
assert stdout == b'dcos-config version 0.1.0\n'
assert stderr == b''
stdout = b'dcos-config version 0.1.0\n'
assert_command(['dcos', 'config', '--version'],
stdout=stdout)
def test_list_property(env):
returncode, stdout, stderr = exec_command(
['dcos', 'config', 'show'],
env)
assert returncode == 0
assert stdout == b"""core.email=test@mail.com
stdout = b"""core.email=test@mail.com
core.reporting=False
marathon.host=localhost
marathon.port=8080
@@ -78,7 +67,9 @@ package.sources=['git://github.com/mesosphere/universe.git', \
'https://github.com/mesosphere/universe/archive/master.zip']
subcommand.pip_find_links=../dist
"""
assert stderr == b''
assert_command(['dcos', 'config', 'show'],
stdout=stdout,
env=env)
def test_get_existing_string_property(env):
@@ -94,19 +85,17 @@ def test_get_missing_property(env):
def test_get_top_property(env):
returncode, stdout, stderr = exec_command(
['dcos', 'config', 'show', 'marathon'],
env)
assert returncode == 1
assert stdout == b''
assert stderr == (
stderr = (
b"Property 'marathon' doesn't fully specify a value - "
b"possible properties are:\n"
b"marathon.host\n"
b"marathon.port\n"
)
assert_command(['dcos', 'config', 'show', 'marathon'],
stderr=stderr,
returncode=1)
def test_set_existing_string_property(env):
_set_value('marathon.host', 'newhost', env)
@@ -191,27 +180,25 @@ def test_prepend_list(env):
def test_append_non_list(env):
returncode, stdout, stderr = exec_command(
['dcos', 'config', 'append', 'marathon.host', 'new_uri'],
env)
stderr = (b"Append/Prepend not supported on 'marathon.host' "
b"properties - use 'dcos config set marathon.host new_uri'\n")
assert returncode == 1
assert stdout == b''
assert (stderr ==
b"Append/Prepend not supported on 'marathon.host' "
b"properties - use 'dcos config set marathon.host new_uri'\n")
assert_command(
['dcos', 'config', 'append', 'marathon.host', 'new_uri'],
returncode=1,
stderr=stderr,
env=env)
def test_prepend_non_list(env):
returncode, stdout, stderr = exec_command(
['dcos', 'config', 'prepend', 'marathon.host', 'new_uri'],
env)
stderr = (b"Append/Prepend not supported on 'marathon.host' "
b"properties - use 'dcos config set marathon.host new_uri'\n")
assert returncode == 1
assert stdout == b''
assert (stderr ==
b"Append/Prepend not supported on 'marathon.host' "
b"properties - use 'dcos config set marathon.host new_uri'\n")
assert_command(
['dcos', 'config', 'prepend', 'marathon.host', 'new_uri'],
returncode=1,
stderr=stderr,
env=env)
def test_unset_property(env):
@@ -221,29 +208,27 @@ def test_unset_property(env):
def test_unset_missing_property(env):
returncode, stdout, stderr = exec_command(
assert_command(
['dcos', 'config', 'unset', 'missing.property'],
env)
assert returncode == 1
assert stdout == b''
assert stderr == b"Property 'missing.property' doesn't exist\n"
returncode=1,
stderr=b"Property 'missing.property' doesn't exist\n",
env=env)
def test_unset_top_property(env):
returncode, stdout, stderr = exec_command(
['dcos', 'config', 'unset', 'marathon'],
env)
assert returncode == 1
assert stdout == b''
assert stderr == (
stderr = (
b"Property 'marathon' doesn't fully specify a value - "
b"possible properties are:\n"
b"marathon.host\n"
b"marathon.port\n"
)
assert_command(
['dcos', 'config', 'unset', 'marathon'],
returncode=1,
stderr=stderr,
env=env)
def test_unset_whole_list(env):
_unset_value('package.sources', None, env)
@@ -268,73 +253,64 @@ def test_unset_list_index(env):
def test_unset_outbound_index(env):
returncode, stdout, stderr = exec_command(
['dcos', 'config', 'unset', '--index=3', 'package.sources'],
env)
stderr = (
b'Index (3) is out of bounds - possible values are '
b'between 0 and 1\n'
)
assert returncode == 1
assert stdout == b''
assert (stderr ==
b'Index (3) is out of bounds - possible values are '
b'between 0 and 1\n')
assert_command(
['dcos', 'config', 'unset', '--index=3', 'package.sources'],
returncode=1,
stderr=stderr,
env=env)
def test_unset_bad_index(env):
returncode, stdout, stderr = exec_command(
['dcos', 'config', 'unset', '--index=number', 'package.sources'],
env)
stderr = b'Error parsing string as int\n'
assert returncode == 1
assert stdout == b''
assert stderr == b'Error parsing string as int\n'
assert_command(
['dcos', 'config', 'unset', '--index=number', 'package.sources'],
returncode=1,
stderr=stderr,
env=env)
def test_unset_index_from_string(env):
returncode, stdout, stderr = exec_command(
['dcos', 'config', 'unset', '--index=0', 'marathon.host'],
env)
stderr = b'Unsetting based on an index is only supported for lists\n'
assert returncode == 1
assert stdout == b''
assert (stderr ==
b'Unsetting based on an index is only supported for lists\n')
assert_command(
['dcos', 'config', 'unset', '--index=0', 'marathon.host'],
returncode=1,
stderr=stderr,
env=env)
def test_validate(env):
returncode, stdout, stderr = exec_command(
['dcos', 'config', 'validate'],
env)
assert returncode == 0
assert stdout == b''
assert stderr == b''
assert_command(['dcos', 'config', 'validate'],
env=env)
def test_validation_error(env):
_unset_value('marathon.host', None, env)
returncode, stdout, stderr = exec_command(
['dcos', 'config', 'validate'],
env)
assert returncode == 1
assert stdout == b''
assert stderr == b"""Error: 'host' is a required property
stderr = b"""Error: 'host' is a required property
Path: marathon
Value: {"port": 8080}
"""
assert_command(['dcos', 'config', 'validate'],
returncode=1,
stderr=stderr,
env=env)
_set_value('marathon.host', 'localhost', env)
def test_set_property_key(env):
returncode, stdout, stderr = exec_command(
assert_command(
['dcos', 'config', 'set', 'path.to.value', 'cool new value'],
env)
assert returncode == 1
assert stdout == b''
assert stderr == b"'path' is not a dcos command.\n"
returncode=1,
stderr=b"'path' is not a dcos command.\n",
env=env)
def test_set_missing_property(env):
@@ -350,33 +326,21 @@ def test_set_core_property(env):
def _set_value(key, value, env):
returncode, stdout, stderr = exec_command(
assert_command(
['dcos', 'config', 'set', key, value],
env)
assert returncode == 0
assert stdout == b''
assert stderr == b''
env=env)
def _append_value(key, value, env):
returncode, stdout, stderr = exec_command(
assert_command(
['dcos', 'config', 'append', key, value],
env)
assert returncode == 0
assert stdout == b''
assert stderr == b''
env=env)
def _prepend_value(key, value, env):
returncode, stdout, stderr = exec_command(
assert_command(
['dcos', 'config', 'prepend', key, value],
env)
assert returncode == 0
assert stdout == b''
assert stderr == b''
env=env)
def _get_value(key, value, env):
@@ -399,11 +363,7 @@ def _unset_value(key, index, env):
if index is not None:
cmd.append('--index={}'.format(index))
returncode, stdout, stderr = exec_command(cmd, env)
assert returncode == 0
assert stdout == b''
assert stderr == b''
assert_command(cmd, env=env)
def _get_missing_value(key, env):

View File

@@ -2,7 +2,7 @@ import os
from dcos.api import constants
from common import exec_command
from common import assert_command, exec_command
def test_default():
@@ -29,10 +29,7 @@ Get detailed command description with 'dcos <command> --help'.
def test_help():
returncode, stdout, stderr = exec_command(['dcos', '--help'])
assert returncode == 0
assert stdout == b"""\
stdout = b"""\
Command line utility for the Mesosphere Datacenter Operating
System (DCOS)
@@ -62,15 +59,14 @@ Environment Variables:
DCOS_CONFIG This environment variable points to the
location of the DCOS configuration file.
"""
assert stderr == b''
assert_command(['dcos', '--help'],
stdout=stdout)
def test_version():
returncode, stdout, stderr = exec_command(['dcos', '--version'])
assert returncode == 0
assert stdout == b'dcos version 0.1.0\n'
assert stderr == b''
assert_command(['dcos', '--version'],
stdout=b'dcos version 0.1.0\n')
def test_missing_dcos_config():
@@ -78,12 +74,13 @@ def test_missing_dcos_config():
constants.PATH_ENV: os.environ[constants.PATH_ENV],
}
returncode, stdout, stderr = exec_command(['dcos'], env=env)
stdout = (b"Environment variable 'DCOS_CONFIG' must be set "
b"to the DCOS config file.\n")
assert returncode == 1
assert stdout == (b"Environment variable 'DCOS_CONFIG' must be set "
b"to the DCOS config file.\n")
assert stderr == b''
assert_command(['dcos'],
stdout=stdout,
returncode=1,
env=env)
def test_dcos_config_not_a_file():
@@ -92,12 +89,13 @@ def test_dcos_config_not_a_file():
'DCOS_CONFIG': 'missing/file',
}
returncode, stdout, stderr = exec_command(['dcos'], env=env)
stdout = (b"Environment variable 'DCOS_CONFIG' maps to "
b"'missing/file' and it is not a file.\n")
assert returncode == 1
assert stdout == (b"Environment variable 'DCOS_CONFIG' maps to "
b"'missing/file' and it is not a file.\n")
assert stderr == b''
assert_command(['dcos'],
returncode=1,
stdout=stdout,
env=env)
def test_log_level_flag():
@@ -117,11 +115,11 @@ def test_capital_log_level_flag():
def test_invalid_log_level_flag():
returncode, stdout, stderr = exec_command(
['dcos', '--log-level=blah', 'config', '--info'])
stdout = (b"Log level set to an unknown value 'blah'. Valid "
b"values are ['debug', 'info', 'warning', 'error', "
b"'critical']\n")
assert returncode == 1
assert stdout == (b"Log level set to an unknown value 'blah'. Valid "
b"values are ['debug', 'info', 'warning', 'error', "
b"'critical']\n")
assert stderr == b''
assert_command(
['dcos', '--log-level=blah', 'config', '--info'],
returncode=1,
stdout=stdout)

View File

@@ -1,11 +1,8 @@
from common import exec_command
from common import assert_command
def test_help():
returncode, stdout, stderr = exec_command(['dcos', 'help', '--help'])
assert returncode == 0
assert stdout == b"""Display command line usage information
stdout = b"""Display command line usage information
Usage:
dcos help --info
@@ -16,30 +13,22 @@ Options:
--info Show a short description of this subcommand
--version Show version
"""
assert stderr == b''
assert_command(['dcos', 'help', '--help'],
stdout=stdout)
def test_info():
returncode, stdout, stderr = exec_command(['dcos', 'help', '--info'])
assert returncode == 0
assert stdout == b'Display command line usage information\n'
assert stderr == b''
assert_command(['dcos', 'help', '--info'],
stdout=b'Display command line usage information\n')
def test_version():
returncode, stdout, stderr = exec_command(['dcos', 'help', '--version'])
assert returncode == 0
assert stdout == b'dcos-help version 0.1.0\n'
assert stderr == b''
assert_command(['dcos', 'help', '--version'],
stdout=b'dcos-help version 0.1.0\n')
def test_list():
returncode, stdout, stderr = exec_command(['dcos', 'help'])
assert returncode == 0
assert stdout == """\
stdout = """\
Command line utility for the Mesosphere Datacenter Operating
System (DCOS). The Mesosphere DCOS is a distributed operating
system built around Apache Mesos. This utility provides tools
@@ -55,4 +44,6 @@ Available DCOS commands:
Get detailed command description with 'dcos <command> --help'.
""".encode('utf-8')
assert stderr == b''
assert_command(['dcos', 'help'],
stdout=stdout)

View File

@@ -1,13 +1,10 @@
import json
from common import exec_command
from common import assert_command, exec_command
def test_help():
returncode, stdout, stderr = exec_command(['dcos', 'marathon', '--help'])
assert returncode == 0
assert stdout == b"""Deploy and manage applications on the DCOS
stdout = b"""Deploy and manage applications on the DCOS
Usage:
dcos marathon --config-schema
@@ -62,24 +59,18 @@ Positional arguments:
value must be the '=' character. E.g. cpus=2.0
<task-id> The task id
"""
assert stderr == b''
assert_command(['dcos', 'marathon', '--help'],
stdout=stdout)
def test_version():
returncode, stdout, stderr = exec_command(
['dcos', 'marathon', '--version'])
assert returncode == 0
assert stdout == b'dcos-marathon version 0.1.0\n'
assert stderr == b''
assert_command(['dcos', 'marathon', '--version'],
stdout=b'dcos-marathon version 0.1.0\n')
def test_info():
returncode, stdout, stderr = exec_command(['dcos', 'marathon', '--info'])
assert returncode == 0
assert stdout == b'Deploy and manage applications on the DCOS\n'
assert stderr == b''
assert_command(['dcos', 'marathon', '--info'],
stdout=b'Deploy and manage applications on the DCOS\n')
def test_empty_list():
@@ -93,13 +84,8 @@ def test_add_app():
def test_optional_add_app():
returncode, stdout, stderr = exec_command(
['dcos', 'marathon', 'app', 'add',
'tests/data/marathon/zero_instance_sleep.json'])
assert returncode == 0
assert stdout == b''
assert stderr == b''
assert_command(['dcos', 'marathon', 'app', 'add',
'tests/data/marathon/zero_instance_sleep.json'])
_list_apps('zero-instance-app')
_remove_app('zero-instance-app')
@@ -126,13 +112,11 @@ def test_add_existing_app():
_add_app('tests/data/marathon/zero_instance_sleep.json')
with open('tests/data/marathon/zero_instance_sleep_v2.json') as fd:
returncode, stdout, stderr = exec_command(
['dcos', 'marathon', 'app', 'add'],
stdin=fd)
assert returncode == 1
assert stdout == b"Application '/zero-instance-app' already exists\n"
assert stderr == b''
stdout = b"Application '/zero-instance-app' already exists\n"
assert_command(['dcos', 'marathon', 'app', 'add'],
returncode=1,
stdout=stdout,
stdin=fd)
_remove_app('zero-instance-app')
@@ -170,14 +154,11 @@ def test_show_missing_relative_app_version():
'zero-instance-app',
'tests/data/marathon/update_zero_instance_sleep.json')
returncode, stdout, stderr = exec_command(
['dcos', 'marathon', 'app', 'show',
'--app-version=-2', 'zero-instance-app'])
assert returncode == 1
assert stdout == b''
assert (stderr ==
b"Application 'zero-instance-app' only has 2 version(s).\n")
stderr = b"Application 'zero-instance-app' only has 2 version(s).\n"
assert_command(['dcos', 'marathon', 'app', 'show',
'--app-version=-2', 'zero-instance-app'],
returncode=1,
stderr=stderr)
_remove_app('zero-instance-app')
@@ -206,15 +187,13 @@ def test_show_bad_app_version():
'zero-instance-app',
'tests/data/marathon/update_zero_instance_sleep.json')
returncode, stdout, stderr = exec_command(
stderr = (b'Error: Invalid format: "20:39:32.972Z" is malformed at '
b'":39:32.972Z"\n')
assert_command(
['dcos', 'marathon', 'app', 'show', '--app-version=20:39:32.972Z',
'zero-instance-app'])
assert returncode == 1
assert stdout == b''
assert (stderr ==
(b'Error: Invalid format: "20:39:32.972Z" is malformed at '
b'":39:32.972Z"\n'))
'zero-instance-app'],
returncode=1,
stderr=stderr)
_remove_app('zero-instance-app')
@@ -225,24 +204,20 @@ def test_show_bad_relative_app_version():
'zero-instance-app',
'tests/data/marathon/update_zero_instance_sleep.json')
returncode, stdout, stderr = exec_command(
assert_command(
['dcos', 'marathon', 'app', 'show',
'--app-version=2', 'zero-instance-app'])
assert returncode == 1
assert stdout == b''
assert (stderr == b"Relative versions must be negative: 2\n")
'--app-version=2', 'zero-instance-app'],
returncode=1,
stderr=b"Relative versions must be negative: 2\n")
_remove_app('zero-instance-app')
def test_start_missing_app():
returncode, stdout, stderr = exec_command(
['dcos', 'marathon', 'app', 'start', 'missing-id'])
assert returncode == 1
assert stdout == b''
assert stderr == b"Error: App '/missing-id' does not exist\n"
assert_command(
['dcos', 'marathon', 'app', 'start', 'missing-id'],
returncode=1,
stderr=b"Error: App '/missing-id' does not exist\n")
def test_start_app():
@@ -255,24 +230,18 @@ def test_start_already_started_app():
_add_app('tests/data/marathon/zero_instance_sleep.json')
_start_app('zero-instance-app')
returncode, stdout, stderr = exec_command(
['dcos', 'marathon', 'app', 'start', 'zero-instance-app'])
assert returncode == 1
assert (stdout ==
b"Application 'zero-instance-app' already started: 1 instances.\n")
assert stderr == b''
stdout = b"Application 'zero-instance-app' already started: 1 instances.\n"
assert_command(['dcos', 'marathon', 'app', 'start', 'zero-instance-app'],
returncode=1,
stdout=stdout)
_remove_app('zero-instance-app')
def test_stop_missing_app():
returncode, stdout, stderr = exec_command(
['dcos', 'marathon', 'app', 'stop', 'missing-id'])
assert returncode == 1
assert stdout == b''
assert stderr == b"Error: App '/missing-id' does not exist\n"
assert_command(['dcos', 'marathon', 'app', 'stop', 'missing-id'],
returncode=1,
stderr=b"Error: App '/missing-id' does not exist\n")
def test_stop_app():
@@ -294,24 +263,18 @@ def test_stop_app():
def test_stop_already_stopped_app():
_add_app('tests/data/marathon/zero_instance_sleep.json')
returncode, stdout, stderr = exec_command(
['dcos', 'marathon', 'app', 'stop', 'zero-instance-app'])
assert returncode == 1
assert (stdout ==
b"Application 'zero-instance-app' already stopped: 0 instances.\n")
assert stderr == b''
stdout = b"Application 'zero-instance-app' already stopped: 0 instances.\n"
assert_command(['dcos', 'marathon', 'app', 'stop', 'zero-instance-app'],
returncode=1,
stdout=stdout)
_remove_app('zero-instance-app')
def test_update_missing_app():
returncode, stdout, stderr = exec_command(
['dcos', 'marathon', 'app', 'update', 'missing-id'])
assert returncode == 1
assert stdout == b''
assert stderr == b"Error: App '/missing-id' does not exist\n"
assert_command(['dcos', 'marathon', 'app', 'update', 'missing-id'],
stderr=b"Error: App '/missing-id' does not exist\n",
returncode=1)
def test_update_missing_field():
@@ -372,25 +335,19 @@ def test_update_app_from_stdin():
def test_restarting_stopped_app():
_add_app('tests/data/marathon/zero_instance_sleep.json')
returncode, stdout, stderr = exec_command(
['dcos', 'marathon', 'app', 'restart', 'zero-instance-app'])
assert returncode == 1
assert stdout == (
b"Unable to perform rolling restart of application '"
b"/zero-instance-app' because it has no running tasks\n")
assert stderr == b''
stdout = (b"Unable to perform rolling restart of application '"
b"/zero-instance-app' because it has no running tasks\n")
assert_command(['dcos', 'marathon', 'app', 'restart', 'zero-instance-app'],
returncode=1,
stdout=stdout)
_remove_app('zero-instance-app')
def test_restarting_missing_app():
returncode, stdout, stderr = exec_command(
['dcos', 'marathon', 'app', 'restart', 'missing-id'])
assert returncode == 1
assert stdout == b''
assert stderr == b"Error: App '/missing-id' does not exist\n"
assert_command(['dcos', 'marathon', 'app', 'restart', 'missing-id'],
returncode=1,
stderr=b"Error: App '/missing-id' does not exist\n")
def test_restarting_app():
@@ -410,22 +367,17 @@ def test_restarting_app():
def test_list_version_missing_app():
returncode, stdout, stderr = exec_command(
['dcos', 'marathon', 'app', 'version', 'list', 'missing-id'])
assert returncode == 1
assert stdout == b''
assert stderr == b"Error: App '/missing-id' does not exist\n"
assert_command(
['dcos', 'marathon', 'app', 'version', 'list', 'missing-id'],
returncode=1,
stderr=b"Error: App '/missing-id' does not exist\n")
def test_list_version_negative_max_count():
returncode, stdout, stderr = exec_command(
['dcos', 'marathon', 'app', 'version', 'list',
'missing-id', '--max-count=-1'])
assert returncode == 1
assert stdout == b''
assert stderr == b'Maximum count must be a positive number: -1\n'
assert_command(['dcos', 'marathon', 'app', 'version', 'list',
'missing-id', '--max-count=-1'],
returncode=1,
stderr=b'Maximum count must be a positive number: -1\n')
def test_list_version_app():
@@ -479,13 +431,10 @@ def test_list_deployment_app():
def test_rollback_missing_deployment():
returncode, stdout, stderr = exec_command(
['dcos', 'marathon', 'deployment', 'rollback', 'missing-deployment'])
assert returncode == 1
assert stdout == b''
assert (stderr ==
b'Error: DeploymentPlan missing-deployment does not exist\n')
assert_command(
['dcos', 'marathon', 'deployment', 'rollback', 'missing-deployment'],
returncode=1,
stderr=b'Error: DeploymentPlan missing-deployment does not exist\n')
def test_rollback_deployment():
@@ -513,12 +462,7 @@ def test_stop_deployment():
_start_app('zero-instance-app', 3)
result = _list_deployments(1, 'zero-instance-app')
returncode, stdout, stderr = exec_command(
['dcos', 'marathon', 'deployment', 'stop', result[0]['id']])
assert returncode == 0
assert stdout == b''
assert stderr == b''
assert_command(['dcos', 'marathon', 'deployment', 'stop', result[0]['id']])
_list_deployments(0)
@@ -613,11 +557,8 @@ def test_bad_configuration():
assert returncode == 0
assert stderr == b''
returncode, stdout, stderr = exec_command(
assert_command(
['dcos', 'config', 'set', 'marathon.port', str(int(port) + 1)])
assert returncode == 0
assert stdout == b''
assert stderr == b''
returncode, stdout, stderr = exec_command(
['dcos', 'marathon', 'app', 'list'])
@@ -654,12 +595,7 @@ def _list_apps(app_id=None):
def _remove_app(app_id):
returncode, stdout, stderr = exec_command(
['dcos', 'marathon', 'app', 'remove', app_id])
assert returncode == 0
assert stdout == b''
assert stderr == b''
assert_command(['dcos', 'marathon', 'app', 'remove', app_id])
# Let's make sure that we don't return until the deployment has finished
result = _list_deployments(None, app_id)
@@ -711,13 +647,8 @@ def _start_app(app_id, instances=None):
def _update_app(app_id, file_path):
with open(file_path) as fd:
returncode, stdout, stderr = exec_command(
['dcos', 'marathon', 'app', 'update', app_id],
stdin=fd)
assert returncode == 0
assert stdout == b''
assert stderr == b''
assert_command(['dcos', 'marathon', 'app', 'update', app_id],
stdin=fd)
def _list_versions(app_id, expected_count, max_count=None):

View File

@@ -8,10 +8,7 @@ from common import assert_command, exec_command
def test_package():
returncode, stdout, stderr = exec_command(['dcos', 'package', '--help'])
assert returncode == 0
assert stdout == b"""Install and manage DCOS software packages
stdout = b"""Install and manage DCOS software packages
Usage:
dcos package --config-schema
@@ -55,35 +52,28 @@ Configuration:
"git://github.com/mesosphere/universe.git"
]
"""
assert stderr == b''
assert_command(['dcos', 'package', '--help'],
stdout=stdout)
def test_info():
returncode, stdout, stderr = exec_command(['dcos', 'package', '--info'])
assert returncode == 0
assert stdout == b'Install and manage DCOS software packages\n'
assert stderr == b''
assert_command(['dcos', 'package', '--info'],
stdout=b'Install and manage DCOS software packages\n')
def test_version():
returncode, stdout, stderr = exec_command(['dcos', 'package', '--version'])
assert returncode == 0
assert stdout == b'dcos-package version 0.1.0\n'
assert stderr == b''
assert_command(['dcos', 'package', '--version'],
stdout=b'dcos-package version 0.1.0\n')
def test_sources_list():
returncode, stdout, stderr = exec_command(['dcos', 'package', 'sources'])
assert returncode == 0
assert stdout == b"""c3f1a0df1d2068e6b11d40224f5e500d3183a97e \
stdout = b"""c3f1a0df1d2068e6b11d40224f5e500d3183a97e \
git://github.com/mesosphere/universe.git
f4ba0923d14eb75c1c0afca61c2adf9b2b355bd5 \
https://github.com/mesosphere/universe/archive/master.zip
"""
assert stderr == b''
assert_command(['dcos', 'package', 'sources'],
stdout=stdout)
def test_update_without_validation():
@@ -108,20 +98,13 @@ def test_update_with_validation():
def test_describe_nonexistent():
returncode, stdout, stderr = exec_command(
['dcos', 'package', 'describe', 'xyzzy'])
assert returncode == 1
assert stdout == b'Package [xyzzy] not found\n'
assert stderr == b''
assert_command(['dcos', 'package', 'describe', 'xyzzy'],
stdout=b'Package [xyzzy] not found\n',
returncode=1)
def test_describe():
returncode, stdout, stderr = exec_command(
['dcos', 'package', 'describe', 'mesos-dns'])
assert returncode == 0
assert stdout == b"""\
stdout = b"""\
{
"description": "DNS-based service discovery for Mesos.",
"maintainer": "support@mesosphere.io",
@@ -139,7 +122,8 @@ tutorial-gce.html",
"website": "http://mesosphere.github.io/mesos-dns"
}
"""
assert stderr == b''
assert_command(['dcos', 'package', 'describe', 'mesos-dns'],
stdout=stdout)
def test_bad_install():
@@ -163,16 +147,11 @@ def test_install():
def test_package_metadata():
returncode, stdout, stderr = exec_command(['dcos',
'package',
'install',
'helloworld'])
assert returncode == 0
assert stdout == b"""Installing package [helloworld] version [0.1.0]
stdout = b"""Installing package [helloworld] version [0.1.0]
Installing CLI subcommand for package [helloworld]
"""
assert stderr == b''
assert_command(['dcos', 'package', 'install', 'helloworld'],
stdout=stdout)
# test marathon labels
expected_metadata = b"""eyJkZXNjcmlwdGlvbiI6ICJFeGFtcGxlIERDT1MgYXBwbGljYX\
@@ -231,12 +210,7 @@ wLjEuMCJdfQ=="""
assert six.b(f.read()) == b'0'
# uninstall helloworld
returncode, stdout, stderr = exec_command(
['dcos', 'package', 'uninstall', 'helloworld'])
assert returncode == 0
assert stdout == b''
assert stderr == b''
assert_command(['dcos', 'package', 'uninstall', 'helloworld'])
def test_install_with_id():
@@ -254,14 +228,12 @@ with app id [dns-2]\n"""
def test_install_missing_package():
returncode, stdout, stderr = exec_command(
['dcos', 'package', 'install', 'missing-package'])
assert returncode == 1
assert stdout == b''
assert stderr == b"""Package [missing-package] not found
stderr = b"""Package [missing-package] not found
You may need to run 'dcos package update' to update your repositories
"""
assert_command(['dcos', 'package', 'install', 'missing-package'],
returncode=1,
stderr=stderr)
def test_uninstall_with_id():
@@ -281,26 +253,16 @@ def test_uninstall_missing():
def test_uninstall_subcommand():
returncode, stdout, stderr = exec_command(
['dcos', 'package', 'install', 'helloworld'])
assert returncode == 0
assert stdout == b"""Installing package [helloworld] version [0.1.0]
stdout = b"""Installing package [helloworld] version [0.1.0]
Installing CLI subcommand for package [helloworld]
"""
assert stderr == b''
assert_command(['dcos', 'package', 'install', 'helloworld'],
stdout=stdout)
returncode, stdout, stderr = exec_command(
['dcos', 'package', 'uninstall', 'helloworld'])
assert returncode == 0
assert stdout == b''
assert stderr == b''
assert_command(['dcos', 'package', 'uninstall', 'helloworld'])
returncode, stdout, stderr = exec_command(
['dcos', 'subcommand', 'list'])
assert returncode == 0
assert stdout == b'[]\n'
assert stderr == b''
assert_command(['dcos', 'subcommand', 'list'],
stdout=b'[]\n')
def test_list_installed():