mirror of
https://github.com/ggogel/seafile-containerized.git
synced 2025-09-02 18:59:19 +00:00
Added unit tests for auto upgrade logic
This commit is contained in:
parent
7b76411537
commit
a1d1369680
8 changed files with 62 additions and 3 deletions
|
@ -5,8 +5,8 @@ services:
|
||||||
- docker
|
- docker
|
||||||
|
|
||||||
install:
|
install:
|
||||||
# Must put something here, or travis would ask us for requirments.txt
|
- pip install -r ci/requirements.txt
|
||||||
- echo "Nothing to install"
|
|
||||||
|
|
||||||
script:
|
script:
|
||||||
|
- ./run-tests.sh
|
||||||
- ci/ci.sh
|
- ci/ci.sh
|
||||||
|
|
2
ci/requirements.txt
Normal file
2
ci/requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
pytest==3.7.1
|
||||||
|
mock==2.0.0
|
3
pytest.ini
Normal file
3
pytest.ini
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
[pytest]
|
||||||
|
addopts = -vv -s
|
||||||
|
log_format = %(asctime)s:%(name)s:%(levelname)s:%(message)s
|
10
run-tests.sh
Executable file
10
run-tests.sh
Executable file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
cd "$( dirname "${BASH_SOURCE[0]}" )"
|
||||||
|
|
||||||
|
export PYTHONPATH=$PWD/scripts:$PYTHONPATH
|
||||||
|
# This env is required by all the scripts
|
||||||
|
export SEAFILE_VERSION=$(cat image/seafile/Dockerfile | sed -r -n 's/.*SEAFILE_VERSION=([0-9.]+).*/\1/p')
|
||||||
|
pytest tests/unit
|
|
@ -57,6 +57,10 @@ def run_script_and_update_version_stamp(script, new_version):
|
||||||
call(script)
|
call(script)
|
||||||
update_version_stamp(new_version)
|
update_version_stamp(new_version)
|
||||||
|
|
||||||
|
def is_minor_upgrade(v1, v2):
|
||||||
|
get_major_version = lambda x: x.split('.')[:2]
|
||||||
|
return v1 != v2 and get_major_version(v1) == get_major_version(v2)
|
||||||
|
|
||||||
def check_upgrade():
|
def check_upgrade():
|
||||||
last_version = read_version_stamp()
|
last_version = read_version_stamp()
|
||||||
current_version = os.environ['SEAFILE_VERSION']
|
current_version = os.environ['SEAFILE_VERSION']
|
||||||
|
@ -67,7 +71,7 @@ def check_upgrade():
|
||||||
run_script_and_update_version_stamp(minor_upgrade_script, current_version)
|
run_script_and_update_version_stamp(minor_upgrade_script, current_version)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Now we do the major upgrade
|
||||||
scripts_to_run = collect_upgrade_scripts(from_version=last_version, to_version=current_version)
|
scripts_to_run = collect_upgrade_scripts(from_version=last_version, to_version=current_version)
|
||||||
for script in scripts_to_run:
|
for script in scripts_to_run:
|
||||||
loginfo('Running scripts {}'.format(script))
|
loginfo('Running scripts {}'.format(script))
|
||||||
|
|
0
tests/unit/__init__.py
Normal file
0
tests/unit/__init__.py
Normal file
8
tests/unit/conftest.py
Normal file
8
tests/unit/conftest.py
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from os.path import abspath, basename, exists, dirname, join
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
project_dir = join(dirname(abspath(__file__)), '../..')
|
||||||
|
scripts_dir = join(project_dir, 'scrpits')
|
32
tests/unit/test_upgrade.py
Normal file
32
tests/unit/test_upgrade.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import glob
|
||||||
|
from os.path import abspath, basename, exists, dirname, join
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from mock import patch
|
||||||
|
|
||||||
|
from upgrade import is_minor_upgrade, collect_upgrade_scripts
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("v1, v2, result", [
|
||||||
|
('6.3.0', '6.3.0', False),
|
||||||
|
('6.3.0', '6.3.1', True),
|
||||||
|
('6.3.0', '6.4.0', False),
|
||||||
|
('6.3.1', '6.4.0', False),
|
||||||
|
('6.4.0', '6.3.0', False),
|
||||||
|
])
|
||||||
|
def test_minor_upgrade(v1, v2, result):
|
||||||
|
assert is_minor_upgrade(v1, v2) == result
|
||||||
|
|
||||||
|
|
||||||
|
def test_collect_upgrade_scripts():
|
||||||
|
files = [
|
||||||
|
'upgrade_4.4_5.0.sh',
|
||||||
|
'upgrade_5.0_5.1.sh',
|
||||||
|
'upgrade_5.1_6.0.sh',
|
||||||
|
'upgrade_6.0_6.1.sh',
|
||||||
|
]
|
||||||
|
def fake_glob(pattern):
|
||||||
|
return [join(dirname(pattern), f) for f in files]
|
||||||
|
def _basename(files):
|
||||||
|
return [basename(f) for f in files]
|
||||||
|
with patch.object(glob, 'glob', fake_glob):
|
||||||
|
assert _basename(collect_upgrade_scripts('5.0.1', '6.1.0')) == files[1:]
|
Loading…
Add table
Reference in a new issue