-
Notifications
You must be signed in to change notification settings - Fork 16
/
sudo-edit-test.el
67 lines (49 loc) · 2.8 KB
/
sudo-edit-test.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
;;; sudo-edit-test.el --- sudo-edit: Unit test suite -*- lexical-binding: t -*-
;; Copyright (c) 2016 Mario Rodas <[email protected]>
;; Author: Mario Rodas <[email protected]>
;; URL: https://github.com/nflath/sudo-edit
;; Keywords: convenience
;; Version: 0.0.1
;; Package-Requires: ((emacs "24") (cl-lib "0.5"))
;; This file is NOT part of GNU Emacs.
;;; License:
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; The unit test suite of sudo-edit
;;; Code:
(declare-function undercover "undercover")
(when (require 'undercover nil 'no-error)
(undercover "sudo-edit.el"))
(require 'sudo-edit)
(ert-deftest sudo-edit-filename-test ()
;; local files
(should (equal (sudo-edit-filename "/path/to/example.txt" "root")
"/sudo:root@localhost:/path/to/example.txt"))
;; remote files
(should (equal (sudo-edit-filename "/ssh:remotehost:/path/to/example.txt" "root")
"/ssh:remotehost|sudo:root@remotehost:/path/to/example.txt"))
(should (equal (sudo-edit-filename "/ssh:remotehost|sudo:root@remotehost:/path/to/example.txt" "www-data")
"/ssh:remotehost|sudo:root@remotehost|sudo:www-data@remotehost:/path/to/example.txt"))
;; Change method from scp to ssh in ssh related methods
(should (equal (sudo-edit-filename "/scp:remotehost:/path/to/example.txt" "root")
"/ssh:remotehost|sudo:root@remotehost:/path/to/example.txt"))
;; tramp multi-hops files
(should (equal (sudo-edit-filename "/ssh:machine1|ssh:machine2:/path/to/example.txt" "root")
"/ssh:machine1|ssh:machine2|sudo:root@machine2:/path/to/example.txt"))
(should (equal (sudo-edit-filename "/ssh:machine1|ssh:machine2|sudo:root@machine2:/path/to/example.txt" "www-data")
"/ssh:machine1|ssh:machine2|sudo:root@machine2|sudo:www-data@machine2:/path/to/example.txt")))
(ert-deftest sudo-edit-sudo-edit-out-of-band-ssh-p-test ()
(should (sudo-edit-out-of-band-ssh-p "/scp:remotehost:/path/to/example.txt"))
(should (sudo-edit-out-of-band-ssh-p "/sftp:remotehost:/path/to/example.txt"))
(should-not (sudo-edit-out-of-band-ssh-p "/telnet:remotehost:/path/to/example.txt")))
(provide 'sudo-edit-test)
;;; sudo-edit-test.el ends here