2017-12-22 11:38:58 +00:00
|
|
|
"""
|
|
|
|
Tests that runs validity checks on arguments passed in from shell
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
|
2017-12-24 23:03:09 +00:00
|
|
|
def validate_arguments(builddir, args_list, expected):
|
2017-12-22 11:38:58 +00:00
|
|
|
try:
|
2017-12-24 23:03:09 +00:00
|
|
|
cmd = ['repo2docker']
|
|
|
|
for k in args_list:
|
|
|
|
cmd.append(k)
|
|
|
|
cmd.append(builddir)
|
|
|
|
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
|
2017-12-22 11:38:58 +00:00
|
|
|
return True
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
output = e.output.decode()
|
2017-12-24 23:03:09 +00:00
|
|
|
if expected in output:
|
2017-12-22 11:38:58 +00:00
|
|
|
return False
|
|
|
|
else:
|
|
|
|
raise
|
|
|
|
|
2017-12-23 00:17:32 +00:00
|
|
|
|
2017-12-22 11:38:58 +00:00
|
|
|
def test_image_name_fail():
|
2017-12-22 12:31:41 +00:00
|
|
|
"""
|
2017-12-23 00:17:32 +00:00
|
|
|
Test to check if repo2docker throws image_name validation error on --image-name argument containing
|
|
|
|
uppercase characters and _ characters in incorrect positions.
|
2017-12-22 12:31:41 +00:00
|
|
|
"""
|
|
|
|
|
2017-12-22 11:38:58 +00:00
|
|
|
builddir = os.path.dirname(__file__)
|
2017-12-24 23:03:09 +00:00
|
|
|
image_name = 'Test/Invalid_name:1.0.0'
|
|
|
|
args_list = ['--no-run', '--no-build', '--image-name', image_name]
|
|
|
|
expected = "error: argument --image-name: %r is not a valid docker image name. " \
|
|
|
|
"Image name can contain only lowercase characters." % image_name
|
|
|
|
assert not validate_arguments(builddir, args_list, expected)
|
2017-12-22 11:38:58 +00:00
|
|
|
|
2017-12-23 00:17:32 +00:00
|
|
|
|
|
|
|
def test_image_name_underscore_fail():
|
|
|
|
"""
|
|
|
|
Test to check if repo2docker throws image_name validation error on --image-name argument starts with _.
|
|
|
|
"""
|
|
|
|
|
|
|
|
builddir = os.path.dirname(__file__)
|
2017-12-24 23:03:09 +00:00
|
|
|
image_name = '_test/invalid_name:1.0.0'
|
|
|
|
args_list = ['--no-run', '--no-build', '--image-name', image_name]
|
|
|
|
expected = "error: argument --image-name: %r is not a valid docker image name. " \
|
|
|
|
"Image name can contain only lowercase characters." % image_name
|
2017-12-23 00:17:32 +00:00
|
|
|
|
2017-12-24 23:03:09 +00:00
|
|
|
assert not validate_arguments(builddir, args_list, expected)
|
2017-12-23 00:17:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_image_name_double_dot_fail():
|
|
|
|
"""
|
|
|
|
Test to check if repo2docker throws image_name validation error on --image-name argument contains consecutive dots.
|
|
|
|
"""
|
|
|
|
|
|
|
|
builddir = os.path.dirname(__file__)
|
2017-12-24 23:03:09 +00:00
|
|
|
image_name = 'test..com/invalid_name:1.0.0'
|
|
|
|
args_list = ['--no-run', '--no-build', '--image-name', image_name]
|
|
|
|
expected = "error: argument --image-name: %r is not a valid docker image name. " \
|
|
|
|
"Image name can contain only lowercase characters." % image_name
|
2017-12-23 00:17:32 +00:00
|
|
|
|
2017-12-24 23:03:09 +00:00
|
|
|
assert not validate_arguments(builddir, args_list, expected)
|
2017-12-23 00:17:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_image_name_valid_restircted_registry_domain_name_fail():
|
|
|
|
"""
|
|
|
|
Test to check if repo2docker throws image_name validation error on -image-name argument being invalid. Based on the
|
|
|
|
regex definitions first part of registry domain cannot contain uppercase characters
|
|
|
|
"""
|
|
|
|
|
|
|
|
builddir = os.path.dirname(__file__)
|
2017-12-24 23:03:09 +00:00
|
|
|
image_name = 'Test.com/valid_name:1.0.0'
|
|
|
|
args_list = ['--no-run', '--no-build', '--image-name', image_name]
|
|
|
|
expected = "error: argument --image-name: %r is not a valid docker image name. " \
|
|
|
|
"Image name can contain only lowercase characters." % image_name
|
2017-12-23 00:17:32 +00:00
|
|
|
|
2017-12-24 23:03:09 +00:00
|
|
|
assert not validate_arguments(builddir, args_list, expected)
|
2017-12-23 00:17:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_image_name_valid_registry_domain_name_success():
|
|
|
|
"""
|
|
|
|
Test to check if repo2docker runs with a valid --image-name argument.
|
|
|
|
"""
|
|
|
|
|
|
|
|
builddir = os.path.dirname(__file__) + '/dockerfile/simple/'
|
2017-12-24 23:03:09 +00:00
|
|
|
image_name = 'test.COM/valid_name:1.0.0'
|
|
|
|
args_list = ['--no-run', '--no-build', '--image-name', image_name]
|
2017-12-23 00:17:32 +00:00
|
|
|
|
2017-12-24 23:03:09 +00:00
|
|
|
assert validate_arguments(builddir, args_list, None)
|
2017-12-23 00:17:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_image_name_valid_name_success():
|
|
|
|
"""
|
|
|
|
Test to check if repo2docker runs with a valid --image-name argument.
|
|
|
|
"""
|
|
|
|
|
|
|
|
builddir = os.path.dirname(__file__) + '/dockerfile/simple/'
|
2017-12-24 23:03:09 +00:00
|
|
|
image_name = 'test.com/valid_name:1.0.0'
|
|
|
|
args_list = ['--no-run', '--no-build', '--image-name', image_name]
|
|
|
|
|
|
|
|
assert validate_arguments(builddir, args_list, None)
|
|
|
|
|
|
|
|
def test_volume_no_build_fail():
|
|
|
|
"""
|
|
|
|
Test to check if repo2docker fails when both --no-build and -v arguments are given
|
|
|
|
"""
|
|
|
|
builddir = os.path.dirname(__file__)
|
|
|
|
args_list = ['--no-build', '-v', '/data:/data']
|
|
|
|
|
|
|
|
assert not validate_arguments(builddir, args_list, 'To Mount volumes with -v, you also need to run the container')
|
|
|
|
|
|
|
|
|
|
|
|
def test_volume_no_run_fail():
|
|
|
|
"""
|
|
|
|
Test to check if repo2docker fails when both --no-run and -v arguments are given
|
|
|
|
"""
|
|
|
|
builddir = os.path.dirname(__file__)
|
|
|
|
args_list = ['--no-run', '-v', '/data:/data']
|
2017-12-23 00:17:32 +00:00
|
|
|
|
2017-12-24 23:03:09 +00:00
|
|
|
assert not validate_arguments(builddir, args_list, 'To Mount volumes with -v, you also need to run the container')
|