Exemplo n.º 1
0
    def test_resolve_tag(self):
        '''
        Test the resolve_tag function. It runs docker.insect_image on the image
        name passed and then looks for the RepoTags key in the result
        '''
        id_ = 'sha256:6ad733544a6317992a6fac4eb19fe1df577d4dec7529efec28a5bd0edad0fd30'
        tags = ['foo:latest', 'foo:bar']
        mock_tagged = MagicMock(return_value={'Id': id_, 'RepoTags': tags})
        mock_untagged = MagicMock(return_value={'Id': id_, 'RepoTags': []})
        mock_unexpected = MagicMock(return_value={'Id': id_})
        mock_not_found = MagicMock(side_effect=CommandExecutionError())

        with patch.object(docker_mod, 'inspect_image', mock_tagged):
            self.assertEqual(docker_mod.resolve_tag('foo'), tags[0])
            self.assertEqual(docker_mod.resolve_tag('foo', all=True), tags)

        with patch.object(docker_mod, 'inspect_image', mock_untagged):
            self.assertEqual(docker_mod.resolve_tag('foo'), id_)
            self.assertEqual(docker_mod.resolve_tag('foo', all=True), [id_])

        with patch.object(docker_mod, 'inspect_image', mock_unexpected):
            self.assertEqual(docker_mod.resolve_tag('foo'), id_)
            self.assertEqual(docker_mod.resolve_tag('foo', all=True), [id_])

        with patch.object(docker_mod, 'inspect_image', mock_not_found):
            self.assertIs(docker_mod.resolve_tag('foo'), False)
            self.assertIs(docker_mod.resolve_tag('foo', all=True), False)
Exemplo n.º 2
0
def test_resolve_tag():
    """
    Test the resolve_tag function. It runs docker.insect_image on the image
    name passed and then looks for the RepoTags key in the result
    """
    id_ = "sha256:6ad733544a6317992a6fac4eb19fe1df577d4dec7529efec28a5bd0edad0fd30"
    tags = ["foo:latest", "foo:bar"]
    mock_tagged = MagicMock(return_value={"Id": id_, "RepoTags": tags})
    mock_untagged = MagicMock(return_value={"Id": id_, "RepoTags": []})
    mock_unexpected = MagicMock(return_value={"Id": id_})
    mock_not_found = MagicMock(side_effect=CommandExecutionError())

    with patch.object(docker_mod, "inspect_image", mock_tagged):
        assert docker_mod.resolve_tag("foo") == tags[0]
        assert docker_mod.resolve_tag("foo", all=True) == tags

    with patch.object(docker_mod, "inspect_image", mock_untagged):
        assert docker_mod.resolve_tag("foo") == id_
        assert docker_mod.resolve_tag("foo", all=True) == [id_]

    with patch.object(docker_mod, "inspect_image", mock_unexpected):
        assert docker_mod.resolve_tag("foo") == id_
        assert docker_mod.resolve_tag("foo", all=True) == [id_]

    with patch.object(docker_mod, "inspect_image", mock_not_found):
        assert docker_mod.resolve_tag("foo") is False
        assert docker_mod.resolve_tag("foo", all=True) is False
Exemplo n.º 3
0
    def test_resolve_tag(self):
        '''
        Test the resolve_tag function
        '''
        with_prefix = 'docker.io/foo:latest'
        no_prefix = 'bar:latest'
        with patch.object(docker_mod, 'list_tags',
                          MagicMock(return_value=[with_prefix])):
            self.assertEqual(docker_mod.resolve_tag('foo'), with_prefix)
            self.assertEqual(docker_mod.resolve_tag('foo:latest'), with_prefix)
            self.assertEqual(docker_mod.resolve_tag(with_prefix), with_prefix)
            self.assertEqual(docker_mod.resolve_tag('foo:bar'), False)

        with patch.object(docker_mod, 'list_tags',
                          MagicMock(return_value=[no_prefix])):
            self.assertEqual(docker_mod.resolve_tag('bar'), no_prefix)
            self.assertEqual(docker_mod.resolve_tag(no_prefix), no_prefix)
            self.assertEqual(docker_mod.resolve_tag('bar:baz'), False)