Basic test passing
This commit is contained in:
parent
1e43c91d85
commit
21843c8b7f
|
@ -1,44 +1,36 @@
|
||||||
"""Generate test fixtures"""
|
"""Generate test fixtures"""
|
||||||
|
|
||||||
|
|
||||||
def containers(project="default", containers=None):
|
def containers(project="default", containers=[]):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
project (str): Name of the compose project
|
project (str): Name of the compose project
|
||||||
containers (dict):
|
containers (dict):
|
||||||
{
|
{
|
||||||
'containers: [
|
'containers: [
|
||||||
|
'service': 'service_name',
|
||||||
|
'mounts: [{
|
||||||
|
'Source': '/home/user/stuff',
|
||||||
|
'Destination': '/srv/stuff',
|
||||||
|
'Type': 'bind' / 'volume'
|
||||||
|
}],
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
return {
|
return [
|
||||||
|
{
|
||||||
'HostConfig': {'NetworkMode': 'restic-volume-backup_default'},
|
'HostConfig': {'NetworkMode': 'restic-volume-backup_default'},
|
||||||
'Id': '58d550e8f450129fa757820446e4021822a660918a61437e95115d3dc48ddde8',
|
'Id': '58d550e8f450129fa757820446e4021822a660918a61437e95115d3dc48ddde8',
|
||||||
'Image': 'restic-volume-backup_backup',
|
'Image': 'restic-volume-backup_backup',
|
||||||
'ImageID': 'sha256:4d9a81206af7d65563b85d06be160dc90dc20ade94edcf544261f0e1db4472b3',
|
'ImageID': 'sha256:4d9a81206af7d65563b85d06be160dc90dc20ade94edcf544261f0e1db4472b3',
|
||||||
'Labels': {
|
'Labels': {
|
||||||
'com.docker.compose.oneoff': 'True',
|
'com.docker.compose.oneoff': 'False',
|
||||||
'com.docker.compose.project': project,
|
'com.docker.compose.project': project,
|
||||||
'com.docker.compose.service': 'backup',
|
'com.docker.compose.service': container['service'],
|
||||||
|
**container.get('labels', {}),
|
||||||
},
|
},
|
||||||
'Mounts': [
|
'Mounts': container.get('mounts', []),
|
||||||
{
|
|
||||||
'Destination': '/restic-volume-backup',
|
|
||||||
'Mode': 'rw',
|
|
||||||
'RW': True,
|
|
||||||
'Source': '/Users/einarforselv/Documents/projects/contraz/restic-volume-backup',
|
|
||||||
'Type': 'bind',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'Destination': '/tmp/docker.sock',
|
|
||||||
'Mode': 'ro',
|
|
||||||
'RW': False,
|
|
||||||
'Source': '/var/run/docker.sock',
|
|
||||||
'Type': 'bind',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
'Names': ['/restic-volume-backup_backup_run_58d1699be0d8'],
|
'Names': ['/restic-volume-backup_backup_run_58d1699be0d8'],
|
||||||
'NetworkSettings': {
|
'NetworkSettings': {
|
||||||
'Networks': {
|
'Networks': {
|
||||||
|
@ -60,6 +52,7 @@ def containers(project="default", containers=None):
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'State': 'running',
|
'State': 'running',
|
||||||
},
|
}
|
||||||
|
for container in containers]
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
|
@ -1,15 +1,43 @@
|
||||||
|
import json
|
||||||
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
from restic_volume_backup import utils
|
from restic_volume_backup import utils
|
||||||
|
import fixtures
|
||||||
|
|
||||||
|
list_containers_func = 'restic_volume_backup.utils.list_containers'
|
||||||
|
|
||||||
def list_containers():
|
|
||||||
return {}
|
|
||||||
|
|
||||||
|
|
||||||
@mock.patch('restic_volume_backup.utils.list_containers', list_containers)
|
|
||||||
class ResticBackupTests(unittest.TestCase):
|
class ResticBackupTests(unittest.TestCase):
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
"""Set up basic enviroment variables"""
|
||||||
|
os.environ['RESTIC_REPOSITORY'] = "test"
|
||||||
|
os.environ['RESTIC_PASSWORD'] = "password"
|
||||||
|
|
||||||
def test_stuff(self):
|
def test_stuff(self):
|
||||||
assert utils.list_containers() == {}
|
containers = [
|
||||||
|
{
|
||||||
|
'service': 'web',
|
||||||
|
'labels': {
|
||||||
|
'moo': 1,
|
||||||
|
},
|
||||||
|
'mounts': [{
|
||||||
|
'Source': 'moo',
|
||||||
|
'Destination': 'moo',
|
||||||
|
'Type': 'bind',
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'service': 'mysql',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'service': 'postgres',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
with mock.patch(list_containers_func, fixtures.containers(containers=containers)):
|
||||||
|
test = utils.list_containers()
|
||||||
|
|
||||||
|
# raise ValueError(json.dumps(test, indent=2))
|
||||||
|
|
Loading…
Reference in New Issue