read-session should return nil when there is no value

this is to be consistent with most all other implementations of
ring's SessionStore that i've seen
This commit is contained in:
Gered 2022-01-02 14:26:00 -05:00
parent a04a74f2a8
commit 1fd154c4f6
3 changed files with 6 additions and 6 deletions

View file

@ -59,7 +59,7 @@
(swap! session-map sweep-entry event-fns key)
(when (and refresh-on-read (contains? @session-map key))
(swap! session-map assoc-in [key :timestamp] (now)))
(get-in @session-map [key :value] {}))
(get-in @session-map [key :value]))
(write-session [_ key data]
(let [key (or key (str (UUID/randomUUID)))]

View file

@ -10,7 +10,7 @@
(let [as (aging-memory-store :events [(event/expires-after 1)])]
(write-session as "mykey" {:foo 1})
(. Thread (sleep 1500))
(is (= (read-session as "mykey") {})))))
(is (nil? (read-session as "mykey"))))))
(deftest session-expiry-by-sweep
(testing "Test session expiry sweep."
@ -43,6 +43,6 @@
:refresh-on-read true
:sweep-every 1
:sweep-delay 1000)]
(is (= (read-session as "foo") {}))
(is (nil? (read-session as "foo")))
; read again to trigger the sweep
(is (= (read-session as "foo") {})))))
(is (nil? (read-session as "foo"))))))

View file

@ -7,7 +7,7 @@
(deftest basic-read-empty
(testing "Test session reads."
(let [as (aging-memory-store)]
(is (= (read-session as "mykey") {})))))
(is (nil? (read-session as "mykey"))))))
(deftest basic-write
(testing "Test session writes and reads."
@ -22,7 +22,7 @@
(let [as (aging-memory-store)]
(write-session as "mykey" {:a 1})
(delete-session as "mykey")
(is (= (read-session as "mykey") {})))))
(is (nil? (read-session as "mykey"))))))
(deftest timestamp-on-creation
(testing "Test the behaviour where each entry's timestamp is set only on session creation."