Beispiel #1
0
def test_main_no_docker_image(mock_load, mock_os):
    mock_os.environ = {'BUILD_DIST': 'build.dist'}
    mock_os.path.exists.return_value = True
    mock_result = Mock()
    mock_load.return_value = mock_result
    mock_result.xml_state.build_type.get_image.return_value = 'oci'
    main()
Beispiel #2
0
def test_main_no_build_service():
    exception = False
    try:
        main()
    except Exception as e:
        exception = True
        assert 'Not building inside build service' in str(e)
    assert exception
Beispiel #3
0
def test_main_no_kiwi_result(mock_os):
    mock_os.environ = {'BUILD_DIST': 'build.dist'}
    mock_os.path.exists.return_value = False
    exception = False
    try:
        main()
    except Exception as e:
        exception = True
        assert 'Kiwi result file not found' in str(e)
    assert exception
Beispiel #4
0
def test_main(mock_load, mock_move, mock_command, mock_template, mock_dump,
              mock_iterparse, mock_file, mock_os, mock_parser):
    mock_parser.return_value = {
        'RELEASE': '2.1',
        'BUILD_ARCH': 'x86_64',
        'DISTURL': 'obs://someurl',
        'RECIPEFILE': 'config.xml'
    }
    mock_os.environ = {'BUILD_DIST': 'build.dist'}
    mock_os.path.exists.return_value = True
    mock_result = Mock()
    mock_load.return_value = mock_result
    mock_result.xml_state.get_image_version.return_value = '1.2.3'
    mock_result.xml_state.xml_data.get_name.return_value = 'myimage'
    mock_result.xml_state.get_container_config.return_value = {
        'container_name': 'myname',
        'container_tag': 'mytag'
    }
    mock_result.xml_state.build_type.get_image.return_value = 'docker'
    main()
    mock_file.assert_called_once_with(
        '/usr/src/packages/SOURCES/myimage-metadata', 'w')
    mock_dump.assert_called_once_with({'myname': ['mytag']}, ANY)
    mock_command.assert_called_once_with([
        'rpmbuild', '--target', 'x86_64', '-ba', '--define',
        'disturl obs://someurl', '/usr/lib/build/myimage-metadata.spec'
    ])
    mock_template.assert_called_once_with(
        ANY, '/usr/lib/build/myimage-metadata.spec')
    assert mock_move.call_args_list == [
        call(('/usr/src/packages/RPMS/x86_64/'
              'myimage-metadata-1.2.3-2.1.x86_64.rpm'),
             '/usr/src/packages/OTHER'),
        call('/usr/src/packages/SRPMS/myimage-metadata-1.2.3-2.1.src.rpm',
             '/usr/src/packages/OTHER')
    ]
Beispiel #5
0
def test_main_no_build_data(mock_os):
    mock_os.environ = {'BUILD_DIST': 'build.dist'}
    mock_os.path.exists.side_effect = lambda x: (False if 'build.data' == x
                                                 else True)
    main()