Skip to content

Instantly share code, notes, and snippets.

@paul
Created August 30, 2011 19:57
Show Gist options
  • Save paul/1181856 to your computer and use it in GitHub Desktop.
Save paul/1181856 to your computer and use it in GitHub Desktop.
(ns seraph.test.api
(:use
[clojure.test]
[picard test helpers])
(:require
[seraph.config :as config]
[seraph.routing :as routing]))
(defn handle-request
[{host :host :as hdrs} body]
(cond
(= "api.strobeapp.com" host)
[200 {:request-hdrs hdrs} "you got api.strobeapp.com"]
(= "api.strobeapp.local" host)
[200 {:request-hdrs hdrs} "you got api.strobeapp.local"]
:else
[404 {} ""]))
(defn- mock-proxy
[dn]
(defstream
(request [[hdrs body]]
(dn :response (handle-request hdrs body)))))
(defmacro with-stack
[opts & stmts]
(if-not (map? opts)
`(with-stack {} ~opts ~@stmts)
`(with-app
(routing/mk-stack
{:api-proxy mock-proxy})
~@stmts)))
(deftest ^{:focus true} forwards-api-request-default
(with-stack
(GET "api.strobeapp.com/applications")
(is (= 200 (last-response-status)))))
(deftest forwards-api-request-configured
(config/with-config
{:api-host "api.strobeapp.local"}
(with-stack
(GET "api.strobeapp.com/applications")
(is (= 200 (last-response-status))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment