(module instaweb-test mzscheme
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
(require (lib "url.ss" "net")
(planet "port.ss" ("schematics" "port.plt" 1))
"instaweb.ss")
(provide instaweb-tests)
(define instaweb-tests
(test-suite
"All tests for instaweb"
(test-case
"Server listens on specified port and IP"
(before
(with-output-to-file "dummy.ss"
(lambda ()
(write
'(module dummy mzscheme
(require (lib "response-structs.ss" "web-server"))
(provide interface-version timeout start)
(define interface-version 'v1)
(define timeout +inf.0)
(define (start initial-request)
(make-response/full
200
"OK"
(current-seconds)
#"text/plain"
'()
'("foo\r\n"))))))
'replace)
(thread
(lambda ()
(instaweb "dummy.ss" 8000 "127.0.0.1")))
(sleep 1)
(let ((content
(get-pure-port
(string->url "http://127.0.0.1:8000/servlets/dummy.ss"))))
(check string=? (port->string content) "foo\r\n"))
(check-exn
exn:fail:network?
(lambda ()
(get-pure-port
(string->url "http://127.0.0.1:8123/servlets/dummy.ss"))))))
))
)