-
-
Save andrewschoen/8ebdb961ed4b1fa5dd7c to your computer and use it in GitHub Desktop.
patch to add test coverage to teuthology.orchestra.cluster.write_file
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
diff --git a/teuthology/orchestra/test/test_cluster.py b/teuthology/orchestra/test/test_cluster.py | |
index 7596583..6a3f678 100644 | |
--- a/teuthology/orchestra/test/test_cluster.py | |
+++ b/teuthology/orchestra/test/test_cluster.py | |
@@ -1,4 +1,7 @@ | |
import fudge | |
+import pytest | |
+ | |
+from mock import patch | |
from .. import cluster, remote | |
@@ -204,3 +207,25 @@ class TestCluster(object): | |
) | |
c_foo = c.exclude('foo', lambda role: role.startswith('b')) | |
assert c_foo.remotes == {r2: ['bar'], r3: ['foo']} | |
+ | |
+ @fudge.with_fakes | |
+ @patch("teuthology.misc.write_file") | |
+ @patch("teuthology.misc.sudo_write_file") | |
+ def test_write_file(self, m_sudo_write_file, m_write_file): | |
+ fudge.clear_expectations() | |
+ r1 = remote.Remote('r1', ssh=fudge.Fake('SSH')) | |
+ c = cluster.Cluster( | |
+ remotes=[ | |
+ (r1, ['foo', 'bar']), | |
+ ], | |
+ ) | |
+ c.write_file("filename", "content", sudo=True) | |
+ assert m_sudo_write_file.called | |
+ m_sudo_write_file.assert_called_with(r1, "filename", "content", None) | |
+ with pytest.raises(ValueError): | |
+ c.write_file("filename", "content", sudo=False, perms="perms") | |
+ c.write_file("filename", "content") | |
+ assert m_write_file.called | |
+ m_write_file.assert_called_with(r1, "filename", "content", None) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment