gnu: linux-libre@4.14: Update to 4.14.198.
[jackhill/guix/guix.git] / tests / publish.scm
index 80e0977..1c3b278 100644 (file)
@@ -1,6 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2015 David Thompson <davet@gnu.org>
-;;; Copyright © 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -35,8 +35,8 @@
   #:use-module ((guix serialization) #:select (restore-file))
   #:use-module (gcrypt pk-crypto)
   #:use-module ((guix pki) #:select (%public-key-file %private-key-file))
-  #:use-module (guix zlib)
-  #:use-module (guix lzlib)
+  #:use-module (zlib)
+  #:use-module (lzlib)
   #:use-module (web uri)
   #:use-module (web client)
   #:use-module (web response)
@@ -45,6 +45,7 @@
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-26)
   #:use-module (srfi srfi-64)
+  #:use-module (ice-9 threads)
   #:use-module (ice-9 format)
   #:use-module (ice-9 match)
   #:use-module (ice-9 rdelim))
                   "StorePath: ~a
 URL: nar/~a
 Compression: none
+FileSize: ~a
 NarHash: sha256:~a
 NarSize: ~d
-References: ~a
-FileSize: ~a~%"
+References: ~a~%"
                   %item
                   (basename %item)
+                  (path-info-nar-size info)
                   (bytevector->nix-base32-string
                    (path-info-hash info))
                   (path-info-nar-size info)
-                  (basename (first (path-info-references info)))
-                  (path-info-nar-size info)))
+                  (basename (first (path-info-references info)))))
          (signature (base64-encode
                      (string->utf8
                       (canonical-sexp->string
-                       ((@@ (guix scripts publish) signed-string)
-                        unsigned-info))))))
+                       (signed-string unsigned-info))))))
     (format #f "~aSignature: 1;~a;~a~%"
             unsigned-info (gethostname) signature))
   (utf8->string
@@ -170,21 +170,20 @@ FileSize: ~a~%"
                   "StorePath: ~a
 URL: nar/~a
 Compression: none
+FileSize: ~a
 NarHash: sha256:~a
 NarSize: ~d
-References: ~%\
-FileSize: ~a~%"
+References: ~%"
                   item
                   (uri-encode (basename item))
+                  (path-info-nar-size info)
                   (bytevector->nix-base32-string
                    (path-info-hash info))
-                  (path-info-nar-size info)
                   (path-info-nar-size info)))
          (signature (base64-encode
                      (string->utf8
                       (canonical-sexp->string
-                       ((@@ (guix scripts publish) signed-string)
-                        unsigned-info))))))
+                       (signed-string unsigned-info))))))
     (format #f "~aSignature: 1;~a;~a~%"
             unsigned-info (gethostname) signature))
 
@@ -205,8 +204,6 @@ FileSize: ~a~%"
        (call-with-input-string nar (cut restore-file <> temp)))
      (call-with-input-file temp read-string))))
 
-(unless (zlib-available?)
-  (test-skip 1))
 (test-equal "/nar/gzip/*"
   "bar"
   (call-with-temporary-output-file
@@ -218,8 +215,6 @@ FileSize: ~a~%"
          (cut restore-file <> temp)))
      (call-with-input-file temp read-string))))
 
-(unless (zlib-available?)
-  (test-skip 1))
 (test-equal "/nar/gzip/* is really gzip"
   %gzip-magic-bytes
   ;; Since 'gzdopen' (aka. 'call-with-gzip-input-port') transparently reads
@@ -230,8 +225,6 @@ FileSize: ~a~%"
                (string-append "/nar/gzip/" (basename %item))))))
     (get-bytevector-n nar (bytevector-length %gzip-magic-bytes))))
 
-(unless (lzlib-available?)
-  (test-skip 1))
 (test-equal "/nar/lzip/*"
   "bar"
   (call-with-temporary-output-file
@@ -243,8 +236,6 @@ FileSize: ~a~%"
          (cut restore-file <> temp)))
      (call-with-input-file temp read-string))))
 
-(unless (zlib-available?)
-  (test-skip 1))
 (test-equal "/*.narinfo with compression"
   `(("StorePath" . ,%item)
     ("URL" . ,(string-append "nar/gzip/" (basename %item)))
@@ -265,8 +256,6 @@ FileSize: ~a~%"
                   (_ #f)))
               (recutils->alist body)))))
 
-(unless (lzlib-available?)
-  (test-skip 1))
 (test-equal "/*.narinfo with lzip compression"
   `(("StorePath" . ,%item)
     ("URL" . ,(string-append "nar/lzip/" (basename %item)))
@@ -287,8 +276,6 @@ FileSize: ~a~%"
                   (_ #f)))
               (recutils->alist body)))))
 
