summaryrefslogtreecommitdiff
path: root/tests/publish.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2016-07-20 16:54:31 +0200
committerLudovic Courtès <ludo@gnu.org>2016-07-20 16:54:31 +0200
commitff6638d112d794c9c433731643711932452fd2ff (patch)
tree483ff44e6ba65eb14a1fcd8482315f14da63f252 /tests/publish.scm
parent260bc60f83b1955ac7f48b71872d3d2809132ee2 (diff)
downloadpatches-ff6638d112d794c9c433731643711932452fd2ff.tar
patches-ff6638d112d794c9c433731643711932452fd2ff.tar.gz
publish: Handle '/file' URLs, for content-addressed files.
* guix/scripts/publish.scm (render-content-addressed-file): New procedure. (http-write): Add 'application/octet-stream' case. (make-request-handler): Add /file/NAME/sha256/HASH URLs. * tests/publish.scm ("/file/NAME/sha256/HASH") ("/file/NAME/sha256/INVALID-NIX-BASE32-STRING") ("/file/NAME/sha256/INVALID-HASH"): New tests. * doc/guix.texi (Invoking guix publish): Mention the /file URLs.
Diffstat (limited to 'tests/publish.scm')
-rw-r--r--tests/publish.scm34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/publish.scm b/tests/publish.scm
index 9bf181f1fc..0ba33487bd 100644
--- a/tests/publish.scm
+++ b/tests/publish.scm
@@ -26,6 +26,8 @@
#:use-module (guix utils)
#:use-module (guix hash)
#:use-module (guix store)
+ #:use-module (guix derivations)
+ #:use-module (guix gexp)
#:use-module (guix base32)
#:use-module (guix base64)
#:use-module ((guix records) #:select (recutils->alist))
@@ -210,4 +212,36 @@ References: ~%"
(display "This file is not a valid store item." port)))
(response-code (http-get (publish-uri (string-append "/nar/invalid"))))))
+(test-equal "/file/NAME/sha256/HASH"
+ "Hello, Guix world!"
+ (let* ((data "Hello, Guix world!")
+ (hash (call-with-input-string data port-sha256))
+ (drv (run-with-store %store
+ (gexp->derivation "the-file.txt"
+ #~(call-with-output-file #$output
+ (lambda (port)
+ (display #$data port)))
+ #:hash-algo 'sha256
+ #:hash hash)))
+ (out (build-derivations %store (list drv))))
+ (utf8->string
+ (http-get-body
+ (publish-uri
+ (string-append "/file/the-file.txt/sha256/"
+ (bytevector->nix-base32-string hash)))))))
+
+(test-equal "/file/NAME/sha256/INVALID-NIX-BASE32-STRING"
+ 404
+ (let ((uri (publish-uri
+ "/file/the-file.txt/sha256/not-a-nix-base32-string")))
+ (response-code (http-get uri))))
+
+(test-equal "/file/NAME/sha256/INVALID-HASH"
+ 404
+ (let ((uri (publish-uri
+ (string-append "/file/the-file.txt/sha256/"
+ (bytevector->nix-base32-string
+ (call-with-input-string "" port-sha256))))))
+ (response-code (http-get uri))))
+
(test-end "publish")