Browse Source

TDD: created tests first :)

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac183@1900 e5f2f494-b856-4b98-b285-d166d9295462
Jelte Jansen 15 years ago
parent
commit
91923a0d65
1 changed files with 31 additions and 0 deletions
  1. 31 0
      src/bin/msgq/tests/msgq_test.py

+ 31 - 0
src/bin/msgq/tests/msgq_test.py

@@ -1,6 +1,7 @@
 from msgq import SubscriptionManager, MsgQ
 
 import unittest
+import os
 
 #
 # Currently only the subscription part is implemented...  I'd have to mock
@@ -58,5 +59,35 @@ class TestSubscriptionManager(unittest.TestCase):
         self.sm.subscribe('g1', '*', 's2')
         self.assertEqual(self.sm.find_sub("g1", "i1"), [ 's1' ])
 
+    def test_open_socket_parameter(self):
+        self.assertFalse(os.path.exists("./my_socket_file"))
+        msgq = MsgQ("./my_socket_file");
+        self.assertTrue(os.path.exists("./my_socket_file"))
+        msgq.shutdown();
+        self.assertFalse(os.path.exists("./my_socket_file"))
+
+    def test_open_socket_environment_variable(self):
+        self.assertFalse(os.path.exists("my_socket_file"))
+        os.environ["BIND10_MSGQ_SOCKET_FILE"] = "./my_socket_file"
+        msgq = MsgQ();
+        self.assertTrue(os.path.exists("./my_socket_file"))
+        msgq.shutdown();
+        self.assertFalse(os.path.exists("./my_socket_file"))
+
+    def test_open_socket_default(self):
+        if "BIND10_MSGQ_SOCKET_FILE" in os.environ:
+            del os.environ["BIND10_MSGQ_SOCKET_FILE"]
+        socket_file = MsgQ.SOCKET_FILE
+        self.assertFalse(os.path.exists(socket_file))
+        msgq = MsgQ();
+        self.assertTrue(os.path.exists("./my_socket_file"))
+        msgq.shutdown();
+        self.assertFalse(os.path.exists("./my_socket_file"))
+        pass
+
+    def test_open_socket_bad(self):
+        self.assertRaises(Exception, MsgQ("/does/not/exist"))
+        pass
+
 if __name__ == '__main__':
     unittest.main()