From ad3479304e95ff12c3356bc5248382511b358545 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 12 Sep 2014 21:39:35 -0400 Subject: test: Add coverage for render module. * tests/guix-web/render.scm: New file. --- guix-web/render.scm | 1 + tests/guix-web/render.scm | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 tests/guix-web/render.scm diff --git a/guix-web/render.scm b/guix-web/render.scm index e4f8771..024bcf7 100644 --- a/guix-web/render.scm +++ b/guix-web/render.scm @@ -52,6 +52,7 @@ (define (redirect path) (let ((uri (build-uri 'http + #:host "localhost" #:path (string-append "/" (encode-and-join-uri-path path))))) (list (build-response diff --git a/tests/guix-web/render.scm b/tests/guix-web/render.scm new file mode 100644 index 0000000..ed1b120 --- /dev/null +++ b/tests/guix-web/render.scm @@ -0,0 +1,68 @@ +;;; guix-web - Web interface for GNU Guix +;;; Copyright © 2014 David Thompson +;;; +;;; This program is free software: you can redistribute it and/or +;;; modify it under the terms of the GNU Affero General Public License +;;; as published by the Free Software Foundation, either version 3 of +;;; the License, or (at your option) any later version. +;;; +;;; This program is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; Affero General Public License for more details. +;;; +;;; You should have received a copy of the GNU Affero General Public +;;; License along with this program. If not, see +;;; . + +(define-module (tests guix-web render) + #:use-module (ice-9 match) + #:use-module (srfi srfi-64) + #:use-module (web response) + #:use-module (web uri) + #:use-module (json) + #:use-module (guix-web render)) + +(define render-to-string + (match-lambda + ((headers render-proc) + (list headers (call-with-output-string render-proc))))) + +(test-begin "render") + +(test-equal "render-html" + '(((content-type . (text/html))) + "guix-web") + (render-to-string + (render-html '(html (head (title "guix-web")))))) + +(test-equal "render-json" + '(((content-type . (application/json))) + "{\"foo\" : [1, 2, 3]}") + (render-to-string + (render-json (json (object ("foo" (1 2 3))))))) + +(test-equal "not-found" + (list (build-response #:code 404) + "Resource not found: http://localhost/foo") + (not-found (string->uri "http://localhost/foo"))) + +(test-equal "unprocessable-entity" + (list (build-response #:code 422) "") + (unprocessable-entity)) + +(test-equal "created" + (list (build-response #:code 201) "") + (created)) + +(test-equal "redirect" + (list (build-response + #:code 301 + #:headers `((content-type . (text/html)) + (location . ,(string->uri "http://localhost/foo/bar")))) + "Redirect to http://localhost/foo/bar") + (redirect '("foo" "bar"))) + +(test-end) + +(exit (= (test-runner-fail-count (test-runner-current)) 0)) -- cgit v1.2.3