]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blobdiff - src/allmydata/test/test_cli.py
When the CLI cannot connect to the gateway, it prints an error message rather than...
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / test / test_cli.py
index c88d00b3ae16c7a6c9334d90c5a1e389b5729d8d..e846a77ac8d46c2022bd56da6f96be5e8c232311 100644 (file)
@@ -13,6 +13,8 @@ from allmydata.immutable import upload
 from allmydata.interfaces import MDMF_VERSION, SDMF_VERSION
 from allmydata.mutable.publish import MutableData
 from allmydata.dirnode import normalize
+from allmydata.scripts.common_http import socket_error
+import allmydata.scripts.common_http
 from pycryptopp.publickey import ed25519
 
 # Test that the scripts can be imported.
@@ -3279,6 +3281,28 @@ class Errors(GridTestMixin, CLITestMixin, unittest.TestCase):
 
         return d
 
+    def test_broken_socket(self):
+        # When the http connection breaks (such as when node.url is overwritten
+        # by a confused user), a user friendly error message should be printed.
+        self.basedir = "cli/Errors/test_broken_socket"
+        self.set_up_grid()
+
+        # Simulate a connection error
+        endheaders = allmydata.scripts.common_http.httplib.HTTPConnection.endheaders
+        def _fix_endheaders(*args):
+            allmydata.scripts.common_http.httplib.HTTPConnection.endheaders = endheaders
+        def _socket_error(*args, **kwargs):
+            raise socket_error('test error')
+        allmydata.scripts.common_http.httplib.HTTPConnection.endheaders = _socket_error
+
+        d = self.do_cli("mkdir")
+        def _check_invalid((rc,stdout,stderr)):
+            self.failIfEqual(rc, 0)
+            self.failUnlessIn("Error trying to connect to http://127.0.0.1", stderr)
+        d.addCallback(_check_invalid)
+        d.addCallback(_fix_endheaders)
+        return d
+
 
 class Get(GridTestMixin, CLITestMixin, unittest.TestCase):
     def test_get_without_alias(self):