コード例 #1
0
def test_no_target(fake_docker_registry, fake_image_foo_name):
    source = _get_image(f'{fake_docker_registry}/{fake_image_foo_name}:foo')
    _tag_image(fake_image_foo_name, source.uri, is_dry_run=False)

    expected_target = _get_image(
        f'{fake_docker_registry}/{fake_image_foo_name}:latest')

    assert not is_image_on_registry(source)
    assert not is_image_on_registry(expected_target)
    main(('--source', source.uri))

    assert is_local_image_the_same_on_registry(source, expected_target)
コード例 #2
0
def test_no_previous_image(fake_docker_registry, fake_image_foo_name):
    source = _get_image(f'{fake_docker_registry}/{fake_image_foo_name}:foo')
    _tag_image(fake_image_foo_name, source.uri, is_dry_run=False)

    target = _get_image(f'{fake_docker_registry}/{fake_image_foo_name}:latest')
    _tag_image(target.name, target.uri, is_dry_run=False)

    assert not is_image_on_registry(source)
    assert not is_image_on_registry(target)
    main(('--source', source.uri, '--target', target.uri))

    assert are_two_images_on_registry_the_same(source, target)
    assert is_local_image_the_same_on_registry(source, target)
コード例 #3
0
def test_two_same_images(capsys, fake_docker_registry, fake_image_foo_name):
    source = _get_image(f'{fake_docker_registry}/{fake_image_foo_name}:foo')
    _tag_image(source.name, source.uri, is_dry_run=False)

    target = _get_image(f'{fake_docker_registry}/{fake_image_foo_name}:latest')
    _tag_image(target.name, target.uri, is_dry_run=False)

    assert not is_image_on_registry(source)
    assert not is_image_on_registry(target)
    _push_image(target.uri, is_dry_run=False)
    out, _ = capsys.readouterr()
    assert f'Pushing image {target.uri}' in out
    assert not is_image_on_registry(source)
    assert is_image_on_registry(target)

    main(('--source', source.uri, '--target', target.uri))
    out, _ = capsys.readouterr()
    assert f'Pushing image {target.uri}' not in out
    assert 'Image has NOT changed' in out
    assert are_two_images_on_registry_the_same(source, target)
    assert is_local_image_the_same_on_registry(source, target)
コード例 #4
0
def test_push_new_image_dry_run(
    capsys,
    fake_docker_registry,
    fake_image_foo_name,
    fake_image_bar_name,
):
    source = _get_image(f'{fake_docker_registry}/{fake_image_foo_name}:foo')
    _tag_image(source.name, source.uri, is_dry_run=False)

    target = _get_image(f'{fake_docker_registry}/{fake_image_bar_name}:latest')
    _tag_image(target.name, target.uri, is_dry_run=False)

    assert not is_image_on_registry(source)
    assert not is_image_on_registry(target)
    _push_image(target.uri, is_dry_run=False)
    out, _ = capsys.readouterr()
    assert f'Pushing image {target.uri}' in out
    assert not is_image_on_registry(source)
    assert is_image_on_registry(target)

    main(('--source', source.uri, '--target', target.uri, '--dry-run'))
    out, _ = capsys.readouterr()
    assert 'Image was not actually tagged since this is a dry run' in out
    assert 'Image was not actually pushed since this is a dry run' in out
    assert not is_image_on_registry(source)
    assert is_image_on_registry(target)
コード例 #5
0
def test_two_same_images_with_different_packages(
    capsys,
    fake_docker_registry,
    fake_baz_dummy_deb_images,
):
    baz_dummy_deb_name, baz_no_dummy_deb_name = fake_baz_dummy_deb_images
    source = _get_image(f'{fake_docker_registry}/{baz_dummy_deb_name}:baz')
    _tag_image(source.name, source.uri, is_dry_run=False)

    target = _get_image(
        f'{fake_docker_registry}/{baz_no_dummy_deb_name}:latest')
    _tag_image(target.name, target.uri, is_dry_run=False)

    assert not is_image_on_registry(source)
    assert not is_image_on_registry(target)
    _push_image(target.uri, is_dry_run=False)
    out, _ = capsys.readouterr()
    assert f'Pushing image {target.uri}' in out
    assert not is_image_on_registry(source)
    assert is_image_on_registry(target)

    main(('--source', source.uri, '--target', target.uri))

    out, _ = capsys.readouterr()
    source_key = ImageKey(**re.search(
        f'Source key: {IMAGE_KEY_RE_SUFFIX}',
        out,
    ).groupdict())
    target_key = ImageKey(**re.search(
        f'Target key: {IMAGE_KEY_RE_SUFFIX}',
        out,
    ).groupdict())
    assert source_key.packages_hash != target_key.packages_hash
    assert source_key.commands_hash == target_key.commands_hash

    assert are_two_images_on_registry_the_same(source, target)
    assert is_local_image_the_same_on_registry(source, target)