forked from cloudlinux/kuberdock-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_backup_node_merge.py
57 lines (49 loc) · 2.43 KB
/
test_backup_node_merge.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# KuberDock - is a platform that allows users to run applications using Docker
# container images and create SaaS / PaaS based on these applications.
# Copyright (C) 2017 Cloud Linux INC
#
# This file is part of KuberDock.
#
# KuberDock is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# KuberDock is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with KuberDock; if not, see <http://www.gnu.org/licenses/>.
from backup_node_merge import group_by_timestamp, MergeError
from tests_integration.lib.integration_test_utils import assert_raises, assert_eq
def test_grouping():
data = ["local_pv_backup_2016-09-22T05:01:00.0000",
"local_pv_backup_2016-09-22T05:02:00.0000",
"local_pv_backup_2016-09-22T07:01:00.0000",
"local_pv_backup_2016-09-22T07:02:00.0000",
"local_pv_backup_2016-09-22T09:01:00.0000",
"local_pv_backup_2016-09-22T09:02:00.0000",
"local_pv_backup_2016-09-22T11:01:00.0000",
"local_pv_backup_2016-09-22T11:02:00.0000",
]
g1, g2, g3, g4 = list(group_by_timestamp(data, 3600))
assert g1 == ['local_pv_backup_2016-09-22T05:01:00.0000',
'local_pv_backup_2016-09-22T05:02:00.0000']
assert g2 == ['local_pv_backup_2016-09-22T07:01:00.0000',
'local_pv_backup_2016-09-22T07:02:00.0000']
assert g3 == ['local_pv_backup_2016-09-22T09:01:00.0000',
'local_pv_backup_2016-09-22T09:02:00.0000']
assert g4 == ['local_pv_backup_2016-09-22T11:01:00.0000',
'local_pv_backup_2016-09-22T11:02:00.0000']
def test_grouping_raises():
data = ["local_pv_backup",
"local_pv_backup_2016-09-22T05:02:00.0000"]
with assert_raises(MergeError):
list(group_by_timestamp(data, 3600))
def test_grouping_skipping_raises():
data = ["local_pv_backup",
"local_pv_backup_2016-09-22T05:02:00.0000"]
g1, = list(group_by_timestamp(data, 3600, skip_errors=True))
assert g1 == ['local_pv_backup_2016-09-22T05:02:00.0000']