Personal emacs config
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.

86 lines
4.2 KiB

  1. ;;; dired-rsync-ert --- tests for dired-rsync
  2. ;;
  3. ;;; Commentary:
  4. ;;
  5. ;; Mostly this is for the internal functions as it is hard to test
  6. ;; remote SSH accessible resources in a test case.
  7. ;;
  8. ;;; Code:
  9. (require 'ert)
  10. (when (require 'undercover nil t)
  11. (undercover "dired-rsync.el"))
  12. (require 'dired-rsync)
  13. (ert-deftest dired-rsync-test-extract-host ()
  14. "Test the various extractions of host from sources."
  15. (should (string-equal "host"
  16. (dired-rsync--extract-host-from-tramp
  17. "/ssh:host:/path/to/file.txt")))
  18. (should (string-equal "user@host"
  19. (dired-rsync--extract-host-from-tramp
  20. "/ssh:user@host:/path/to/file.txt")))
  21. (should (string-equal "host"
  22. (dired-rsync--extract-host-from-tramp
  23. "/ssh:user@host:/path/to/file.txt" t))))
  24. (ert-deftest dired-rsync-test-extract-user ()
  25. "Test the various extractions of user from paths."
  26. (should (string-equal "user"
  27. (dired-rsync--extract-user-from-tramp
  28. "/ssh:user@host:/path/to/file.txt")))
  29. (let ((tramp-default-user "wibble"))
  30. (should (string-equal "wibble"
  31. (dired-rsync--extract-user-from-tramp
  32. "/ssh:host:/path/to/file.txt")))))
  33. (ert-deftest dired-rsync-test-extract-path()
  34. "Test the various extractions of the path."
  35. (should (string-equal "/path/to/file.txt"
  36. (car (dired-rsync--extract-paths-from-tramp
  37. '("/ssh:host:/path/to/file.txt"
  38. "/ssh:host:/path/to/file2.txt")))))
  39. (should (string-equal "/path/to/file2.txt"
  40. (nth 1 (dired-rsync--extract-paths-from-tramp
  41. '("/ssh:host:/path/to/file.txt"
  42. "/ssh:host:/path/to/file2.txt")))))
  43. (should (string-equal "/path/to/file.txt"
  44. (car (dired-rsync--extract-paths-from-tramp
  45. '("/ssh:host:/path/to/file.txt")))))
  46. (should (string-equal "/path/to/pluralised\\'s.txt"
  47. (car (dired-rsync--extract-paths-from-tramp
  48. '("/ssh:host:/path/to/pluralised's.txt")))))
  49. (should (string-equal "/path/to/file.txt"
  50. (car (dired-rsync--extract-paths-from-tramp
  51. '("/ssh:servername|sudo:root@servername:/path/to/file.txt"))))))
  52. (ert-deftest dired-rsync-test-quote-and-maybe-convert-from-tramp ()
  53. "Test quote and maybe convert from tramp defun"
  54. ;; test against regression of issue #26: missing username in rsync command
  55. (should (string-equal "username@192.168.1.1:\"/blat/blot/\""
  56. (dired-rsync--quote-and-maybe-convert-from-tramp "/scp:username@192.168.1.1:/blat/blot/")))
  57. (should (string-equal "192.168.1.1:\"/blat/blot/\""
  58. (dired-rsync--quote-and-maybe-convert-from-tramp "/scp:192.168.1.1:/blat/blot/"))))
  59. (ert-deftest dired-rsync-test-remote-port()
  60. "Test the remote port handling."
  61. (should (= 50000 (dired-rsync--get-remote-port)))
  62. (cl-letf (((symbol-function 'dired-rsync--get-active-buffers) (lambda() '(1 2))))
  63. (should (= 50002 (dired-rsync--get-remote-port)))))
  64. (ert-deftest dired-rsync-test-remote-remote-cmd ()
  65. "Test we generate a good remote to remote command."
  66. (should (string-equal
  67. "ssh -A -R localhost:50000:host:22 seed \"rsync -az --info=progress2 -e \\\"ssh -p 50000 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null\\\" a b c's user@localhost:/video\""
  68. (dired-rsync--remote-to-remote-cmd "seed" '("a" "b" "c's") "user"
  69. "host" "/video")))
  70. (cl-letf (((symbol-function 'dired-rsync--get-active-buffers) (lambda() '(1 2))))
  71. (should (string-equal
  72. "ssh -A -R localhost:50002:host:22 seed \"rsync -az --info=progress2 -e \\\"ssh -p 50002 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null\\\" a b c's user@localhost:/video\""
  73. (dired-rsync--remote-to-remote-cmd "seed" '("a" "b" "c's") "user"
  74. "host" "/video")))))
  75. ;;; dired-rsync-ert.el ends here