mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-08-19 03:57:21 +00:00
add tests for ring plugin
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
*.o
|
||||
*.py[co]
|
||||
*.class
|
||||
*.jar
|
||||
|
||||
/uwsgi
|
||||
/uwsgibuild.*
|
||||
|
||||
/t/ring/target
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
Ring Test Suite
|
||||
================
|
||||
|
||||
how to build and run
|
||||
---------------------
|
||||
|
||||
* cd UWSGIROOT
|
||||
* cd t/ring
|
||||
* lein uberjar
|
||||
* cd ../..
|
||||
* uwsgi t/ring/config.ini
|
||||
* open http://localhost:9090 in your browser
|
||||
|
||||
run cases in jetty
|
||||
-------------------
|
||||
|
||||
* lein ring server
|
||||
* open http://localhost:3000 in your browser
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
[uwsgi]
|
||||
http = :9090
|
||||
http-modifier1 = 8
|
||||
http-modifier2 = 1
|
||||
|
||||
jvm-classpath = plugins/jvm/uwsgi.jar
|
||||
jvm-classpath = t/ring/target/uwsgi-ring-tests-0.0.1-standalone.jar
|
||||
|
||||
ring-app = uwsgi.ring.tests.app:app
|
||||
@@ -0,0 +1,10 @@
|
||||
(defproject unbit/uwsgi-ring-tests "0.0.1"
|
||||
:description "uwsgi-ring-tests: test cases for uwsgi ring server"
|
||||
:dependencies [[org.clojure/clojure "1.4.0"]
|
||||
[compojure "1.1.3"]
|
||||
[ring/ring "1.1.0"]]
|
||||
|
||||
:source-paths ["src"]
|
||||
|
||||
:plugins [[lein-ring "0.7.5"]]
|
||||
:ring {:handler uwsgi.ring.tests.app/app})
|
||||
@@ -0,0 +1,29 @@
|
||||
(ns uwsgi.ring.tests.app
|
||||
(:use compojure.core)
|
||||
(:use [ring.middleware params
|
||||
keyword-params
|
||||
nested-params
|
||||
multipart-params])
|
||||
(:require [compojure.route :as route]
|
||||
[uwsgi.ring.tests.basic :as basic]
|
||||
[uwsgi.ring.tests.body :as body]
|
||||
[uwsgi.ring.tests.simple :as simple]
|
||||
[uwsgi.ring.tests.upload :as upload])
|
||||
(:gen-class
|
||||
:main true))
|
||||
|
||||
(defn app-routes [req]
|
||||
(if (= (get req :uri) "/")
|
||||
(basic/index-page req)
|
||||
((routes simple/app-routes body/app-routes upload/app-routes) req)))
|
||||
|
||||
(def app
|
||||
(-> app-routes
|
||||
wrap-keyword-params
|
||||
wrap-nested-params
|
||||
wrap-params
|
||||
wrap-multipart-params))
|
||||
|
||||
(defn -main [& args]
|
||||
(println "uwsgi ring tests app loaded"))
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
(ns uwsgi.ring.tests.basic)
|
||||
|
||||
(defn index-page [req] {:status 200
|
||||
:headers { "Content-Type" "text/html" , "Server" "uWSGI" }
|
||||
:body (str "<h1>Ring test suites</h1>"
|
||||
"<h2>Simple tests</h2>"
|
||||
"<ul>"
|
||||
"<li><a href='/hello'>hello</a></li>"
|
||||
"<li><a href='/echo?msg=abc'>echo</a></li>"
|
||||
"<li><a href='/palindrome?msg=abc'>palindrome</a></li>"
|
||||
"</ul>"
|
||||
"<h2>Body type tests</h2>"
|
||||
"<ul>"
|
||||
"<li><a href='/sequence'>sequence</a></li>"
|
||||
"<li><a href='/file'>file</a></li>"
|
||||
"<li><a href='/stream'>stream</a></li>"
|
||||
"</ul>"
|
||||
"<h2>Upload tests</h2>"
|
||||
"<form action='/upload' enctype='multipart/form-data' method='post'>"
|
||||
"<p>"
|
||||
"Please select a file<br>"
|
||||
"<input type='file' name='file' size='40'>"
|
||||
"</p>"
|
||||
"<input type='submit' value='Upload'>"
|
||||
"</form>"
|
||||
"<h2>Other tests</h2>"
|
||||
"<ul>"
|
||||
"<li>...</li>"
|
||||
"</ul>")})
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
(ns uwsgi.ring.tests.body
|
||||
(:use [compojure.core]))
|
||||
|
||||
; generating primary numbers
|
||||
; http://clojuredocs.org/clojure_core/clojure.core/lazy-seq#example_1000
|
||||
(defn sieve [s]
|
||||
(cons (first s)
|
||||
(lazy-seq (sieve (filter #(not= 0 (mod % (first s)))
|
||||
(rest s))))))
|
||||
|
||||
(defn sequence [] (take 20 (sieve (iterate inc 2))))
|
||||
|
||||
(defn file [] (java.io.File. "CONTRIBUTORS"))
|
||||
|
||||
(defn stream [] (java.io.FileInputStream. (java.io.File. "CONTRIBUTORS")))
|
||||
|
||||
(defroutes app-routes
|
||||
(GET "/sequence" [] (sequence))
|
||||
(GET "/file" [] (file))
|
||||
(GET "/stream" [] (stream)))
|
||||
@@ -0,0 +1,13 @@
|
||||
(ns uwsgi.ring.tests.simple
|
||||
(:use [compojure.core]))
|
||||
|
||||
(defn hello [] "Hello, World!")
|
||||
|
||||
(defn echo [msg] msg)
|
||||
|
||||
(defn palindrome [msg] (clojure.string/reverse msg))
|
||||
|
||||
(defroutes app-routes
|
||||
(GET "/hello" [] (hello))
|
||||
(GET "/echo" [msg] (echo msg))
|
||||
(GET "/palindrome" [msg] (palindrome msg)))
|
||||
@@ -0,0 +1,20 @@
|
||||
(ns uwsgi.ring.tests.upload
|
||||
(:use [compojure.core]))
|
||||
|
||||
(defn upload-file [fname fsize fbody] {
|
||||
:status 200
|
||||
:headers { "Content-Type" "text/html" , "Server" "uWSGI" }
|
||||
:body (str "<h1>Uploaded file</h1>"
|
||||
"<ul>"
|
||||
"<li>" fname "</li>"
|
||||
"<li>" fsize "</li>"
|
||||
"</ul>")})
|
||||
|
||||
(defroutes app-routes
|
||||
(POST "/upload" {params :params}
|
||||
(let [file (params :file)
|
||||
file-name (file :filename)
|
||||
file-size (file :size)
|
||||
file-body (file :tempfile)]
|
||||
(upload-file file-name file-size file-body))))
|
||||
|
||||
Reference in New Issue
Block a user