コード例 #1
0
def test_is_docker_image_latest_tag_without_tag():
    """
   Given
   - A latest docker image has an empty tag

   When
   - The most updated docker image in docker-hub is '1.0.3'

   Then
   -  If the docker image is numeric and the most update one, it is Valid
   -  If the docker image is not numeric and labeled "latest", it is Invalid
  """
    with mock.patch.object(DockerImageValidator, '__init__',
                           lambda x, y, z, w: None):
        docker_image_validator = DockerImageValidator(None, None, None)
        docker_image_validator.yml_file = {}
        docker_image_validator.ignored_errors = {}
        docker_image_validator.file_path = "path"
        docker_image_validator.docker_image_latest_tag = ''
        docker_image_validator.docker_image_name = 'demisto/python'
        docker_image_validator.code_type = 'python'
        docker_image_validator.suppress_print = False

        docker_image_validator.is_latest_tag = True
        docker_image_validator.docker_image_tag = '1.0.2'
        docker_image_validator.is_valid = True

        assert docker_image_validator.is_docker_image_latest_tag() is False
        assert docker_image_validator.is_latest_tag is False
        assert docker_image_validator.is_docker_image_valid() is False
コード例 #2
0
def test_is_docker_image_latest_tag_with_default_image():
    """
    Given
    - The default docker image - 'demisto/python:1.3-alpine'

    When
    - The most updated docker image in docker-hub is '1.0.3'

    Then
    -  If the docker image is numeric and the most update one, it is Valid
    -  If the docker image is not numeric and labeled "latest", it is Invalid
   """
    with mock.patch.object(DockerImageValidator, '__init__',
                           lambda x, y, z, w: None):
        docker_image_validator = DockerImageValidator(None, None, None)
        docker_image_validator.yml_file = {}
        docker_image_validator.file_path = "PATH"
        docker_image_validator.ignored_errors = {}
        docker_image_validator.code_type = 'python'
        docker_image_validator.checked_files = set()
        docker_image_validator.docker_image_latest_tag = '1.0.3'
        docker_image_validator.docker_image_name = 'demisto/python'
        docker_image_validator.suppress_print = False

        docker_image_validator.is_latest_tag = True
        docker_image_validator.is_modified_file = False
        docker_image_validator.docker_image_tag = '1.3-alpine'
        docker_image_validator.is_valid = True

        assert docker_image_validator.is_docker_image_latest_tag() is False
        assert docker_image_validator.is_latest_tag is False
        assert docker_image_validator.is_docker_image_valid() is False
コード例 #3
0
def test_is_docker_image_latest_tag_with_tag_labeled_latest():
    """
    Given
    - A docker image with "latest" as tag

    When
    - The most updated docker image in docker-hub is '1.0.3'

    Then
    -  If the docker image is numeric and the most update one, it is Valid
    -  If the docker image is not numeric and labeled "latest", it is Invalid
   """
    with mock.patch.object(DockerImageValidator, '__init__',
                           lambda x, y, z, w: None):
        docker_image_validator = DockerImageValidator(None, None, None)
        docker_image_validator.yml_file = {}
        docker_image_validator.docker_image_latest_tag = 'latest'
        docker_image_validator.docker_image_name = 'demisto/python'

        docker_image_validator.is_latest_tag = True
        docker_image_validator.is_valid = True
        docker_image_validator.docker_image_tag = 'latest'

        assert docker_image_validator.is_docker_image_latest_tag() is False
        assert docker_image_validator.is_latest_tag is False
        assert docker_image_validator.is_docker_image_valid() is False
コード例 #4
0
def test_is_docker_image_latest_tag_with_numeric_but_not_most_updated():
    """
   Given
   - A docker image with '1.0.2' as tag

   When
   - The most updated docker image in docker-hub is '1.0.3'

   Then
   -  If the docker image is numeric and the most update one, it is Valid
   -  If the docker image is not numeric and labeled "latest", it is Invalid
   - If the docker image is not the most updated one it is still valid
        (however, a warning will be printed)
  """
    with mock.patch.object(DockerImageValidator, '__init__',
                           lambda x, y, z, w: None):
        docker_image_validator = DockerImageValidator(None, None, None)
        docker_image_validator.yml_file = {}
        docker_image_validator.docker_image_latest_tag = '1.0.3'
        docker_image_validator.docker_image_name = 'demisto/python'

        docker_image_validator.is_latest_tag = True
        docker_image_validator.docker_image_tag = '1.0.2'
        docker_image_validator.is_valid = True

        assert docker_image_validator.is_docker_image_latest_tag() is True
        assert docker_image_validator.is_latest_tag is True
        assert docker_image_validator.is_docker_image_valid() is True
コード例 #5
0
ファイル: docker_test.py プロジェクト: oylosoar/demisto-sdk
def test_is_docker_image_latest_tag_with_numeric_but_not_most_updated():
    """
   Given
   - A docker image with '1.0.2' as tag

   When
   - The most updated docker image in docker-hub is '1.0.3'

   Then
   -  If the docker image is numeric and the most update one, it is Valid
   -  If the docker image is not numeric and labeled "latest", it is Invalid
   - If the docker image is not the most updated one it is invalid
  """
    with mock.patch.object(DockerImageValidator, '__init__',
                           lambda x, y, z, w: None):
        docker_image_validator = DockerImageValidator(None, None, None)
        docker_image_validator.yml_file = {}
        docker_image_validator.ignored_errors = {}
        docker_image_validator.file_path = "path"
        docker_image_validator.docker_image_latest_tag = '1.0.3'
        docker_image_validator.docker_image_name = 'demisto/python'
        docker_image_validator.code_type = 'python'
        docker_image_validator.checked_files = set()

        docker_image_validator.is_latest_tag = True
        docker_image_validator.docker_image_tag = '1.0.2'
        docker_image_validator.is_valid = True

        assert docker_image_validator.is_docker_image_latest_tag() is False
        assert docker_image_validator.is_latest_tag is False
        assert docker_image_validator.is_docker_image_valid() is False