Add tests for list_active_tags
This commit is contained in:
parent
218acaffbf
commit
626f306283
2 changed files with 64 additions and 0 deletions
|
@ -199,6 +199,7 @@ def delete_tag(namespace_name, repository_name, tag_name):
|
|||
|
||||
found.lifetime_end_ts = now_ts
|
||||
found.save()
|
||||
return found
|
||||
|
||||
|
||||
def garbage_collect_tags(repo):
|
||||
|
|
63
data/model/test/test_tag.py
Normal file
63
data/model/test/test_tag.py
Normal file
|
@ -0,0 +1,63 @@
|
|||
from data.model.repository import create_repository
|
||||
from data.model.tag import list_active_repo_tags, create_or_update_tag, delete_tag
|
||||
from data.model.image import find_create_or_link_image
|
||||
from test.fixtures import database_uri, init_db_path, sqlitedb_file
|
||||
|
||||
def assert_tags(repository, *args):
|
||||
tags = list(list_active_repo_tags(repository))
|
||||
assert len(tags) == len(args)
|
||||
|
||||
tags_dict = {}
|
||||
for tag in tags:
|
||||
assert not tag.name in tags_dict
|
||||
assert not tag.hidden
|
||||
assert not tag.lifetime_end_ts
|
||||
|
||||
tags_dict[tag.name] = tag
|
||||
|
||||
for expected in args:
|
||||
assert expected in tags_dict
|
||||
|
||||
def test_list_active_tags(database_uri):
|
||||
# Create a new repository.
|
||||
repository = create_repository('devtable', 'somenewrepo', None)
|
||||
|
||||
# Create some images.
|
||||
image1 = find_create_or_link_image('foobarimage1', repository, None, {}, 'local_us')
|
||||
image2 = find_create_or_link_image('foobarimage2', repository, None, {}, 'local_us')
|
||||
|
||||
# Make sure its tags list is empty.
|
||||
assert_tags(repository)
|
||||
|
||||
# Add some new tags.
|
||||
footag = create_or_update_tag('devtable', 'somenewrepo', 'foo', image1.docker_image_id)
|
||||
bartag = create_or_update_tag('devtable', 'somenewrepo', 'bar', image1.docker_image_id)
|
||||
|
||||
# Since timestamps are stored on a second-granuality, we need to make the tags "start"
|
||||
# before "now", so when we recreate them below, they don't conflict.
|
||||
footag.lifetime_start_ts -= 5
|
||||
bartag.lifetime_start_ts -= 5
|
||||
|
||||
footag.save()
|
||||
bartag.save()
|
||||
|
||||
# Make sure they are returned.
|
||||
assert_tags(repository, 'foo', 'bar')
|
||||
|
||||
# Delete a tag and make sure it isn't returned.
|
||||
footag = delete_tag('devtable', 'somenewrepo', 'foo')
|
||||
footag.lifetime_end_ts -= 4
|
||||
footag.save()
|
||||
|
||||
assert_tags(repository, 'bar')
|
||||
|
||||
# Add a new foo again.
|
||||
footag = create_or_update_tag('devtable', 'somenewrepo', 'foo', image1.docker_image_id)
|
||||
footag.lifetime_start_ts -= 3
|
||||
footag.save()
|
||||
|
||||
assert_tags(repository, 'foo', 'bar')
|
||||
|
||||
# "Move" foo by updating it and make sure we don't get duplicates.
|
||||
create_or_update_tag('devtable', 'somenewrepo', 'foo', image2.docker_image_id)
|
||||
assert_tags(repository, 'foo', 'bar')
|
Reference in a new issue