tests: Allow opam test to run without networking.
Fixes a regression introduced in
fc29c80b96, where, since
'get-opam-repository' was no longer mocked, the test would try to access
the actual OPAM repository through a call to 'http-fetch/cached'; this
would lead to a test failure when networking is unavailable.
* tests/opam.scm ("opam->guix-package"): Mock 'get-opam-repository'
again.
			
			
This commit is contained in:
		
							parent
							
								
									511dc6877e
								
							
						
					
					
						commit
						358ad74f41
					
				
					 1 changed files with 46 additions and 44 deletions
				
			
		|  | @ -71,50 +71,52 @@ url { | ||||||
| (test-begin "opam") | (test-begin "opam") | ||||||
| 
 | 
 | ||||||
| (test-assert "opam->guix-package" | (test-assert "opam->guix-package" | ||||||
|   (mock ((guix import utils) url-fetch |   (mock ((guix import opam) get-opam-repository | ||||||
|          (lambda (url file-name) |          (const test-repo)) | ||||||
|            (match url |         (mock ((guix import utils) url-fetch | ||||||
|              ("https://example.org/foo-1.0.0.tar.gz" |                (lambda (url file-name) | ||||||
|               (begin |                  (match url | ||||||
|                 (mkdir-p "foo-1.0.0") |                    ("https://example.org/foo-1.0.0.tar.gz" | ||||||
|                 (system* "tar" "czvf" file-name "foo-1.0.0/") |                     (begin | ||||||
|                 (delete-file-recursively "foo-1.0.0") |                       (mkdir-p "foo-1.0.0") | ||||||
|                 (set! test-source-hash |                       (system* "tar" "czvf" file-name "foo-1.0.0/") | ||||||
|                   (call-with-input-file file-name port-sha256)))) |                       (delete-file-recursively "foo-1.0.0") | ||||||
|              (_ (error "Unexpected URL: " url))))) |                       (set! test-source-hash | ||||||
|         (let ((my-package (string-append test-repo |                             (call-with-input-file file-name port-sha256)))) | ||||||
|                                          "/packages/foo/foo.1.0.0"))) |                    (_ (error "Unexpected URL: " url))))) | ||||||
|           (mkdir-p my-package) |               (let ((my-package (string-append test-repo | ||||||
|           (with-output-to-file (string-append my-package "/opam") |                                                "/packages/foo/foo.1.0.0"))) | ||||||
|             (lambda _ |                 (mkdir-p my-package) | ||||||
|               (format #t "~a" test-opam-file)))) |                 (with-output-to-file (string-append my-package "/opam") | ||||||
|         (match (opam->guix-package "foo" #:repo (list test-repo)) |                   (lambda _ | ||||||
|           (('package |                     (format #t "~a" test-opam-file)))) | ||||||
|              ('name "ocaml-foo") |               (match (opam->guix-package "foo" #:repo (list test-repo)) | ||||||
|              ('version "1.0.0") |                 (('package | ||||||
|              ('source ('origin |                    ('name "ocaml-foo") | ||||||
|                         ('method 'url-fetch) |                    ('version "1.0.0") | ||||||
|                         ('uri "https://example.org/foo-1.0.0.tar.gz") |                    ('source ('origin | ||||||
|                         ('sha256 |                               ('method 'url-fetch) | ||||||
|                          ('base32 |                               ('uri "https://example.org/foo-1.0.0.tar.gz") | ||||||
|                           (? string? hash))))) |                               ('sha256 | ||||||
|              ('build-system 'ocaml-build-system) |                                ('base32 | ||||||
|              ('propagated-inputs |                                 (? string? hash))))) | ||||||
|               ('quasiquote |                    ('build-system 'ocaml-build-system) | ||||||
|                (("ocaml-zarith" ('unquote 'ocaml-zarith))))) |                    ('propagated-inputs | ||||||
|              ('native-inputs |                     ('quasiquote | ||||||
|               ('quasiquote |                      (("ocaml-zarith" ('unquote 'ocaml-zarith))))) | ||||||
|                (("ocaml-alcotest" ('unquote 'ocaml-alcotest)) |                    ('native-inputs | ||||||
|                 ("ocamlbuild" ('unquote 'ocamlbuild))))) |                     ('quasiquote | ||||||
|              ('home-page "https://example.org/") |                      (("ocaml-alcotest" ('unquote 'ocaml-alcotest)) | ||||||
|              ('synopsis "Some example package") |                       ("ocamlbuild" ('unquote 'ocamlbuild))))) | ||||||
|              ('description "This package is just an example.") |                    ('home-page "https://example.org/") | ||||||
|              ('license 'license:bsd-3)) |                    ('synopsis "Some example package") | ||||||
|            (string=? (bytevector->nix-base32-string |                    ('description "This package is just an example.") | ||||||
|                       test-source-hash) |                    ('license 'license:bsd-3)) | ||||||
|                      hash)) |                  (string=? (bytevector->nix-base32-string | ||||||
|           (x |                             test-source-hash) | ||||||
|            (pk 'fail x #f))))) |                            hash)) | ||||||
|  |                 (x | ||||||
|  |                  (pk 'fail x #f)))))) | ||||||
| 
 | 
 | ||||||
| ;; Test the opam file parser | ;; Test the opam file parser | ||||||
| ;; We fold over some test cases. Each case is a pair of the string to parse and the | ;; We fold over some test cases. Each case is a pair of the string to parse and the | ||||||
|  |  | ||||||
		Reference in a new issue