예제 #1
0
def test_check_repos_removed_previously(inspect_tag):
    """
    Test that a previously removed tag doesn't stay in the results.
    """
    old_data = {
        'example.com/repos/testrepo': {
            'latest': {
                'action': 'added',
                'repo': 'example.com/repos/testrepo',
                'reponame': 'testrepo',
                'tag': 'latest',
                'digest': INSPECT_DATA_1['Digest'],
                'old_digest': None,
                'created': format_time(INSPECT_DATA_1['Created']),
                'labels': INSPECT_DATA_1['Labels'],
                'os': INSPECT_DATA_1['Os'],
                'arch': INSPECT_DATA_1['Architecture'],
            },
            'stage': {
                'action': 'removed',
                'repo': 'example.com/repos/testrepo',
                'reponame': 'testrepo',
                'tag': 'stage',
                'digest': None,
                'old_digest': INSPECT_DATA_2['Digest'],
                'created': None,
                'labels': {},
                'os': None,
                'arch': None,
            }
        }
    }
    result = container.check_repos(CONF, old_data)
    inspect_tag.assert_called_once_with('example.com/repos/testrepo')
    assert result == {
        'example.com/repos/testrepo': {
            'latest': {
                'action': 'unchanged',
                'repo': 'example.com/repos/testrepo',
                'reponame': 'testrepo',
                'tag': 'latest',
                'digest': INSPECT_DATA_1['Digest'],
                'old_digest': None,
                'created': format_time(INSPECT_DATA_1['Created']),
                'labels': INSPECT_DATA_1['Labels'],
                'os': INSPECT_DATA_1['Os'],
                'arch': INSPECT_DATA_1['Architecture'],
            },
        }
    }
예제 #2
0
def test_check_repos_ghost(run):
    """
    Test that a tag that appeared in the RepoTags list, but no longer exists, and isn't present
    in the data from the previous run, results in the correct output.
    """
    run.side_effect = [
        Mock(returncode=0, stdout=json.dumps(INSPECT_DATA_1)),
        Mock(returncode=1, stderr='FATA[0001] Error reading manifest stage in example.com/repos/testrepo:'
             'manifest unknown: manifest unknown\n')
    ]
    old_data = {
        'example.com/repos/testrepo': {
            'latest': {
                'action': 'added',
                'repo': 'example.com/repos/testrepo',
                'reponame': 'testrepo',
                'tag': 'latest',
                'digest': INSPECT_DATA_1['Digest'],
                'old_digest': None,
                'created': format_time(INSPECT_DATA_1['Created']),
                'labels': INSPECT_DATA_1['Labels'],
                'os': INSPECT_DATA_1['Os'],
                'arch': INSPECT_DATA_1['Architecture'],
            },
        }
    }
    result = container.check_repos(CONF, old_data)
    assert run.call_count == 2
    assert result == {
        'example.com/repos/testrepo': {
            'latest': {
                'action': 'unchanged',
                'repo': 'example.com/repos/testrepo',
                'reponame': 'testrepo',
                'tag': 'latest',
                'digest': INSPECT_DATA_1['Digest'],
                'old_digest': None,
                'created': format_time(INSPECT_DATA_1['Created']),
                'labels': INSPECT_DATA_1['Labels'],
                'os': INSPECT_DATA_1['Os'],
                'arch': INSPECT_DATA_1['Architecture'],
            },
        }
    }
예제 #3
0
def test_check_repos_unchanged_ignore(inspect_tag):
    """
    Test that the 'ignore' flag is correctly ignored.
    """
    old_data = {
        'example.com/repos/testrepo': {
            'ignore': True,
            'latest': {
                'action': 'added',
                'repo': 'example.com/repos/testrepo',
                'reponame': 'testrepo',
                'tag': 'latest',
                'digest': INSPECT_DATA_1['Digest'],
                'old_digest': None,
                'created': format_time(INSPECT_DATA_1['Created']),
                'labels': INSPECT_DATA_1['Labels'],
                'os': INSPECT_DATA_1['Os'],
                'arch': INSPECT_DATA_1['Architecture'],
            }
        }
    }
    result = container.check_repos(CONF, old_data)
    inspect_tag.assert_called_once_with('example.com/repos/testrepo')
    assert result == {
        'example.com/repos/testrepo': {
            'latest': {
                'action': 'unchanged',
                'repo': 'example.com/repos/testrepo',
                'reponame': 'testrepo',
                'tag': 'latest',
                'digest': INSPECT_DATA_1['Digest'],
                'old_digest': None,
                'created': format_time(INSPECT_DATA_1['Created']),
                'labels': INSPECT_DATA_1['Labels'],
                'os': INSPECT_DATA_1['Os'],
                'arch': INSPECT_DATA_1['Architecture'],
            }
        }
    }
예제 #4
0
def gen_result(repo, tag, tagdata):
    """
    Generate a dict containing info about the specified repo.
    """
    return {
        'repo': repo,
        'reponame': repo.split('/')[-1],
        'tag': tag,
        'digest': tagdata.get('Digest'),
        'created': format_time(tagdata.get('Created')),
        'labels': tagdata.get('Labels', {}),
        'os': tagdata.get('Os'),
        'arch': tagdata.get('Architecture'),
    }
