diff options
Diffstat (limited to 'tests/ldp-primer.scm')
-rw-r--r-- | tests/ldp-primer.scm | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/tests/ldp-primer.scm b/tests/ldp-primer.scm new file mode 100644 index 0000000..cc27e4b --- /dev/null +++ b/tests/ldp-primer.scm @@ -0,0 +1,95 @@ +(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: <http://www.w3.org/ns/ldp/BasicContainer>; rel=\"type\"\r\n\ +Slug: alice\r\n\r\n" + read-request)) + (request-body "@prefix dcterms: <http://purl.org/dc/terms/>. +@prefix ldp: <http://www.w3.org/ns/ldp#>. + +<http://example.org/alice/> 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" + "<http://www.w3.org/ns/ldp#BasicContainer>; rel=\"type\", <http://www.w3.org/ns/ldp#Resource>; 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: <http://purl.org/dc/terms/>. +@prefix ldp: <http://www.w3.org/ns/ldp#>. + +<http://example.org/alice/> a ldp:Container, ldp:BasicContainer; + dcterms:title 'Alice’s data storage on the Web' . +</alice> a <http://www.w3.org/ns/ldp#Container>, + <http://www.w3.org/ns/ldp#BasicContainer> . +" + (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") |