-(unless (zlib-available?)
-  (test-skip 1))
 (test-equal "/*.narinfo for a compressed file"
   '("none" "nar")          ;compression-less nar
   ;; Assume 'guix publish -C' is already running on port 6799.
@@ -301,6 +288,33 @@ FileSize: ~a~%"
     (list (assoc-ref info "Compression")
           (dirname (assoc-ref info "URL")))))
 
+(test-equal "/*.narinfo with lzip + gzip"
+  `((("StorePath" . ,%item)
+     ("URL" . ,(string-append "nar/gzip/" (basename %item)))
+     ("Compression" . "gzip")
+     ("URL" . ,(string-append "nar/lzip/" (basename %item)))
+     ("Compression" . "lzip"))
+    200
+    200)
+  (call-with-temporary-directory
+   (lambda (cache)
+     (let ((thread (with-separate-output-ports
+                    (call-with-new-thread
+                     (lambda ()
+                       (guix-publish "--port=6793" "-Cgzip:2" "-Clzip:2"))))))
+       (wait-until-ready 6793)
+       (let* ((base "http://localhost:6793/")
+              (part (store-path-hash-part %item))
+              (url  (string-append base part ".narinfo"))
+              (body (http-get-port url)))
+         (list (take (recutils->alist body) 5)
+               (response-code
+                (http-get (string-append base "nar/gzip/"
+                                         (basename %item))))
+               (response-code
+                (http-get (string-append base "nar/lzip/"
+                                         (basename %item))))))))))
+
 (test-equal "custom nar path"
   ;; Serve nars at /foo/bar/chbouib instead of /nar.
   (list `(("StorePath" . ,%item)
@@ -383,8 +397,6 @@ FileSize: ~a~%"
                               (call-with-input-string "" port-sha256))))))
     (response-code (http-get uri))))
 
-(unless (zlib-available?)
-  (test-skip 1))
 (test-equal "with cache"
   (list #t
         `(("StorePath" . ,%item)
@@ -441,8 +453,50 @@ FileSize: ~a~%"
                          (stat:size (stat nar)))
                       (response-code uncompressed)))))))))
 
-(unless (zlib-available?)
-  (test-skip 1))
+(test-equal "with cache, lzip + gzip"
+  '(200 200 404)
+  (call-with-temporary-directory
+   (lambda (cache)
+     (let ((thread (with-separate-output-ports
+                    (call-with-new-thread
+                     (lambda ()
+                       (guix-publish "--port=6794" "-Cgzip:2" "-Clzip:2"
+                                     (string-append "--cache=" cache)))))))
+       (wait-until-ready 6794)
+       (let* ((base     "http://localhost:6794/")
+              (part     (store-path-hash-part %item))
+              (url      (string-append base part ".narinfo"))
+              (nar-url  (cute string-append "nar/" <> "/"
+                              (basename %item)))
+              (cached   (cute string-append cache "/" <> "/"
+                              (basename %item) ".narinfo"))
+              (nar      (cute string-append cache "/" <> "/"
+                              (basename %item) ".nar"))
+              (response (http-get url)))
+         (wait-for-file (cached "gzip"))
+         (let* ((body         (http-get-port url))
+                (narinfo      (recutils->alist body))
+                (uncompressed (string-append base "nar/"
+                                             (basename %item))))
+           (and (file-exists? (nar "gzip"))
+                (file-exists? (nar "lzip"))
+                (equal? (take (pk 'narinfo/gzip+lzip narinfo) 7)
+                        `(("StorePath" . ,%item)
+                          ("URL" . ,(nar-url "gzip"))
+                          ("Compression" . "gzip")
+                          ("FileSize" . ,(number->string
+                                          (stat:size (stat (nar "gzip")))))
+                          ("URL" . ,(nar-url "lzip"))
+                          ("Compression" . "lzip")
+                          ("FileSize" . ,(number->string
+                                          (stat:size (stat (nar "lzip")))))))
+                (list (response-code
+                       (http-get (string-append base (nar-url "gzip"))))
+                      (response-code
+                       (http-get (string-append base (nar-url "lzip"))))
+                      (response-code
+                       (http-get uncompressed))))))))))
+
 (let ((item (add-text-to-store %store "fake-compressed-thing.tar.gz"
                                (random-text))))
   (test-equal "with cache, uncompressed"
@@ -522,9 +576,7 @@ FileSize: ~a~%"
               (item     (add-text-to-store %store "random" (random-text)))
               (part     (store-path-hash-part item))
               (url      (string-append base part ".narinfo"))
-              (cached   (string-append cache
-                                       (if (zlib-available?)
-                                           "/gzip/" "/none/")
+              (cached   (string-append cache "/gzip/"
                                        (basename item)
                                        ".narinfo"))
               (response (http-get url)))