Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_server.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import copy | |||||
import pytest | import pytest | ||||
import yaml | import yaml | ||||
from swh.storage.api.server import load_and_check_config | from swh.storage.api.server import load_and_check_config | ||||
def prepare_config_file(tmpdir, content, name='config.yml'): | def prepare_config_file(tmpdir, content, name='config.yml'): | ||||
"""Prepare configuration file in `$tmpdir/name` with content `content`. | """Prepare configuration file in `$tmpdir/name` with content `content`. | ||||
Show All 36 Lines | def test_load_and_check_config_wrong_configuration(tmpdir): | ||||
"""Wrong configuration raises""" | """Wrong configuration raises""" | ||||
config_path = prepare_config_file(tmpdir, 'something: useless') | config_path = prepare_config_file(tmpdir, 'something: useless') | ||||
with pytest.raises(KeyError) as e: | with pytest.raises(KeyError) as e: | ||||
load_and_check_config(config_path) | load_and_check_config(config_path) | ||||
assert e.value.args[0] == 'Missing \'%storage\' configuration' | assert e.value.args[0] == 'Missing \'%storage\' configuration' | ||||
def test_load_and_check_config_remote_config_local_type_raise(tmpdir): | |||||
"""'local' configuration without 'local' storage raises""" | |||||
config = { | |||||
'storage': { | |||||
'cls': 'remote', | |||||
'args': {} | |||||
} | |||||
} | |||||
config_path = prepare_config_file(tmpdir, config) | |||||
with pytest.raises(ValueError) as e: | |||||
load_and_check_config(config_path, type='local') | |||||
assert ( | |||||
e.value.args[0] == | |||||
"The storage backend can only be started with a 'local' configuration" | |||||
) | |||||
def test_load_and_check_config_local_incomplete_configuration(tmpdir): | |||||
"""Incomplete 'local' configuration should raise""" | |||||
config = { | |||||
'storage': { | |||||
'cls': 'local', | |||||
'args': { | |||||
'db': 'database', | |||||
'objstorage': 'object_storage' | |||||
} | |||||
} | |||||
} | |||||
for key in ('db', 'objstorage'): | |||||
c = copy.deepcopy(config) | |||||
c['storage']['args'].pop(key) | |||||
config_path = prepare_config_file(tmpdir, c) | |||||
with pytest.raises(ValueError) as e: | |||||
load_and_check_config(config_path) | |||||
assert ( | |||||
e.value.args[0] == | |||||
"Invalid configuration; missing '%s' config entry" % key | |||||
) | |||||
def test_load_and_check_config_local_config_fine(tmpdir): | def test_load_and_check_config_local_config_fine(tmpdir): | ||||
"""'Remote configuration is fine""" | """'Remote configuration is fine""" | ||||
config = { | config = { | ||||
'storage': { | 'storage': { | ||||
'cls': 'local', | 'cls': 'local', | ||||
'args': { | 'args': { | ||||
'db': 'db', | 'db': 'db', | ||||
'objstorage': 'something', | 'objstorage': 'something', | ||||
Show All 20 Lines |