test set-up for storage: run tests with sqlite and postgresql settings
This commit is contained in:
parent
db405da6d9
commit
c4fdc6eeec
4 changed files with 48 additions and 16 deletions
|
@ -5,23 +5,39 @@
|
||||||
(defpackage :scopes/storage
|
(defpackage :scopes/storage
|
||||||
(:use :common-lisp)
|
(:use :common-lisp)
|
||||||
(:export #:*db-config*
|
(:export #:*db-config*
|
||||||
#:storage
|
#:make-storage
|
||||||
#:drop-table))
|
#:drop-table))
|
||||||
|
|
||||||
(in-package :scopes/storage)
|
(in-package :scopes/storage)
|
||||||
|
|
||||||
(defparameter *db-config* nil)
|
(defparameter *db-config* nil)
|
||||||
|
(defparameter *db-engine* nil)
|
||||||
|
|
||||||
(defclass storage-factory ()
|
(defclass db-engine ()
|
||||||
((params :initarg :params)
|
((params :initarg :params)
|
||||||
(config :initarg :config)))
|
(config :initarg :config)))
|
||||||
|
|
||||||
(defclass storage ()
|
(defclass storage ()
|
||||||
((factory :initarg :factory)
|
((engine :initarg :engine)
|
||||||
(db)
|
(db)
|
||||||
(schema)))
|
(schema)))
|
||||||
|
|
||||||
|
(defun make-storage ()
|
||||||
|
(let ((engine (make-engine (getf *db-config* :db-type) *db-config*)))
|
||||||
|
(make-instance 'storage :engine engine)))
|
||||||
|
|
||||||
(defun drop-table (st tn)
|
(defun drop-table (st tn)
|
||||||
st
|
st
|
||||||
(print (sxql:yield
|
(print (sxql:yield
|
||||||
(sxql:drop-table tn :if-exists t))))
|
(sxql:drop-table tn :if-exists t))))
|
||||||
|
|
||||||
|
;; db-driver-specific stuff
|
||||||
|
|
||||||
|
(defun make-engine (db-type config)
|
||||||
|
(let ((params
|
||||||
|
(cond
|
||||||
|
((eq db-type :sqlite3)
|
||||||
|
'(:id-type integer :json-type json))
|
||||||
|
((eq db-type :postgres)
|
||||||
|
'(:id-type bigserial :json-type jsonb)))))
|
||||||
|
(make-instance 'db-engine :params params :config config)))
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
(defpackage :scopes/storage/tracking
|
(defpackage :scopes/storage/tracking
|
||||||
(:use :common-lisp)
|
(:use :common-lisp)
|
||||||
|
(:local-nicknames (:storage :scopes/storage))
|
||||||
(:export #:track #:time-stamp #:data
|
(:export #:track #:time-stamp #:data
|
||||||
#:container
|
#:container
|
||||||
#:create-table))
|
#:create-table))
|
||||||
|
@ -21,13 +22,15 @@
|
||||||
|
|
||||||
(defun create-table (storage table-name head-fields)
|
(defun create-table (storage table-name head-fields)
|
||||||
storage
|
storage
|
||||||
(let
|
(let*
|
||||||
((id-type 'bigserial)
|
((params (slot-value (slot-value storage 'storage::engine) 'storage::params))
|
||||||
|
(id-type (getf params :id-type))
|
||||||
|
(json-type (getf params :json-type))
|
||||||
(hf-def (mapcar #'(lambda (x) (list x :type 'text)) head-fields)))
|
(hf-def (mapcar #'(lambda (x) (list x :type 'text)) head-fields)))
|
||||||
(print (sxql:yield
|
(print (sxql:yield
|
||||||
(sxql:make-statement :create-table table-name
|
(sxql:make-statement :create-table table-name
|
||||||
(nconc
|
(nconc
|
||||||
`((trackid :type ,id-type :primary-key t))
|
`((trackid :type ,id-type :primary-key t))
|
||||||
hf-def
|
hf-def
|
||||||
'((timestamp :type timestamp)
|
`((timestamp :type timestamp)
|
||||||
(data :type jsonb))))))))
|
(data :type ,json-type))))))))
|
||||||
|
|
|
@ -23,26 +23,26 @@
|
||||||
|
|
||||||
(defun test-exec ()
|
(defun test-exec ()
|
||||||
(forge:exec '(4 2 +))
|
(forge:exec '(4 2 +))
|
||||||
(t:== (car (forge:dstack)) 6))
|
(== (car (forge:dstack)) 6))
|
||||||
|
|
||||||
(defun test-def ()
|
(defun test-def ()
|
||||||
(forge:exec '((dup *) "square" def))
|
(forge:exec '((dup *) "square" def))
|
||||||
(forge:exec '(7 square))
|
(forge:exec '(7 square))
|
||||||
(t:== (car (forge:dstack)) 49))
|
(== (car (forge:dstack)) 49))
|
||||||
|
|
||||||
(defun test-exec-str ()
|
(defun test-exec-str ()
|
||||||
(forge:exec-str "16 square")
|
(forge:exec-str "16 square")
|
||||||
(t:== (car (forge:dstack)) 256))
|
(== (car (forge:dstack)) 256))
|
||||||
|
|
||||||
(defun test-const ()
|
(defun test-const ()
|
||||||
(forge:exec-str "17 \"c1\" const")
|
(forge:exec-str "17 \"c1\" const")
|
||||||
(forge:exec-str "c1 square")
|
(forge:exec-str "c1 square")
|
||||||
(t:== (car (forge:dstack)) 289))
|
(== (car (forge:dstack)) 289))
|
||||||
|
|
||||||
(defun test-var ()
|
(defun test-var ()
|
||||||
(forge:exec '(24 "v1" var))
|
(forge:exec '(24 "v1" var))
|
||||||
(forge:exec '(v1 get 2 *))
|
(forge:exec '(v1 get 2 *))
|
||||||
(t:== (car (forge:dstack)) 48)
|
(== (car (forge:dstack)) 48)
|
||||||
(forge:exec '(5 v1 put))
|
(forge:exec '(5 v1 put))
|
||||||
(forge:exec '(v1 get 2 *))
|
(forge:exec '(v1 get 2 *))
|
||||||
(t:== (car (forge:dstack)) 10))
|
(== (car (forge:dstack)) 10))
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
(:local-nicknames (:storage :scopes/storage)
|
(:local-nicknames (:storage :scopes/storage)
|
||||||
(:tracking :scopes/storage/tracking)
|
(:tracking :scopes/storage/tracking)
|
||||||
(:t :scopes/testing))
|
(:t :scopes/testing))
|
||||||
(:export #:run #:try
|
(:export #:*db-config-postgres* #:*db-config-sqlite*
|
||||||
#:*db-config-postgres* #:*db-config-sqlite*)
|
#:run #:run-all #:run-postgres #:run-sqlite #:try)
|
||||||
(:import-from :scopes/testing #:==))
|
(:import-from :scopes/testing #:==))
|
||||||
|
|
||||||
(in-package :scopes/test-storage)
|
(in-package :scopes/test-storage)
|
||||||
|
@ -16,13 +16,26 @@
|
||||||
(defparameter *db-config-sqlite* nil)
|
(defparameter *db-config-sqlite* nil)
|
||||||
(defparameter *db-config-postgres* nil)
|
(defparameter *db-config-postgres* nil)
|
||||||
(load "test/etc")
|
(load "test/etc")
|
||||||
|
|
||||||
(defun try()
|
(defun try()
|
||||||
(setf storage:*db-config* *db-config-sqlite*)
|
(setf storage:*db-config* *db-config-sqlite*)
|
||||||
(print storage:*db-config*)
|
(print storage:*db-config*)
|
||||||
(print *db-config-postgres*))
|
(print *db-config-postgres*))
|
||||||
|
|
||||||
|
(defun run-all ()
|
||||||
|
(run-sqlite)
|
||||||
|
(run-postgres))
|
||||||
|
|
||||||
|
(defun run-sqlite ()
|
||||||
|
(let ((storage:*db-config* *db-config-sqlite*))
|
||||||
|
(run)))
|
||||||
|
|
||||||
|
(defun run-postgres ()
|
||||||
|
(let ((storage:*db-config* *db-config-postgres*))
|
||||||
|
(run)))
|
||||||
|
|
||||||
(defun run ()
|
(defun run ()
|
||||||
(let ((st (make-instance 'storage:storage))
|
(let ((st (storage:make-storage))
|
||||||
(t:*tst* (t:test-suite)))
|
(t:*tst* (t:test-suite)))
|
||||||
(test-track st)
|
(test-track st)
|
||||||
(t:show-result)))
|
(t:show-result)))
|
||||||
|
|
Loading…
Add table
Reference in a new issue