datasrc_test.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # Copyright (C) 2011 Internet Systems Consortium.
  2. #
  3. # Permission to use, copy, modify, and distribute this software for any
  4. # purpose with or without fee is hereby granted, provided that the above
  5. # copyright notice and this permission notice appear in all copies.
  6. #
  7. # THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
  8. # DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
  9. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
  10. # INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
  11. # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  12. # FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  13. # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  14. # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. # Make sure we can load the module, put it into path
  16. import sys
  17. import os
  18. sys.path.extend(os.environ["B10_TEST_PLUGIN_DIR"].split(':'))
  19. import datasrc_config_plugin
  20. import unittest
  21. class DatasrcTest(unittest.TestCase):
  22. def reject(self, config):
  23. """
  24. Just a shortcut to check the config is rejected.
  25. """
  26. self.assertIsNotNone(datasrc_config_plugin.check({"classes":
  27. config}))
  28. def accept(self, config):
  29. """
  30. Just a shortcut to check the config is accepted.
  31. """
  32. self.assertIsNone(datasrc_config_plugin.check({"classes":
  33. config}))
  34. def test_load(self):
  35. """
  36. Checks the entry point returns the correct values.
  37. """
  38. (spec, check) = datasrc_config_plugin.load()
  39. # It returns the checking function
  40. self.assertEqual(check, datasrc_config_plugin.check)
  41. # The plugin stores it's spec
  42. self.assertEqual(spec, datasrc_config_plugin.spec)
  43. def test_empty(self):
  44. """
  45. Check an empty input is OK.
  46. """
  47. self.accept({})
  48. def test_invalid_spec(self):
  49. """
  50. Check it rejects stuff that is not well-formed according
  51. to the spec.
  52. """
  53. self.reject("test")
  54. self.reject(13)
  55. self.reject([])
  56. self.reject({"IN": {}})
  57. self.reject({"IN": [{"bad-name": True}]})
  58. def test_class(self):
  59. """
  60. The class is rejected, if it is wrong.
  61. """
  62. self.reject({"BAD": []})
  63. self.reject({"": []})
  64. # But with a good one, it works
  65. for c in ["IN", "CH", "HS"]:
  66. self.accept({c: []})
  67. def test_mem_ok(self):
  68. """
  69. Test we accept an in-memory data source. It doesn't really matter
  70. which one it is. We just want to make sure we accept something
  71. and this one does not need any kind of path mangling to find
  72. plugins.
  73. """
  74. self.accept({"IN": [{
  75. "type": "MasterFiles",
  76. "cache-enable": True,
  77. "params": {}
  78. }]})
  79. def test_dstype_bad(self):
  80. """
  81. The configuration is correct by the spec, but it would be rejected
  82. by the client list. Check we reject it.
  83. """
  84. self.reject({"IN": [{
  85. "type": "No such type"
  86. }]})
  87. if __name__ == '__main__':
  88. unittest.main()