(define-module (ldp-primer) #:use-module (srfi srfi-64) #:use-module (web request) #:use-module (web response) #:use-module (web uri) #:use-module (ldp) #:use-module (ldp precondition) #:use-module (ldp resource update) #:use-module (rnrs bytevectors)) (system* "rm" "-rf" "primer") (catch #t (lambda () (mkdir "primer")) (lambda err #t)) (chdir "primer") (test-begin "setup") (let ((request (call-with-input-string "POST / HTTP/1.1\r\n\ Host: example.org\r\n\ Content-Type: text/turtle\r\n\ Link: ; rel=\"type\"\r\n\ Slug: alice\r\n\r\n" read-request)) (request-body "@prefix dcterms: . @prefix ldp: . a ldp:Container, ldp:BasicContainer; dcterms:title 'Alice’s data storage on the Web' .")) (call-with-values (lambda () (respond request request-body)) (lambda (response response-body) (test-equal "Slug is respected on empty container" (string->uri-reference "/alice") (response-location response))))) (test-end "setup") (test-begin "example1-2") (let ((request (call-with-input-string "GET /alice/ HTTP/1.1\r\n\ Host: example.org\r\n\ Accept: text/turtle\r\n\r\n" read-request)) (request-body #f)) (call-with-values (lambda () (respond request request-body)) (lambda (response response-body) (test-eq "Example 2: OK" 200 (response-code response)) (test-eq "Example 2: content-type" 'text/turtle (car (response-content-type response))) (test-equal "Example 2: links" "; rel=\"type\", ; rel=\"type\"" (assoc-ref (response-headers response) 'link)) (test-equal "Example 2: allow" '(HEAD GET POST PUT DELETE OPTIONS) (response-allow response)) (test-eq "Example 2: has ETag" #t (not (not (response-etag response)))) (test-eq "Example 2: ETag is strong" #t (cdr (response-etag response))) (test-equal "Example 2: content" "@prefix dcterms: . @prefix ldp: . a ldp:Container, ldp:BasicContainer; dcterms:title 'Alice’s data storage on the Web' . a , . " (utf8->string response-body))))) (test-end "example1-2") (test-begin "cleanup") (let ((request (call-with-input-string "DELETE /alice HTTP/1.1\r\n\ Host: example.org\r\n\r\n" read-request)) (request-body #f)) (call-with-values (lambda () (respond request request-body)) (lambda (response response-body) (test-eq "Cleaning OK" 200 (response-code response))))) (test-end "cleanup") (delete-file "representation/manifest.xml") (delete-file "representation/content") (rmdir "representation") (chdir "..") (rmdir "primer")