-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gluster_bridge: Testcases for gluster bridge
Signed-off-by: GowthamShanmugam <gshanmug@redhat.com>
- Loading branch information
1 parent
fa19bed
commit 2e76a86
Showing
16 changed files
with
661 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from mock import MagicMock | ||
import pytest | ||
from tendrl.gluster_bridge import config | ||
|
||
|
||
class TestTendrlconfig(object): | ||
def setup_method(self, method): | ||
config.os.path.exists = MagicMock(return_value=True) | ||
|
||
def test_with_default_path(self): | ||
config.TendrlConfig() | ||
config.os.path.exists.assert_called_with( | ||
"/etc/tendrl/tendrl.conf" | ||
) | ||
|
||
def test_with_config_path(self, monkeypatch): | ||
monkeypatch.setattr(config.os, 'environ', {"TENDRL_CONFIG": "/temp/"}) | ||
config.TendrlConfig() | ||
config.os.path.exists.assert_called_with( | ||
"/temp/" | ||
) | ||
|
||
def test_with_path_exist_error(self): | ||
config.TendrlConfig() | ||
config.os.path.exists = MagicMock(return_value=False) | ||
with pytest.raises(config.ConfigNotFound): | ||
config.TendrlConfig() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import gevent.queue | ||
from gevent import sleep | ||
import pytest | ||
from tendrl.gluster_bridge import gevent_util | ||
|
||
|
||
def test_nosleep_mgr(): | ||
test_nosleep_method1() | ||
with pytest.raises(gevent_util.ForbiddenYield): | ||
raise test_nosleep_method2() | ||
test_nosleep_method3() | ||
with pytest.raises(gevent_util.ForbiddenYield): | ||
raise test_nosleep_method4() | ||
setattr(gevent_util.getcurrent(), 'switch_out', "pytest") | ||
test_nosleep_method1() | ||
assert gevent_util.getcurrent().switch_out == "pytest" | ||
|
||
|
||
# This should raise no exception (print doesn't yield) | ||
@gevent_util.nosleep | ||
def test_nosleep_method1(): | ||
print("test print!") | ||
|
||
|
||
# This should raise an exception when we try push to a fixed size queue | ||
@gevent_util.nosleep | ||
def test_nosleep_method2(): | ||
smallq = gevent.queue.Queue(1) | ||
try: | ||
smallq.put(1) | ||
smallq.put(2) | ||
except gevent_util.ForbiddenYield as ex: | ||
return ex | ||
|
||
|
||
# This should raise no exception when we try push to an unlimited | ||
# size queue | ||
@gevent_util.nosleep | ||
def test_nosleep_method3(): | ||
bigq = gevent.queue.Queue(0) | ||
for i in range(0, 10000): | ||
bigq.put(i) | ||
|
||
|
||
# This should raise an exception on sleep | ||
@gevent_util.nosleep | ||
def test_nosleep_method4(): | ||
try: | ||
sleep(0.1) | ||
except gevent_util.ForbiddenYield as ex: | ||
return ex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,41 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
|
||
""" | ||
test_gluster_bridge | ||
---------------------------------- | ||
Tests for `gluster_bridge` module. | ||
""" | ||
from mock import MagicMock | ||
import os | ||
import shutil | ||
import sys | ||
import tempfile | ||
sys.modules['tendrl.gluster_bridge.config'] = MagicMock() | ||
sys.modules['tendrl.gluster_bridge.manager.rpc'] = MagicMock() | ||
sys.modules['tendrl.gluster_bridge.persistence.persister'] = MagicMock() | ||
sys.modules['logging'] = MagicMock() | ||
from tendrl.gluster_bridge.manager import manager | ||
del sys.modules['tendrl.gluster_bridge.manager.rpc'] | ||
del sys.modules['tendrl.gluster_bridge.persistence.persister'] | ||
del sys.modules['logging'] | ||
del sys.modules['tendrl.gluster_bridge.config'] | ||
|
||
from tendrl.gluster_bridge.tests import base | ||
|
||
class TestGluster_bridge(object): | ||
def setup_method(self, method): | ||
manager.gevent.sleep = MagicMock() | ||
manager.Peer = MagicMock() | ||
manager.Brick = MagicMock() | ||
manager.Volume = MagicMock() | ||
manager.log = MagicMock() | ||
self.managerobj = manager.Manager() | ||
self.Manager = manager | ||
self.tempdir = tempfile.mkdtemp() | ||
|
||
class TestGluster_bridge(base.TestCase): | ||
def teardown_method(self, method): | ||
shutil.rmtree(self.tempdir) | ||
|
||
def test_something(self): | ||
assert True | ||
def _makeFile(self, filename, text): | ||
filename = os.path.join(self.tempdir, filename) | ||
f = open(filename, 'w') | ||
f.write(text) | ||
return filename |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
from mock import MagicMock | ||
import pytest | ||
from tendrl.gluster_bridge import ini2json | ||
from tendrl.gluster_bridge.tests.test_gluster_bridge import TestGluster_bridge | ||
|
||
|
||
class Test_StrictConfigParser(TestGluster_bridge): | ||
|
||
def test_parse_empty_nodefaults(self): | ||
filename = self._makeFile('empty', '') | ||
sections = ini2json.ini_to_dict(filename) | ||
assert sections == {} | ||
|
||
def test_parse_empty_with_comment_line(self): | ||
body = """# empty with comment line""" | ||
filename = self._makeFile('pytest', body) | ||
sections = ini2json.ini_to_dict(filename) | ||
assert sections == {} | ||
|
||
def test_parse_empty_no_leading_whitespace(self): | ||
body = """rem ember_last = True""" | ||
filename = self._makeFile('pytest', body) | ||
sections = ini2json.ini_to_dict(filename) | ||
assert sections == {} | ||
|
||
def test_parse_duplicate_section(self): | ||
body = """[foo]\na=1\n[foo]\nbar=1\nbaz=2""" | ||
filename = self._makeFile('pytest', body) | ||
with pytest.raises(ValueError): | ||
ini2json.ini_to_dict(filename) | ||
|
||
def test_parse_continuation_line(self): | ||
body = """[foo]\nbar:1 2 jammy:jam\n foo bar\n boo""" | ||
filename = self._makeFile('pytest', body) | ||
sections = ini2json.ini_to_dict(filename) | ||
assert sections == ( | ||
{'foo': {'bar': ['1', '2', 'jammy:jam', 'foo', 'bar', 'boo']}} | ||
) | ||
|
||
def test_parse_(self): | ||
body = """[foo]\na=1\n[memo]\n bar=1\nbaz=2""" | ||
filename = self._makeFile('pytest', body) | ||
with pytest.raises(ini2json.ParsingError): | ||
ini2json.ini_to_dict(filename) | ||
|
||
def test_parse_body_default(self): | ||
body = """[foo]\nbar=1\nbaz=2"\n[DEFAULT]\na=1""" | ||
filename = self._makeFile('pytest', body) | ||
sections = ini2json.ini_to_dict(filename) | ||
assert sections == ( | ||
{'foo': {'a': '1', 'bar': '1', 'baz': '2"'}} | ||
) | ||
|
||
def test_parse_missing_section(self): | ||
body = """\nbar=1\nbaz=2"\n[DEFAULT]\na=1i""" | ||
filename = self._makeFile('pytest', body) | ||
with pytest.raises(ini2json.MissingSectionHeaderError): | ||
ini2json.ini_to_dict(filename) | ||
|
||
def test_parse_with_tokens(self): | ||
body = """[foo]\nbar: 1 2 3 4 jammy:jam\n""" | ||
filename = self._makeFile('pytest', body) | ||
sections = ini2json.ini_to_dict(filename) | ||
assert sections == ( | ||
{'foo': {'bar': ['1', '2', '3', '4', 'jammy:jam']}} | ||
) | ||
|
||
def test_parse_with_bad_format(self): | ||
body = """[foo]\nbar: 1 ;\n 2 3 4 jammy:jam\n""" | ||
filename = self._makeFile('pytest', body) | ||
sections = ini2json.ini_to_dict(filename) | ||
assert sections == ( | ||
{'foo': {'bar': ['1', '2', '3', '4', 'jammy:jam']}} | ||
) | ||
|
||
def test_parse_without_token(self): | ||
body = """[foo]\nbar:\n""" | ||
filename = self._makeFile('pytest', body) | ||
sections = ini2json.ini_to_dict(filename) | ||
assert sections == ( | ||
{'foo': {'bar': ''}} | ||
) | ||
|
||
def test_parse_without_space(self): | ||
body = """[foo]\nbar:""\n""" | ||
filename = self._makeFile('pytest', body) | ||
sections = ini2json.ini_to_dict(filename) | ||
assert sections == ( | ||
{'foo': {'bar': ''}} | ||
) | ||
|
||
def test_dget_with_dummy_section(self): | ||
self.strict_config_parser = ini2json.StrictConfigParser() | ||
assert self.strict_config_parser.dget("pytest", 1, 12345) == 12345 | ||
|
||
def test_dget_with_type_str(self): | ||
self.strict_config_parser = ini2json.StrictConfigParser() | ||
self.strict_config_parser.has_option = MagicMock(return_value=True) | ||
self.strict_config_parser.get = MagicMock(return_value="str called") | ||
assert self.strict_config_parser.dget( | ||
"pytest", 1, 12345, str) == "str called" | ||
|
||
def test_dget_with_type_int(self): | ||
self.strict_config_parser = ini2json.StrictConfigParser() | ||
self.strict_config_parser.has_option = MagicMock(return_value=True) | ||
self.strict_config_parser.getint = MagicMock( | ||
return_value="int called") | ||
assert self.strict_config_parser.dget( | ||
"pytest", 1, 12345, int) == "int called" | ||
|
||
def test_dget_with_type_bool(self): | ||
self.strict_config_parser = ini2json.StrictConfigParser() | ||
self.strict_config_parser.has_option = MagicMock(return_value=True) | ||
self.strict_config_parser.getboolean = MagicMock( | ||
return_value="bool called") | ||
assert self.strict_config_parser.dget( | ||
"pytest", 1, 12345, bool) == "bool called" | ||
|
||
def test_dget_with_not_implemented_type(self): | ||
self.strict_config_parser = ini2json.StrictConfigParser() | ||
self.strict_config_parser.has_option = MagicMock(return_value=True) | ||
with pytest.raises(NotImplementedError): | ||
assert self.strict_config_parser.dget("pytest", 1, 12345, float) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from mock import MagicMock | ||
import sys | ||
sys.modules['logging'] = MagicMock() | ||
sys.modules['tendrl.gluster_bridge.config'] = MagicMock() | ||
from tendrl.gluster_bridge import log | ||
del sys.modules['tendrl.gluster_bridge.config'] | ||
del sys.modules['logging'] | ||
|
||
|
||
class Test_log(object): | ||
def test_log(self): | ||
log.root = None | ||
log.setup_logging() | ||
log.logging.getLogger.assert_called_with('tendrl.gluster_bridge.log') |
Oops, something went wrong.