-
Notifications
You must be signed in to change notification settings - Fork 16
/
dired-rsync-ert.el
98 lines (87 loc) · 4.93 KB
/
dired-rsync-ert.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
;;; dired-rsync-ert --- tests for dired-rsync
;;
;;; Commentary:
;;
;; Mostly this is for the internal functions as it is hard to test
;; remote SSH accessible resources in a test case.
;;
;;; Code:
(require 'ert)
;;
(when (and (version<= "26.1" emacs-version)
(require 'undercover nil t))
(undercover "dired-rsync.el"))
(require 'dired-rsync)
(ert-deftest dired-rsync-test-extract-host ()
"Test the various extractions of host from sources."
(should (string-equal "host"
(dired-rsync--extract-host-from-tramp
"/ssh:host:/path/to/file.txt")))
(should (string-equal "user@host"
(dired-rsync--extract-host-from-tramp
"/ssh:user@host:/path/to/file.txt")))
(should (string-equal "host"
(dired-rsync--extract-host-from-tramp
"/ssh:user@host:/path/to/file.txt" t))))
(ert-deftest dired-rsync-test-extract-user ()
"Test the various extractions of user from paths."
(should (string-equal "user"
(dired-rsync--extract-user-from-tramp
"/ssh:user@host:/path/to/file.txt")))
(let ((tramp-default-user "wibble"))
(should (string-equal "wibble"
(dired-rsync--extract-user-from-tramp
"/ssh:host:/path/to/file.txt")))))
(ert-deftest dired-rsync-test-extract-port ()
"Test the various extractions of port from paths."
(should-not (dired-rsync--extract-port-from-tramp "/path/to/file.txt"))
(should (string-equal "1022"
(dired-rsync--extract-port-from-tramp
"/ssh:user@host#1022:/path/to/file.txt"))))
(ert-deftest dired-rsync-test-extract-path()
"Test the various extractions of the path."
(should (string-equal "/path/to/file.txt"
(car (dired-rsync--extract-paths-from-tramp
'("/ssh:host:/path/to/file.txt"
"/ssh:host:/path/to/file2.txt")))))
(should (string-equal "/path/to/file2.txt"
(nth 1 (dired-rsync--extract-paths-from-tramp
'("/ssh:host:/path/to/file.txt"
"/ssh:host:/path/to/file2.txt")))))
(should (string-equal "/path/to/file.txt"
(car (dired-rsync--extract-paths-from-tramp
'("/ssh:host:/path/to/file.txt")))))
(should (string-equal "/path/to/pluralised\\'s.txt"
(car (dired-rsync--extract-paths-from-tramp
'("/ssh:host:/path/to/pluralised's.txt")))))
(should (string-equal "/path/to/file.txt"
(car (dired-rsync--extract-paths-from-tramp
'("/ssh:servername|sudo:root@servername:/path/to/file.txt"))))))
(ert-deftest dired-rsync-test-quote-and-maybe-convert-from-tramp ()
"Test quote and maybe convert from tramp defun"
;; test against regression of issue #26: missing username in rsync command
(should (string-equal "[email protected]:/blat/blot/"
(dired-rsync--quote-and-maybe-convert-from-tramp "/scp:[email protected]:/blat/blot/")))
(should (string-equal "192.168.1.1:/blat/blot/"
(dired-rsync--quote-and-maybe-convert-from-tramp "/scp:192.168.1.1:/blat/blot/"))))
(ert-deftest dired-rsync-test-remote-port()
"Test the remote port handling."
(should (= 50000 (dired-rsync--get-remote-port)))
(cl-letf (((symbol-function 'dired-rsync--get-active-buffers) (lambda() '(1 2))))
(should (= 50002 (dired-rsync--get-remote-port)))))
(ert-deftest dired-rsync-test-remote-remote-cmd ()
"Test we generate a good remote to remote command."
(should (string-equal
"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\""
(dired-rsync--remote-to-remote-cmd "seed" nil '("a" "b" "c's") "user"
"host" nil "/video")))
(should (string-equal
"ssh -A -p 23 -R localhost:50000:host:1022 seed \"rsync -az --info=progress2 -e \\\"ssh -p 50000 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null\\\" -- a b c's user@localhost:/video\""
(dired-rsync--remote-to-remote-cmd "seed" "23" '("a" "b" "c's") "user"
"host" "1022" "/video")))
(cl-letf (((symbol-function 'dired-rsync--get-active-buffers) (lambda() '(1 2))))
(should (string-equal
"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\""
(dired-rsync--remote-to-remote-cmd "seed" nil '("a" "b" "c's") "user"
"host" nil "/video")))))
;;; dired-rsync-ert.el ends here