Extend tests
This commit is contained in:
parent
fb14d65878
commit
5a8411c822
|
@ -4,10 +4,12 @@ import unittest
|
|||
from unittest import mock
|
||||
|
||||
from restic_volume_backup import utils
|
||||
from restic_volume_backup.containers import RunningContainers
|
||||
import fixtures
|
||||
|
||||
list_containers_func = 'restic_volume_backup.utils.list_containers'
|
||||
|
||||
|
||||
class ResticBackupTests(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
|
@ -16,7 +18,18 @@ class ResticBackupTests(unittest.TestCase):
|
|||
os.environ['RESTIC_REPOSITORY'] = "test"
|
||||
os.environ['RESTIC_PASSWORD'] = "password"
|
||||
|
||||
def test_stuff(self):
|
||||
def createContainers(self):
|
||||
backup_hash = fixtures.generate_sha256()
|
||||
os.environ['HOSTNAME'] = backup_hash[:8]
|
||||
return [
|
||||
{
|
||||
'id': backup_hash,
|
||||
'service': 'backup',
|
||||
}
|
||||
]
|
||||
|
||||
def test_list_containers(self):
|
||||
"""Test a basic container list"""
|
||||
containers = [
|
||||
{
|
||||
'service': 'web',
|
||||
|
@ -40,4 +53,59 @@ class ResticBackupTests(unittest.TestCase):
|
|||
with mock.patch(list_containers_func, fixtures.containers(containers=containers)):
|
||||
test = utils.list_containers()
|
||||
|
||||
# raise ValueError(json.dumps(test, indent=2))
|
||||
def test_running_containers(self):
|
||||
containers = self.createContainers()
|
||||
containers += [
|
||||
{
|
||||
'service': 'web',
|
||||
'labels': {
|
||||
'test': 'test',
|
||||
},
|
||||
'mounts': [{
|
||||
'Source': 'test',
|
||||
'Destination': 'test',
|
||||
'Type': 'bind',
|
||||
}]
|
||||
},
|
||||
{
|
||||
'service': 'mysql',
|
||||
},
|
||||
{
|
||||
'service': 'postgres',
|
||||
},
|
||||
]
|
||||
with mock.patch(list_containers_func, fixtures.containers(containers=containers)):
|
||||
result = RunningContainers()
|
||||
self.assertEqual(len(result.containers), 3, msg="Three containers expected")
|
||||
self.assertNotEqual(result.this_container, None, msg="No backup container found")
|
||||
|
||||
def test_include(self):
|
||||
containers = self.createContainers()
|
||||
containers += [
|
||||
{
|
||||
'service': 'web',
|
||||
'labels': {
|
||||
'restic-volume-backup.include': 'media',
|
||||
},
|
||||
'mounts': [
|
||||
{
|
||||
'Source': '/srv/files/media',
|
||||
'Destination': '/srv/media',
|
||||
'Type': 'bind',
|
||||
},
|
||||
{
|
||||
'Source': '/srv/files/stuff',
|
||||
'Destination': '/srv/stuff',
|
||||
'Type': 'bind',
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
with mock.patch(list_containers_func, fixtures.containers(containers=containers)):
|
||||
cnt = RunningContainers()
|
||||
web_service = cnt.get_service('web')
|
||||
self.assertNotEqual(web_service, None, msg="Web service not found")
|
||||
|
||||
|
||||
def test_exclude(self):
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue