-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest-base.ss
88 lines (79 loc) · 3.76 KB
/
test-base.ss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#lang scheme/base
(require "base.ss")
(require srfi/19
(schemeunit-in test text-ui)
(prefix-in sqlite: (sqlite-in sqlite))
"snooze-api.ss"
"snooze-class.ss"
"test-data.ss"
"test-util.ss"
"core/core.ss"
"postgresql8/postgresql8.ss"
"sqlite3/sqlite3.ss")
; [#:server string]
; [#:port natural]
; [#:database string]
; [#:username string]
; [#:password (U string #f)]
; test-suite
; ->
; any
(define (run-tests/postgresql8 #:server [server "localhost"]
#:port [port 5432]
#:database [database "snoozetest"]
#:username [username "snooze"]
#:password [password #f]
tests)
; To setup the default database for testing, the following command line functions will work
; createuser snooze (Make them a superuser)
; createdb snoozetest
(parameterize ([current-snooze (make-snooze #:connect-on-demand? #f
(make-postgresql8-database
#:server server
#:port port
#:database database
#:username username
#:password password
#:pool-connections? #t))]
[direct-query-proc (lambda (sql)
(let ([conn (send (current-snooze) current-connection)])
(send (connection-back-end conn) map sql list)))])
; We don't need the logging output but we do want to know that the hooks don't exn:
(query-logger-set! void)
(direct-find-logger-set! void)
(run-tests tests)))
; (U string path ':memory: ':temp:) test-suite -> any
(define (run-tests/sqlite3 location tests)
(parameterize ([current-snooze (make-snooze #:connect-on-demand? #f
(make-sqlite3-database location))]
[direct-query-proc (lambda (sql)
(let* ([conn (send (current-snooze) current-connection)]
[ans (sqlite:select (connection-back-end conn) sql)])
(if (null? ans) null (map vector->list (cdr ans)))))])
; We don't need the logging output but we do want to know that the hooks don't exn:
(query-logger-set! void)
(direct-find-logger-set! void)
(run-tests tests)))
; string -> time-tai
(define (string->time-tai str)
(date->time-tai (string->date (string-append str "+0000") "~Y-~m-~d ~H:~M:~S~z")))
; string -> time-utc
(define (string->time-utc str)
(date->time-utc (string->date (string-append str "+0000") "~Y-~m-~d ~H:~M:~S~z")))
; Provide statements ---------------------------
(provide (all-from-out "base.ss"
"test-data.ss"
"test-util.ss")
(except-out (schemeunit-out test text-ui)
run-tests))
(provide/contract
[run-tests/postgresql8 (->* (test-suite?)
(#:server string?
#:port natural-number/c
#:database string?
#:username string?
#:password (or/c string? #f))
any)]
[run-tests/sqlite3 (-> (or/c string? path? ':memory: ':temp:) test-suite? any)]
[string->time-tai (-> string? time-tai?)]
[string->time-utc (-> string? time-utc?)])