Support filtering by image id or image tag when describing ecr images

This commit is contained in:
William Richard 2017-06-20 16:22:34 -04:00
commit 3f20ad2c13
No known key found for this signature in database
GPG key ID: F7F8BA4DDBE1ABED
3 changed files with 71 additions and 5 deletions

View file

@ -314,3 +314,57 @@ def test_describe_images():
response['imageDetails'][0]['imageSizeInBytes'].should.equal(52428800)
response['imageDetails'][1]['imageSizeInBytes'].should.equal(52428800)
response['imageDetails'][2]['imageSizeInBytes'].should.equal(52428800)
@mock_ecr
def test_describe_images_by_tag():
client = boto3.client('ecr', region_name='us-east-1')
_ = client.create_repository(
repositoryName='test_repository'
)
tag_map = {}
for tag in ['latest', 'v1', 'v2']:
put_response = client.put_image(
repositoryName='test_repository',
imageManifest=json.dumps(_create_image_manifest()),
imageTag=tag
)
tag_map[tag] = put_response['image']
for tag, put_response in tag_map.items():
response = client.describe_images(repositoryName='test_repository', imageIds=[{'imageTag': tag}])
len(response['imageDetails']).should.be(1)
image_detail = response['imageDetails'][0]
image_detail['registryId'].should.equal("012345678910")
image_detail['repositoryName'].should.equal("test_repository")
image_detail['imageTags'].should.equal([put_response['imageId']['imageTag']])
image_detail['imageDigest'].should.equal(put_response['imageId']['imageDigest'])
@mock_ecr
def test_describe_images_by_digest():
client = boto3.client('ecr', region_name='us-east-1')
_ = client.create_repository(
repositoryName='test_repository'
)
tags = ['latest', 'v1', 'v2']
digest_map = {}
for tag in tags:
put_response = client.put_image(
repositoryName='test_repository',
imageManifest=json.dumps(_create_image_manifest()),
imageTag=tag
)
digest_map[put_response['image']['imageId']['imageDigest']] = put_response['image']
for digest, put_response in digest_map.items():
response = client.describe_images(repositoryName='test_repository',
imageIds=[{'imageDigest': digest}])
len(response['imageDetails']).should.be(1)
image_detail = response['imageDetails'][0]
image_detail['registryId'].should.equal("012345678910")
image_detail['repositoryName'].should.equal("test_repository")
image_detail['imageTags'].should.equal([put_response['imageId']['imageTag']])
image_detail['imageDigest'].should.equal(digest)