Emacs library to communicate with CouchDB databases.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
4.4 KiB

3 years ago
  1. ;;; libelcouch-test.el --- Tests for libelcouch.el -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2018 Damien Cassou
  3. ;; Author: Damien Cassou <damien@cassou.me>
  4. ;; This program is free software; you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;; You should have received a copy of the GNU General Public License
  13. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. ;;; Commentary:
  15. ;;
  16. ;;; Code:
  17. (require 'ert)
  18. (require 'libelcouch)
  19. ;;; Accessors
  20. (ert-deftest libelcouch-entity-name ()
  21. (let* ((instance (libelcouch--instance-create :name "Instance"))
  22. (database (libelcouch--database-create :name "Database" :instance instance))
  23. (document (libelcouch--document-create :name "Document" :database database)))
  24. (should (equal (libelcouch-entity-name instance) "Instance"))
  25. (should (equal (libelcouch-entity-name database) "Database"))
  26. (should (equal (libelcouch-entity-name document) "Document"))))
  27. (ert-deftest libelcouch-entity-parent ()
  28. (let* ((instance (libelcouch--instance-create :name "Instance"))
  29. (database (libelcouch--database-create :name "Database" :instance instance))
  30. (document (libelcouch--document-create :name "Document" :database database)))
  31. (should (eq (libelcouch-entity-parent database) instance))
  32. (should (equal (libelcouch-entity-parent document) database))))
  33. (ert-deftest libelcouch-entity-instance ()
  34. (let* ((instance (libelcouch--instance-create :name "Instance"))
  35. (database (libelcouch--database-create :name "Database" :instance instance))
  36. (document (libelcouch--document-create :name "Document" :database database)))
  37. (should (eq (libelcouch-entity-instance instance) instance))
  38. (should (eq (libelcouch-entity-instance database) instance))
  39. (should (eq (libelcouch-entity-instance document) instance))))
  40. (ert-deftest libelcouch-entity-url ()
  41. (let* ((instance (libelcouch--instance-create :url "http://localhost:5984"))
  42. (database (libelcouch--database-create :name "Database" :instance instance))
  43. (document (libelcouch--document-create :name "Document" :database database)))
  44. (should (equal (libelcouch-entity-url instance) "http://localhost:5984"))
  45. (should (equal (libelcouch-entity-url database) "http://localhost:5984/Database"))
  46. (should (equal (libelcouch-entity-url document) "http://localhost:5984/Database/Document"))))
  47. ;;; Private helpers
  48. (ert-deftest libelcouch--entity-create-children-from-json-instance ()
  49. (let* ((instance (libelcouch--instance-create :name "Instance"))
  50. (json (list "db1" "db2"))
  51. (children (libelcouch--entity-create-children-from-json instance json)))
  52. (should (equal
  53. children
  54. (list
  55. (libelcouch--database-create :name "db1" :instance instance)
  56. (libelcouch--database-create :name "db2" :instance instance))))))
  57. (ert-deftest libelcouch--entity-create-children-from-json-database ()
  58. (let* ((instance (libelcouch--instance-create :name "Instance"))
  59. (database (libelcouch--database-create :name "Database" :instance instance))
  60. (json '((rows . (
  61. ((id . "doc1") (value . ((rev . "rev1"))))
  62. ((id . "doc2") (value . ((rev . "rev2"))))))))
  63. (children (libelcouch--entity-create-children-from-json database json)))
  64. (should (equal
  65. children
  66. (list
  67. (libelcouch--document-create :name "doc1" :revision "rev1" :database database)
  68. (libelcouch--document-create :name "doc2" :revision "rev2" :database database))))))
  69. (ert-deftest libelcouch--entity-children-url ()
  70. (let* ((instance (libelcouch--instance-create :name "Instance" :url "http://localhost:5984"))
  71. (database (libelcouch--database-create :name "Database" :instance instance)))
  72. (should (equal (libelcouch--entity-children-url instance) "http://localhost:5984/_all_dbs"))
  73. (should (equal (libelcouch--entity-children-url database) "http://localhost:5984/Database/_all_docs"))))
  74. (provide 'libelcouch-test)
  75. ;;; libelcouch-test.el ends here