74 lines
2.3 KiB
Common Lisp
74 lines
2.3 KiB
Common Lisp
;;; cl-scopes/test/test-storage
|
|
|
|
;;;; testing facility for scopes/storage
|
|
|
|
(defpackage :scopes/test-storage
|
|
(:use :common-lisp)
|
|
(:local-nicknames (:config :scopes/config)
|
|
(:core :scopes/core)
|
|
(:logging :scopes/logging)
|
|
(:message :scopes/core/message)
|
|
(:msglog :scopes/storage/msglog)
|
|
(:shape :scopes/shape)
|
|
(:storage :scopes/storage)
|
|
(:tracking :scopes/storage/tracking)
|
|
(:t :scopes/testing))
|
|
(:export #:run #:run-all #:run-postgres #:run-sqlite)
|
|
(:import-from :scopes/testing #:deftest #:==))
|
|
|
|
(in-package :scopes/test-storage)
|
|
|
|
(defun run-all ()
|
|
(run-sqlite)
|
|
(run-postgres))
|
|
|
|
(defun run-sqlite ()
|
|
(load (t:test-path "config-sqlite"))
|
|
(let ((t:*test-suite* (t:test-suite "sqlite")))
|
|
(run)))
|
|
|
|
(defun run-postgres ()
|
|
(load (t:test-path "config-postgres"))
|
|
(let ((t:*test-suite* (t:test-suite "postgres")))
|
|
(run)))
|
|
|
|
(defun run ()
|
|
(core:setup-services)
|
|
(let ((ctx (core:find-service :storage)))
|
|
(test-track ctx)
|
|
(test-msglog ctx)
|
|
(t:show-result)))
|
|
|
|
(deftest test-track (ctx)
|
|
(let ((st (storage:storage ctx))
|
|
(data (make-hash-table))
|
|
cont tr tr2)
|
|
(setf cont (make-instance 'tracking:container :storage st))
|
|
(storage:drop-table st :tracks)
|
|
(tracking:create-table cont)
|
|
(setf tr (tracking:make-item cont "t01" "john"))
|
|
(== (shape:head tr) '("t01" "john"))
|
|
(== (shape:head-plist tr) '(:username "john" :taskid "t01"))
|
|
(== (shape:data tr) nil)
|
|
(setf (gethash :desc data) "scopes/storage: queries")
|
|
(setf (shape:data tr) data)
|
|
(tracking:insert tr)
|
|
(== (tracking:trackid tr) 1)
|
|
(setf tr2 (tracking:get-track cont 1))
|
|
(== (shape:head tr2) '("t01" "john"))
|
|
(== (gethash :desc (shape:data tr2)) "scopes/storage: queries")
|
|
))
|
|
|
|
(deftest test-msglog (ctx)
|
|
(let ((st (storage:storage ctx))
|
|
(data (make-hash-table))
|
|
cont msg pm pm2)
|
|
(setf cont (msglog:make-container st))
|
|
(storage:drop-table st :messages)
|
|
(tracking:create-table cont)
|
|
(setf msg (message:create '(:test :data :field :info) :data '(:info "test data")))
|
|
(setf pm (msglog:save msg cont))
|
|
(== (tracking:trackid pm) 1)
|
|
(setf pm2 (tracking:get-track cont 1))
|
|
(log:info "pm2: ~s" pm2)
|
|
))
|