do not allow None as value of image_tags
This commit is contained in:
parent
6e269d1e31
commit
ea3366be35
@ -99,7 +99,7 @@ class Image(BaseObject):
|
|||||||
|
|
||||||
def __init__(self, tag, manifest, repository, digest=None, registry_id=DEFAULT_REGISTRY_ID):
|
def __init__(self, tag, manifest, repository, digest=None, registry_id=DEFAULT_REGISTRY_ID):
|
||||||
self.image_tag = tag
|
self.image_tag = tag
|
||||||
self.image_tags = [tag]
|
self.image_tags = [tag] if tag is not None else []
|
||||||
self.image_manifest = manifest
|
self.image_manifest = manifest
|
||||||
self.image_size_in_bytes = 50 * 1024 * 1024
|
self.image_size_in_bytes = 50 * 1024 * 1024
|
||||||
self.repository = repository
|
self.repository = repository
|
||||||
@ -121,7 +121,7 @@ class Image(BaseObject):
|
|||||||
|
|
||||||
def update_tag(self, tag):
|
def update_tag(self, tag):
|
||||||
self.image_tag = tag
|
self.image_tag = tag
|
||||||
if tag not in self.image_tags:
|
if tag not in self.image_tags and tag is not None:
|
||||||
self.image_tags.append(tag)
|
self.image_tags.append(tag)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -235,7 +235,7 @@ class ECRBackend(BaseBackend):
|
|||||||
found = False
|
found = False
|
||||||
for image in repository.images:
|
for image in repository.images:
|
||||||
if (('imageDigest' in image_id and image.get_image_digest() == image_id['imageDigest']) or
|
if (('imageDigest' in image_id and image.get_image_digest() == image_id['imageDigest']) or
|
||||||
('imageTag' in image_id and image.image_tag == image_id['imageTag'])):
|
('imageTag' in image_id and image_id['imageTag'] in image.image_tags)):
|
||||||
found = True
|
found = True
|
||||||
response.add(image)
|
response.add(image)
|
||||||
if not found:
|
if not found:
|
||||||
|
@ -385,6 +385,68 @@ def test_describe_images_by_tag():
|
|||||||
image_detail['imageDigest'].should.equal(put_response['imageId']['imageDigest'])
|
image_detail['imageDigest'].should.equal(put_response['imageId']['imageDigest'])
|
||||||
|
|
||||||
|
|
||||||
|
@mock_ecr
|
||||||
|
def test_describe_images_tags_should_not_contain_empty_tag1():
|
||||||
|
client = boto3.client('ecr', region_name='us-east-1')
|
||||||
|
_ = client.create_repository(
|
||||||
|
repositoryName='test_repository'
|
||||||
|
)
|
||||||
|
|
||||||
|
manifest = _create_image_manifest()
|
||||||
|
client.put_image(
|
||||||
|
repositoryName='test_repository',
|
||||||
|
imageManifest=json.dumps(manifest)
|
||||||
|
)
|
||||||
|
|
||||||
|
tags = ['v1', 'v2', 'latest']
|
||||||
|
for tag in tags:
|
||||||
|
client.put_image(
|
||||||
|
repositoryName='test_repository',
|
||||||
|
imageManifest=json.dumps(manifest),
|
||||||
|
imageTag=tag
|
||||||
|
)
|
||||||
|
|
||||||
|
response = client.describe_images(repositoryName='test_repository', imageIds=[{'imageTag': tag}])
|
||||||
|
len(response['imageDetails']).should.be(1)
|
||||||
|
image_detail = response['imageDetails'][0]
|
||||||
|
len(image_detail['imageTags']).should.equal(3)
|
||||||
|
image_detail['imageTags'].should.be.equal(tags)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_ecr
|
||||||
|
def test_describe_images_tags_should_not_contain_empty_tag2():
|
||||||
|
client = boto3.client('ecr', region_name='us-east-1')
|
||||||
|
_ = client.create_repository(
|
||||||
|
repositoryName='test_repository'
|
||||||
|
)
|
||||||
|
|
||||||
|
manifest = _create_image_manifest()
|
||||||
|
tags = ['v1', 'v2']
|
||||||
|
for tag in tags:
|
||||||
|
client.put_image(
|
||||||
|
repositoryName='test_repository',
|
||||||
|
imageManifest=json.dumps(manifest),
|
||||||
|
imageTag=tag
|
||||||
|
)
|
||||||
|
|
||||||
|
client.put_image(
|
||||||
|
repositoryName='test_repository',
|
||||||
|
imageManifest=json.dumps(manifest)
|
||||||
|
)
|
||||||
|
|
||||||
|
client.put_image(
|
||||||
|
repositoryName='test_repository',
|
||||||
|
imageManifest=json.dumps(manifest),
|
||||||
|
imageTag='latest'
|
||||||
|
)
|
||||||
|
|
||||||
|
response = client.describe_images(repositoryName='test_repository', imageIds=[{'imageTag': tag}])
|
||||||
|
len(response['imageDetails']).should.be(1)
|
||||||
|
image_detail = response['imageDetails'][0]
|
||||||
|
len(image_detail['imageTags']).should.equal(3)
|
||||||
|
image_detail['imageTags'].should.be.equal(['v1', 'v2', 'latest'])
|
||||||
|
|
||||||
|
|
||||||
@mock_ecr
|
@mock_ecr
|
||||||
def test_describe_repository_that_doesnt_exist():
|
def test_describe_repository_that_doesnt_exist():
|
||||||
client = boto3.client('ecr', region_name='us-east-1')
|
client = boto3.client('ecr', region_name='us-east-1')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user