Adding tests
svn: r6455
This commit is contained in:
parent
6f4bbf80d1
commit
636e5bd9c1
|
@ -1,7 +1,3 @@
|
||||||
;; this is a trivial implementation of the connection-manger interface that
|
|
||||||
;; uses timeouts instead of a queued-model.
|
|
||||||
|
|
||||||
;; the queued-model is also fully implemented but won't be used at this time.
|
|
||||||
(module connection-manager mzscheme
|
(module connection-manager mzscheme
|
||||||
(require "connection-structs.ss"
|
(require "connection-structs.ss"
|
||||||
"timer.ss"
|
"timer.ss"
|
||||||
|
|
|
@ -4,8 +4,30 @@
|
||||||
(lib "string.ss"))
|
(lib "string.ss"))
|
||||||
(require "util.ss")
|
(require "util.ss")
|
||||||
(provide/contract
|
(provide/contract
|
||||||
|
[read-mime-types (path? . -> . hash-table?)]
|
||||||
[make-get-mime-type (path? . -> . (path? . -> . bytes?))])
|
[make-get-mime-type (path? . -> . (path? . -> . bytes?))])
|
||||||
|
|
||||||
|
; read-mime-types : path? -> hash-table?
|
||||||
|
(define (read-mime-types a-path)
|
||||||
|
(define MIME-TYPE-TABLE (make-hash-table))
|
||||||
|
(with-input-from-file a-path
|
||||||
|
(lambda ()
|
||||||
|
(let loop ()
|
||||||
|
(match (read-line (current-input-port) 'any)
|
||||||
|
[(? eof-object?)
|
||||||
|
(void)]
|
||||||
|
[(regexp #"^([^\t ]+)[\t ]+(.+)$"
|
||||||
|
(list s type exts))
|
||||||
|
(for-each (lambda (ext)
|
||||||
|
(hash-table-put! MIME-TYPE-TABLE
|
||||||
|
(lowercase-symbol! ext)
|
||||||
|
type))
|
||||||
|
(regexp-split #" " exts))
|
||||||
|
(loop)]
|
||||||
|
[_
|
||||||
|
(loop)]))))
|
||||||
|
MIME-TYPE-TABLE)
|
||||||
|
|
||||||
;; make-get-mime-type : path? -> path? -> bytes?
|
;; make-get-mime-type : path? -> path? -> bytes?
|
||||||
;; determine the mime type based on the filename's suffix
|
;; determine the mime type based on the filename's suffix
|
||||||
;;
|
;;
|
||||||
|
@ -13,25 +35,10 @@
|
||||||
;; 1. Can we determine the mime type based on file contents?
|
;; 1. Can we determine the mime type based on file contents?
|
||||||
;; 2. Assuming that 7-bit ASCII is correct for mime-type
|
;; 2. Assuming that 7-bit ASCII is correct for mime-type
|
||||||
(define (make-get-mime-type a-path)
|
(define (make-get-mime-type a-path)
|
||||||
(let ([MIME-TYPE-TABLE (make-hash-table)]
|
(let ([MIME-TYPE-TABLE (read-mime-types a-path)]
|
||||||
[DEFAULT-MIME-TYPE #"text/plain; charset=utf-8"]
|
[DEFAULT-MIME-TYPE #"text/plain; charset=utf-8"]
|
||||||
[file-suffix-regexp (byte-regexp #".*\\.([^\\.]*$)")])
|
[file-suffix-regexp (byte-regexp #".*\\.([^\\.]*$)")])
|
||||||
(with-input-from-file a-path
|
|
||||||
(lambda ()
|
|
||||||
(let loop ()
|
|
||||||
(match (read-line (current-input-port) 'any)
|
|
||||||
[(? eof-object?)
|
|
||||||
(void)]
|
|
||||||
[(regexp #"^([^\t ]+)[\t ]+(.+)$"
|
|
||||||
(list s type exts))
|
|
||||||
(for-each (lambda (ext)
|
|
||||||
(hash-table-put! MIME-TYPE-TABLE
|
|
||||||
(lowercase-symbol! ext)
|
|
||||||
type))
|
|
||||||
(regexp-split #" " exts))
|
|
||||||
(loop)]
|
|
||||||
[_
|
|
||||||
(loop)]))))
|
|
||||||
(lambda (path)
|
(lambda (path)
|
||||||
(match (regexp-match file-suffix-regexp (path->bytes path))
|
(match (regexp-match file-suffix-regexp (path->bytes path))
|
||||||
[(list path-bytes sffx)
|
[(list path-bytes sffx)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||||
(provide dispatch-files-tests)
|
(provide dispatch-files-tests)
|
||||||
|
|
||||||
|
; XXX
|
||||||
(define dispatch-files-tests
|
(define dispatch-files-tests
|
||||||
(test-suite
|
(test-suite
|
||||||
"Files")))
|
"Files")))
|
|
@ -2,6 +2,7 @@
|
||||||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||||
(provide dispatch-lang-tests)
|
(provide dispatch-lang-tests)
|
||||||
|
|
||||||
|
; XXX
|
||||||
(define dispatch-lang-tests
|
(define dispatch-lang-tests
|
||||||
(test-suite
|
(test-suite
|
||||||
"Web Language")))
|
"Web Language")))
|
|
@ -2,6 +2,7 @@
|
||||||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||||
(provide dispatch-passwords-tests)
|
(provide dispatch-passwords-tests)
|
||||||
|
|
||||||
|
; XXX
|
||||||
(define dispatch-passwords-tests
|
(define dispatch-passwords-tests
|
||||||
(test-suite
|
(test-suite
|
||||||
"Passwords")))
|
"Passwords")))
|
|
@ -2,6 +2,7 @@
|
||||||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||||
(provide dispatch-servlets-tests)
|
(provide dispatch-servlets-tests)
|
||||||
|
|
||||||
|
; XXX
|
||||||
(define dispatch-servlets-tests
|
(define dispatch-servlets-tests
|
||||||
(test-suite
|
(test-suite
|
||||||
"Servlets")))
|
"Servlets")))
|
|
@ -2,6 +2,7 @@
|
||||||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||||
(provide abort-resume-tests)
|
(provide abort-resume-tests)
|
||||||
|
|
||||||
|
; XXX
|
||||||
(define abort-resume-tests
|
(define abort-resume-tests
|
||||||
(test-suite
|
(test-suite
|
||||||
"Abort Resume")))
|
"Abort Resume")))
|
|
@ -2,6 +2,7 @@
|
||||||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||||
(provide web-cells-tests)
|
(provide web-cells-tests)
|
||||||
|
|
||||||
|
; XXX
|
||||||
(define web-cells-tests
|
(define web-cells-tests
|
||||||
(test-suite
|
(test-suite
|
||||||
"Web Cells")))
|
"Web Cells")))
|
|
@ -2,6 +2,7 @@
|
||||||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||||
(provide web-extras-tests)
|
(provide web-extras-tests)
|
||||||
|
|
||||||
|
; XXX
|
||||||
(define web-extras-tests
|
(define web-extras-tests
|
||||||
(test-suite
|
(test-suite
|
||||||
"Web Extras")))
|
"Web Extras")))
|
|
@ -2,6 +2,7 @@
|
||||||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||||
(provide web-tests)
|
(provide web-tests)
|
||||||
|
|
||||||
|
; XXX
|
||||||
(define web-tests
|
(define web-tests
|
||||||
(test-suite
|
(test-suite
|
||||||
"Web")))
|
"Web")))
|
|
@ -2,6 +2,7 @@
|
||||||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||||
(provide cache-table-tests)
|
(provide cache-table-tests)
|
||||||
|
|
||||||
|
; XXX
|
||||||
(define cache-table-tests
|
(define cache-table-tests
|
||||||
(test-suite
|
(test-suite
|
||||||
"Cache Table")))
|
"Cache Table")))
|
|
@ -2,6 +2,7 @@
|
||||||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||||
(provide connection-manager-tests)
|
(provide connection-manager-tests)
|
||||||
|
|
||||||
|
; XXX
|
||||||
(define connection-manager-tests
|
(define connection-manager-tests
|
||||||
(test-suite
|
(test-suite
|
||||||
"Connection Manager")))
|
"Connection Manager")))
|
|
@ -1,7 +1,42 @@
|
||||||
(module mime-types-test mzscheme
|
(module mime-types-test mzscheme
|
||||||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2))
|
||||||
|
(lib "file.ss")
|
||||||
|
(lib "mime-types.ss" "web-server" "private"))
|
||||||
(provide mime-types-tests)
|
(provide mime-types-tests)
|
||||||
|
|
||||||
|
(define test-file (make-temporary-file))
|
||||||
|
(with-output-to-file test-file
|
||||||
|
(lambda ()
|
||||||
|
(printf #<<END
|
||||||
|
video/mp4 mp4
|
||||||
|
video/mpeg mpeg mpg mpe
|
||||||
|
END
|
||||||
|
))
|
||||||
|
'replace)
|
||||||
|
|
||||||
(define mime-types-tests
|
(define mime-types-tests
|
||||||
(test-suite
|
(test-suite
|
||||||
"MIME Types")))
|
"MIME Types"
|
||||||
|
|
||||||
|
(test-case
|
||||||
|
"Distribution mime.types parses"
|
||||||
|
(check-not-false (read-mime-types (build-path (collection-path "web-server") "default-web-root" "mime.types"))))
|
||||||
|
|
||||||
|
(test-case
|
||||||
|
"Test file parses"
|
||||||
|
(check-not-false (read-mime-types test-file)))
|
||||||
|
(test-case
|
||||||
|
"Default mime-type given"
|
||||||
|
(check-equal? ((make-get-mime-type test-file) (build-path "test.html")) #"text/plain; charset=utf-8"))
|
||||||
|
(test-case
|
||||||
|
"MIME type resolves (single in file)"
|
||||||
|
(check-equal? ((make-get-mime-type test-file) (build-path "test.mp4")) #"video/mp4"))
|
||||||
|
(test-case
|
||||||
|
"MIME type resolves (multiple in file)"
|
||||||
|
(check-equal? ((make-get-mime-type test-file) (build-path "test.mpeg")) #"video/mpeg"))
|
||||||
|
(test-case
|
||||||
|
"MIME type resolves (multiple in file)"
|
||||||
|
(check-equal? ((make-get-mime-type test-file) (build-path "test.mpg")) #"video/mpeg"))
|
||||||
|
(test-case
|
||||||
|
"MIME type resolves (multiple in file)"
|
||||||
|
(check-equal? ((make-get-mime-type test-file) (build-path "test.mpe")) #"video/mpeg")))))
|
|
@ -36,6 +36,7 @@
|
||||||
(lambda (f s) s)))
|
(lambda (f s) s)))
|
||||||
|
|
||||||
|
|
||||||
|
; XXX
|
||||||
(define request-tests
|
(define request-tests
|
||||||
(test-suite
|
(test-suite
|
||||||
"Request Parsing"
|
"Request Parsing"
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||||
(provide response-tests)
|
(provide response-tests)
|
||||||
|
|
||||||
|
; XXX
|
||||||
(define response-tests
|
(define response-tests
|
||||||
(test-suite
|
(test-suite
|
||||||
"HTTP Responses")))
|
"HTTP Responses")))
|
|
@ -3,6 +3,7 @@
|
||||||
(lib "servlet.ss" "web-server"))
|
(lib "servlet.ss" "web-server"))
|
||||||
(provide servlet-tests)
|
(provide servlet-tests)
|
||||||
|
|
||||||
|
; XXX
|
||||||
(define servlet-tests
|
(define servlet-tests
|
||||||
(test-suite
|
(test-suite
|
||||||
"Servlets")))
|
"Servlets")))
|
|
@ -2,6 +2,7 @@
|
||||||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||||
(provide session-tests)
|
(provide session-tests)
|
||||||
|
|
||||||
|
; XXX
|
||||||
(define session-tests
|
(define session-tests
|
||||||
(test-suite
|
(test-suite
|
||||||
"Sessions")))
|
"Sessions")))
|
|
@ -2,6 +2,7 @@
|
||||||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||||
(provide url-param-tests)
|
(provide url-param-tests)
|
||||||
|
|
||||||
|
; XXX
|
||||||
(define url-param-tests
|
(define url-param-tests
|
||||||
(test-suite
|
(test-suite
|
||||||
"URL Parameters")))
|
"URL Parameters")))
|
|
@ -2,6 +2,7 @@
|
||||||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||||
(provide util-tests)
|
(provide util-tests)
|
||||||
|
|
||||||
|
; XXX
|
||||||
(define util-tests
|
(define util-tests
|
||||||
(test-suite
|
(test-suite
|
||||||
"Utilities")))
|
"Utilities")))
|
|
@ -3,6 +3,7 @@
|
||||||
(lib "servlet.ss" "web-server"))
|
(lib "servlet.ss" "web-server"))
|
||||||
(provide servlet-tests)
|
(provide servlet-tests)
|
||||||
|
|
||||||
|
; XXX
|
||||||
(define servlet-tests
|
(define servlet-tests
|
||||||
(test-suite
|
(test-suite
|
||||||
"Servlets")))
|
"Servlets")))
|
|
@ -2,6 +2,7 @@
|
||||||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||||
(provide basic-auth-tests)
|
(provide basic-auth-tests)
|
||||||
|
|
||||||
|
; XXX
|
||||||
(define basic-auth-tests
|
(define basic-auth-tests
|
||||||
(test-suite
|
(test-suite
|
||||||
"BASIC Authentication")))
|
"BASIC Authentication")))
|
|
@ -1,7 +1,33 @@
|
||||||
(module bindings-test mzscheme
|
(module bindings-test mzscheme
|
||||||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2))
|
||||||
|
(lib "bindings.ss" "web-server" "servlet"))
|
||||||
(provide bindings-tests)
|
(provide bindings-tests)
|
||||||
|
|
||||||
|
(define bs `([foo . 3] [foos . 1] [foos . 2]))
|
||||||
|
|
||||||
(define bindings-tests
|
(define bindings-tests
|
||||||
(test-suite
|
(test-suite
|
||||||
"Bindings")))
|
"Bindings"
|
||||||
|
|
||||||
|
(test-case
|
||||||
|
"exists-binding? - true"
|
||||||
|
(check-true (exists-binding? 'foo bs)))
|
||||||
|
(test-case
|
||||||
|
"exists-binding? - false"
|
||||||
|
(check-false (exists-binding? 'bar bs)))
|
||||||
|
|
||||||
|
(test-case
|
||||||
|
"extract-bindings"
|
||||||
|
(check-equal? (extract-bindings 'foos bs) (list 1 2)))
|
||||||
|
|
||||||
|
(test-case
|
||||||
|
"extract-binding/single - success"
|
||||||
|
(check-equal? (extract-binding/single 'foo bs) 3))
|
||||||
|
(test-case
|
||||||
|
"extract-binding/single - failure"
|
||||||
|
(check-exn (lambda (exn) (regexp-match "not found" (exn-message exn)))
|
||||||
|
(lambda () (extract-binding/single 'bar bs) 3)))
|
||||||
|
(test-case
|
||||||
|
"extract-binding/single - multiple"
|
||||||
|
(check-exn (lambda (exn) (regexp-match "multiple times" (exn-message exn)))
|
||||||
|
(lambda () (extract-binding/single 'foos bs) 3))))))
|
|
@ -2,6 +2,7 @@
|
||||||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||||
(provide helpers-tests)
|
(provide helpers-tests)
|
||||||
|
|
||||||
|
; XXX
|
||||||
(define helpers-tests
|
(define helpers-tests
|
||||||
(test-suite
|
(test-suite
|
||||||
"Helpers")))
|
"Helpers")))
|
|
@ -2,6 +2,7 @@
|
||||||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||||
(provide servlet-url-tests)
|
(provide servlet-url-tests)
|
||||||
|
|
||||||
|
; XXX
|
||||||
(define servlet-url-tests
|
(define servlet-url-tests
|
||||||
(test-suite
|
(test-suite
|
||||||
"Servlet URLs")))
|
"Servlet URLs")))
|
|
@ -2,6 +2,7 @@
|
||||||
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
|
||||||
(provide web-tests)
|
(provide web-tests)
|
||||||
|
|
||||||
|
; XXX
|
||||||
(define web-tests
|
(define web-tests
|
||||||
(test-suite
|
(test-suite
|
||||||
"Web")))
|
"Web")))
|
Loading…
Reference in New Issue
Block a user