summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorStefan Kangas <stefankangas@gmail.com>2019-06-09 09:18:46 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2019-06-09 10:08:36 -0700
commit1af27a17847fb02f35359e9bc03c77c1058f7a1d (patch)
tree8ad0793bdc6d9e8165d1e27abc8aa19d3ad73a73 /test
parent179b9c44c5dc6ba0cf8c9235b59c52aebcbaa828 (diff)
downloademacs-1af27a17847fb02f35359e9bc03c77c1058f7a1d.tar.gz
emacs-1af27a17847fb02f35359e9bc03c77c1058f7a1d.tar.bz2
emacs-1af27a17847fb02f35359e9bc03c77c1058f7a1d.zip
Use lexical-binding in password-cache.el and add tests
* lisp/password-cache.el: Use lexical-binding. * test/lisp/password-cache-tests.el: New file.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/password-cache-tests.el75
1 files changed, 75 insertions, 0 deletions
diff --git a/test/lisp/password-cache-tests.el b/test/lisp/password-cache-tests.el
new file mode 100644
index 00000000000..bb8064d4c69
--- /dev/null
+++ b/test/lisp/password-cache-tests.el
@@ -0,0 +1,75 @@
+;;; password-cache-tests.el --- Tests for password-cache.el -*- lexical-binding: t -*-
+
+;; Copyright (C) 2019 Free Software Foundation, Inc.
+
+;; Author: Stefan Kangas <stefankangas@gmail.com>
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs 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.
+
+;; GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;; Code:
+
+(require 'ert)
+(require 'password-cache)
+
+(ert-deftest password-cache-tests-add-and-remove ()
+ (let ((password-data (copy-hash-table password-data)))
+ (password-cache-add "foo" "bar")
+ (should (equal (password-in-cache-p "foo") "bar"))
+ (password-cache-remove "foo")
+ (should (not (password-in-cache-p "foo")))))
+
+(ert-deftest password-cache-tests-read-from-cache ()
+ (let ((password-data (copy-hash-table password-data)))
+ (password-cache-add "foo" "bar")
+ (should (equal (password-read-from-cache "foo") "bar"))
+ (should (not (password-read-from-cache nil)))))
+
+(ert-deftest password-cache-tests-in-cache-p ()
+ (let ((password-data (copy-hash-table password-data)))
+ (password-cache-add "foo" "bar")
+ (should (password-in-cache-p "foo"))
+ (should (not (password-read-from-cache nil)))))
+
+(ert-deftest password-cache-tests-read ()
+ (let ((password-data (copy-hash-table password-data)))
+ (password-cache-add "foo" "bar")
+ (should (equal (password-read nil "foo") "bar"))))
+
+(ert-deftest password-cache-tests-reset ()
+ (let ((password-data (copy-hash-table password-data)))
+ (password-cache-add "foo" "bar")
+ (password-reset)
+ (should (not (password-in-cache-p "foo")))))
+
+(ert-deftest password-cache-tests-add/expires-key ()
+ :tags '(:expensive-test)
+ (let ((password-data (copy-hash-table password-data))
+ (password-cache-expiry 0.01))
+ (password-cache-add "foo" "bar")
+ (sit-for 0.1)
+ (should (not (password-in-cache-p "foo")))))
+
+(ert-deftest password-cache-tests-no-password-cache ()
+ (let ((password-data (copy-hash-table password-data))
+ (password-cache nil))
+ (password-cache-add "foo" "bar")
+ (should (not (password-in-cache-p "foo")))
+ (should (not (password-read-from-cache "foo")))))
+
+(provide 'password-cache-tests)
+;;; password-cache-tests.el ends here