emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] 30/119: fleshed out some more tests


From: Eric Schulte
Subject: [elpa] 30/119: fleshed out some more tests
Date: Mon, 10 Mar 2014 16:57:10 +0000

eschulte pushed a commit to branch master
in repository elpa.

commit 37880de88caf05b4901813e7566689187a176880
Author: Eric Schulte <address@hidden>
Date:   Thu Dec 19 22:15:49 2013 -0700

    fleshed out some more tests
---
 emacs-web-server-test.el |   78 ++++++++++++++++++++++++++++++++++-----------
 1 files changed, 59 insertions(+), 19 deletions(-)

diff --git a/emacs-web-server-test.el b/emacs-web-server-test.el
index efe0cb3..670878f 100644
--- a/emacs-web-server-test.el
+++ b/emacs-web-server-test.el
@@ -5,7 +5,8 @@
 ;; Author: Eric Schulte <address@hidden>
 ;; License: GPLV3 (see the COPYING file in this directory)
 
-;;; TODO: fill in these tests, and then write more
+;; TODO: Allow running all tests at once, or just run tests in two
+;;       different Emacs instances.
 
 ;;; Code:
 (require 'emacs-web-server)
@@ -27,7 +28,24 @@
 
 (defvar ews-test-port 8999)
 
-(ert-deftest ews/hello-world-server ()
+(ert-deftest ews/keyword-style-handler ()
+  "Ensure that a simple keyword-style handler matches correctly."
+  (let ((handler (mapcar (lambda (letter)
+                           `((:GET . ,letter) .
+                             (lambda (proc request)
+                               (ews-response-header proc 200
+                                 '("Content-type" . "text/plain"))
+                               (process-send-string proc
+                                 (concat "returned:" ,letter)))))
+                         '("a" "b"))))
+    (lexical-let ((server (ews-start handler ews-test-port)))
+      (ews-test-run-asynch
+       (lambda (response)
+         (should (string= response "returned:a"))
+         (ews-stop server))
+       "curl" "-s" (format "localhost:%d/a" ews-test-port)))))
+
+(ert-deftest ews/function-style-handler ()
   "Test that a simple hello-world server responds."
   (lexical-let
       ((server
@@ -44,28 +62,42 @@
        (ews-stop server))
      "curl" "-s" (format "localhost:%d" ews-test-port))))
 
-(ert-deftest ews/keyword-style-handler ()
-  "Ensure that a simple keyword-style handler matches correctly."
-  (should t)                            ; should match one
-  (should-not nil)                      ; should not match another
-  )
-
-(ert-deftest ews/function-style-handler ()
-  "Ensure that a function-style handler matches correctly."
-  (should t)                            ; should match one
-  (should-not nil)                      ; should not match another
-  )
-
 (ert-deftest ews/removed-from-ews-servers-after-stop ()
-  (should t))
+  (let ((start-length (length ews-servers)))
+    (let ((server (ews-start nil ews-test-port)))
+      (should (= (length ews-servers) (+ 1 start-length)))
+      (ews-stop server)
+      (should (= (length ews-servers) start-length)))))
 
 (ert-deftest ews/parse-many-headers ()
   "Test that a number of headers parse successfully."
-  (should t))
+  (let ((server (ews-start nil ews-test-port))
+        (client (make-instance 'ews-client))
+        (header-string "GET / HTTP/1.1
+Host: localhost:7777
+User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:26.0) Gecko/20100101 
Firefox/26.0
+Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
+Accept-Language: en-US,en;q=0.5
+Accept-Encoding: gzip, deflate
+DNT: 1
+Cookie: __utma=111872281.1462392269.1345929539.1345929539.1345929539.1
+Connection: keep-alive
+
+"))
+    (unwind-protect
+        (progn
+          (ews-do-filter (process server) client header-string)
+          (let ((headers (cdr (headers client))))
+            (should (string= (cdr (assoc :ACCEPT-ENCODING headers))
+                             "gzip, deflate"))
+            (should (string= (cdr (assoc :GET headers)) "/"))
+            (should (string= (cdr (assoc :CONNECTION headers)) "keep-alive"))))
+      (ews-stop server))))
 
 (ert-deftest ews/parse-post-data ()
-  (let ((post-header
-         "POST / HTTP/1.1
+  (let ((server (ews-start nil ews-test-port))
+        (client (make-instance 'ews-client))
+        (header-string "POST / HTTP/1.1
 User-Agent: curl/7.33.0
 Host: localhost:8080
 Accept: */*
@@ -84,4 +116,12 @@ Content-Disposition: form-data; name=\"name\"
 \"schulte\"
 ------------------f1270d0deb77af03--
 "))
-    (should 'properly-parse-post-data)))
+    (unwind-protect
+        (progn
+          (ews-do-filter (process server) client header-string)
+          (let ((headers (cdr (headers client))))
+            (should (string= (cdr (assoc "name" headers))
+                             "\"schulte\""))
+            (should (string= (cdr (assoc "date" headers))
+                             "Wed Dec 18 00:55:39 MST 2013"))))
+      (ews-stop server))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]