kopia lustrzana https://github.com/jupyterhub/repo2docker
Fixed run argument check for mounting volumes. Refactored argument validation test.
rodzic
5293080add
commit
9e2edb910a
|
@ -369,7 +369,8 @@ class Repo2Docker(Application):
|
||||||
self.run = False
|
self.run = False
|
||||||
self.push = False
|
self.push = False
|
||||||
|
|
||||||
if args.volumes and not args.run:
|
# check against self.run and not args.run as self.run is false on --no-build
|
||||||
|
if args.volumes and not self.run:
|
||||||
# Can't mount if we aren't running
|
# Can't mount if we aren't running
|
||||||
print("To Mount volumes with -v, you also need to run the container")
|
print("To Mount volumes with -v, you also need to run the container")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
|
@ -5,24 +5,17 @@ Tests that runs validity checks on arguments passed in from shell
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
def does_validate_image_name(builddir, image_name):
|
def validate_arguments(builddir, args_list, expected):
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(
|
cmd = ['repo2docker']
|
||||||
[
|
for k in args_list:
|
||||||
'repo2docker',
|
cmd.append(k)
|
||||||
'--no-run',
|
cmd.append(builddir)
|
||||||
'--no-build',
|
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
|
||||||
'--image-name',
|
|
||||||
str(image_name),
|
|
||||||
builddir
|
|
||||||
],
|
|
||||||
stderr=subprocess.STDOUT,
|
|
||||||
).decode()
|
|
||||||
return True
|
return True
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
output = e.output.decode()
|
output = e.output.decode()
|
||||||
if "error: argument --image-name: %r is not a valid docker image name. " \
|
if expected in output:
|
||||||
"Image name can contain only lowercase characters." % image_name in output:
|
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
@ -35,8 +28,11 @@ def test_image_name_fail():
|
||||||
"""
|
"""
|
||||||
|
|
||||||
builddir = os.path.dirname(__file__)
|
builddir = os.path.dirname(__file__)
|
||||||
|
image_name = 'Test/Invalid_name:1.0.0'
|
||||||
assert not does_validate_image_name(builddir, '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)
|
||||||
|
|
||||||
|
|
||||||
def test_image_name_underscore_fail():
|
def test_image_name_underscore_fail():
|
||||||
|
@ -45,8 +41,12 @@ def test_image_name_underscore_fail():
|
||||||
"""
|
"""
|
||||||
|
|
||||||
builddir = os.path.dirname(__file__)
|
builddir = os.path.dirname(__file__)
|
||||||
|
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 does_validate_image_name(builddir, '_test/invalid_name:1.0.0')
|
assert not validate_arguments(builddir, args_list, expected)
|
||||||
|
|
||||||
|
|
||||||
def test_image_name_double_dot_fail():
|
def test_image_name_double_dot_fail():
|
||||||
|
@ -55,8 +55,12 @@ def test_image_name_double_dot_fail():
|
||||||
"""
|
"""
|
||||||
|
|
||||||
builddir = os.path.dirname(__file__)
|
builddir = os.path.dirname(__file__)
|
||||||
|
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
|
||||||
|
|
||||||
assert not does_validate_image_name(builddir, 'test..com/invalid_name:1.0.0')
|
assert not validate_arguments(builddir, args_list, expected)
|
||||||
|
|
||||||
|
|
||||||
def test_image_name_valid_restircted_registry_domain_name_fail():
|
def test_image_name_valid_restircted_registry_domain_name_fail():
|
||||||
|
@ -66,8 +70,12 @@ def test_image_name_valid_restircted_registry_domain_name_fail():
|
||||||
"""
|
"""
|
||||||
|
|
||||||
builddir = os.path.dirname(__file__)
|
builddir = os.path.dirname(__file__)
|
||||||
|
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
|
||||||
|
|
||||||
assert not does_validate_image_name(builddir, 'Test.com/valid_name:1.0.0')
|
assert not validate_arguments(builddir, args_list, expected)
|
||||||
|
|
||||||
|
|
||||||
def test_image_name_valid_registry_domain_name_success():
|
def test_image_name_valid_registry_domain_name_success():
|
||||||
|
@ -76,8 +84,10 @@ def test_image_name_valid_registry_domain_name_success():
|
||||||
"""
|
"""
|
||||||
|
|
||||||
builddir = os.path.dirname(__file__) + '/dockerfile/simple/'
|
builddir = os.path.dirname(__file__) + '/dockerfile/simple/'
|
||||||
|
image_name = 'test.COM/valid_name:1.0.0'
|
||||||
|
args_list = ['--no-run', '--no-build', '--image-name', image_name]
|
||||||
|
|
||||||
assert does_validate_image_name(builddir, 'test.COM/valid_name:1.0.0')
|
assert validate_arguments(builddir, args_list, None)
|
||||||
|
|
||||||
|
|
||||||
def test_image_name_valid_name_success():
|
def test_image_name_valid_name_success():
|
||||||
|
@ -86,5 +96,26 @@ def test_image_name_valid_name_success():
|
||||||
"""
|
"""
|
||||||
|
|
||||||
builddir = os.path.dirname(__file__) + '/dockerfile/simple/'
|
builddir = os.path.dirname(__file__) + '/dockerfile/simple/'
|
||||||
|
image_name = 'test.com/valid_name:1.0.0'
|
||||||
|
args_list = ['--no-run', '--no-build', '--image-name', image_name]
|
||||||
|
|
||||||
assert does_validate_image_name(builddir, 'test.com/valid_name:1.0.0')
|
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']
|
||||||
|
|
||||||
|
assert not validate_arguments(builddir, args_list, 'To Mount volumes with -v, you also need to run the container')
|
Ładowanie…
Reference in New Issue