mirror of
https://github.com/vale981/lack
synced 2025-03-05 09:21:39 -05:00
Add tests for serializing/deserializing UTF-8 sessions in DBI.
This commit is contained in:
parent
3a74575651
commit
114b513c89
1 changed files with 32 additions and 2 deletions
|
@ -8,7 +8,7 @@
|
||||||
:prove))
|
:prove))
|
||||||
(in-package :t.lack.session.store.dbi)
|
(in-package :t.lack.session.store.dbi)
|
||||||
|
|
||||||
(plan 2)
|
(plan 3)
|
||||||
|
|
||||||
(defvar *test-db* (asdf:system-relative-pathname :lack "data/test.db"))
|
(defvar *test-db* (asdf:system-relative-pathname :lack "data/test.db"))
|
||||||
(when (probe-file *test-db*)
|
(when (probe-file *test-db*)
|
||||||
|
@ -49,8 +49,38 @@
|
||||||
(is status 200)
|
(is status 200)
|
||||||
(is body '("Hello, you've been here for 2th times!")))))
|
(is body '("Hello, you've been here for 2th times!")))))
|
||||||
|
|
||||||
|
(subtest "utf-8 session data"
|
||||||
|
(let ((app
|
||||||
|
(builder
|
||||||
|
(:session
|
||||||
|
:store (make-dbi-store
|
||||||
|
:connector (lambda () *conn*)))
|
||||||
|
(lambda (env)
|
||||||
|
(unless (gethash :user (getf env :lack.session))
|
||||||
|
(setf (gethash :user (getf env :lack.session)) "深町英太郎"))
|
||||||
|
(unless (gethash :counter (getf env :lack.session))
|
||||||
|
(setf (gethash :counter (getf env :lack.session)) 0))
|
||||||
|
`(200
|
||||||
|
(:content-type "text/plain")
|
||||||
|
(,(format nil "Hello, ~A! You've been here for ~Ath times!"
|
||||||
|
(gethash :user (getf env :lack.session))
|
||||||
|
(incf (gethash :counter (getf env :lack.session)))))))))
|
||||||
|
session)
|
||||||
|
(destructuring-bind (status headers body)
|
||||||
|
(funcall app (generate-env "/"))
|
||||||
|
(is status 200)
|
||||||
|
(setf session (parse-lack-session headers))
|
||||||
|
(ok session)
|
||||||
|
(is body '("Hello, 深町英太郎! You've been here for 1th times!")))
|
||||||
|
|
||||||
|
(destructuring-bind (status headers body)
|
||||||
|
(funcall app (generate-env "/" :cookies `(("lack.session" . ,session))))
|
||||||
|
(declare (ignore headers))
|
||||||
|
(is status 200)
|
||||||
|
(is body '("Hello, 深町英太郎! You've been here for 2th times!")))))
|
||||||
|
|
||||||
(let ((session (dbi:fetch (dbi:execute (dbi:prepare *conn* "SELECT COUNT(*) AS count FROM sessions")))))
|
(let ((session (dbi:fetch (dbi:execute (dbi:prepare *conn* "SELECT COUNT(*) AS count FROM sessions")))))
|
||||||
(is (getf session :|count|) 1
|
(is (getf session :|count|) 2
|
||||||
"'sessions' has a single record"))
|
"'sessions' has a single record"))
|
||||||
|
|
||||||
(dbi:disconnect *conn*)
|
(dbi:disconnect *conn*)
|
||||||
|
|
Loading…
Add table
Reference in a new issue