proxy/proxy-test.ss
(module proxy-test mzscheme
  
  (require
   (lib "tcp-unit.ss" "net")
   (lib "url.ss" "net")

   (planet "test.ss" ("schematics" "schemeunit.plt" 2))
   (file "proxy.ss"))
  
  (provide proxy-tests)

  (define (request->path method url headers)
    (cond [(regexp-match #rx#"local.html$" url)
           (string->path "local.html")]
          [else #f]))
  
  ;; Assume all connections go through the proxy
  (define shutdown-proxy
    (run-proxy request->path #f 7654 10 tcp@))
  (current-proxy-servers '(("http" "localhost" 7654)))

  ; Wait for the proxy to start up
  (sleep 1)
        
  (define proxy-tests
    (test-suite
     "All tests for proxy"

     (test-case
      "remote host is proxied"
      (let ([ip
             ;; If we ask for google.com we might get
             ;; redirected to the local version, but if we
             ;; ask for a country specific version we get it
             (get-pure-port (string->url "http://www.google.co.uk/"))])
        (after
         (check-not-false (regexp-match #rx"Google" ip))
         (close-input-port ip))))

     ))
  )