예제 #5
0
def test_format_time():
    """
    Test that format_time() formats datetime strings correctly.
    """
    assert utils.format_time('2019-04-23T16:41:13.304737955Z') == \
        '2019-04-23T16:41:13Z'
    assert utils.format_time('2019-04-23T16:41:13.0Z') == \
        '2019-04-23T16:41:13Z'
    assert utils.format_time('2019-04-23T16:41:13Z') == \
        '2019-04-23T16:41:13Z'
    assert utils.format_time('2019-04-23T16:41:13.304737955UTC') == \
        '2019-04-23T16:41:13UTC'
    assert utils.format_time('2019-04-23T16:41:13.0UTC') == \
        '2019-04-23T16:41:13UTC'
    assert utils.format_time('2019-04-23T16:41:13UTC') == \
        '2019-04-23T16:41:13UTC'
    assert utils.format_time('2019-04-23T16:41:13') == \
        '2019-04-23T16:41:13'
예제 #6
0
def test_check_repos_readded(inspect_tag):
    """
    Test that a repo that is readded immediately after it was removed results in
    a "added" message, and not an "updated" message.
    """
    old_data = {
        'example.com/repos/testrepo': {
            'latest': {
                'action': 'removed',
                'repo': 'example.com/repos/testrepo',
                'reponame': 'testrepo',
                'tag': 'latest',
                'digest': None,
                'old_digest': 'a1b2c3',
                'created': None,
                'labels': {},
                'os': None,
                'arch': None,
            }
        }
    }
    result = container.check_repos(CONF, old_data)
    inspect_tag.assert_called_once_with('example.com/repos/testrepo')
    assert result == {
        'example.com/repos/testrepo': {
            'latest': {
                'action': 'added',
                'repo': 'example.com/repos/testrepo',
                'reponame': 'testrepo',
                'tag': 'latest',
                'digest': INSPECT_DATA_1['Digest'],
                'old_digest': None,
                'created': format_time(INSPECT_DATA_1['Created']),
                'labels': INSPECT_DATA_1['Labels'],
                'os': INSPECT_DATA_1['Os'],
                'arch': INSPECT_DATA_1['Architecture'],
            }
        }
    }
예제 #7
0
def test_check_repos_added(inspect_tag):
    """
    Test that a new repo results in the correct output.
    """
    result = container.check_repos(CONF, {})
    inspect_tag.assert_called_once_with('example.com/repos/testrepo')
    assert result == {
        'example.com/repos/testrepo': {
            'latest': {
                'action': 'added',
                'repo': 'example.com/repos/testrepo',
                'reponame': 'testrepo',
                'tag': 'latest',
                'digest': INSPECT_DATA_1['Digest'],
                'old_digest': None,
                'created': format_time(INSPECT_DATA_1['Created']),
                'labels': INSPECT_DATA_1['Labels'],
                'os': INSPECT_DATA_1['Os'],
                'arch': INSPECT_DATA_1['Architecture'],
            }
        }
    }
예제 #8
0
def test_format_time_empty():
    """
    Test that format_time() handles empty values correctly.
    """
    assert utils.format_time(None) is None
    assert utils.format_time('') is None
예제 #9
0
def test_check_repos_removed_error(run):
    """
    Test that a tag that throws an error after initial inspection results in the correct output.
    """
    run.side_effect = [
        Mock(returncode=0, stdout=json.dumps(INSPECT_DATA_1)),
        Mock(returncode=1, stderr='FATA[0001] Error reading manifest stage in example.com/repos/testrepo:'
             'some other error\n')
    ]
    old_data = {
        'example.com/repos/testrepo': {
            'latest': {
                'action': 'added',
                'repo': 'example.com/repos/testrepo',
                'reponame': 'testrepo',
                'tag': 'latest',
                'digest': INSPECT_DATA_1['Digest'],
                'old_digest': None,
                'created': format_time(INSPECT_DATA_1['Created']),
                'labels': INSPECT_DATA_1['Labels'],
                'os': INSPECT_DATA_1['Os'],
                'arch': INSPECT_DATA_1['Architecture'],
            },
            'stage': {
                'action': 'added',
                'repo': 'example.com/repos/testrepo',
                'reponame': 'testrepo',
                'tag': 'stage',
                'digest': INSPECT_DATA_2['Digest'],
                'old_digest': None,
                'created': format_time(INSPECT_DATA_2['Created']),
                'labels': INSPECT_DATA_2['Labels'],
                'os': INSPECT_DATA_2['Os'],
                'arch': INSPECT_DATA_2['Architecture'],
            }
        }
    }
    result = container.check_repos(CONF, old_data)
    assert run.call_count == 2
    assert result == {
        'example.com/repos/testrepo': {
            'latest': {
                'action': 'unchanged',
                'repo': 'example.com/repos/testrepo',
                'reponame': 'testrepo',
                'tag': 'latest',
                'digest': INSPECT_DATA_1['Digest'],
                'old_digest': None,
                'created': format_time(INSPECT_DATA_1['Created']),
                'labels': INSPECT_DATA_1['Labels'],
                'os': INSPECT_DATA_1['Os'],
                'arch': INSPECT_DATA_1['Architecture'],
            },
            'stage': {
                'action': 'removed',
                'repo': 'example.com/repos/testrepo',
                'reponame': 'testrepo',
                'tag': 'stage',
                'digest': None,
                'old_digest': INSPECT_DATA_2['Digest'],
                'created': None,
                'labels': {},
                'os': None,
                'arch': None,
            }
        }
    }