summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Elsing <david.elsing@posteo.net>2023-12-21 22:01:51 +0000
committerEfraim Flashner <efraim@flashner.co.il>2024-01-09 09:38:38 +0200
commit53add91be621a9d97e534397f16f71e071eaba96 (patch)
tree16397d0026baf16de50178b2e9c567e947a770be /tests
parent9f44ff2bb47c964d53905cea17c4bda758cce509 (diff)
tests: Mock find-packages-by-name in crate importer test.
* tests/crate.scm: Import only sha256 from (gcrypt hash) as gcrypt-sha256 to prevent a name collision. Rename test 'cargo-recursive-import' to 'crate-recursive-import' and 'cargo-recursive-import-hoors-existing-packages' to 'crate-recursive-import-honors-existing-packages'. Mock find-packages-by-name from (gnu packages). Adjust test to import fake 'bar' crate instead of doctool. (test-bar-crate): New variable. (test-bar-dependencies): New variable. (test-root-crate): Adjust sha256 -> gcrypt-sha256. (test-doctool-crate,test-doctool-dependencies): Remove variables. (rust-leaf-bob-3): New variable. Signed-off-by: Efraim Flashner <efraim@flashner.co.il>
Diffstat (limited to 'tests')
-rw-r--r--tests/crate.scm203
1 files changed, 115 insertions, 88 deletions
diff --git a/tests/crate.scm b/tests/crate.scm
index 1b9ad88358a..e779f738b33 100644
--- a/tests/crate.scm
+++ b/tests/crate.scm
@@ -25,7 +25,9 @@
25 #:use-module (guix import crate) 25 #:use-module (guix import crate)
26 #:use-module (guix base32) 26 #:use-module (guix base32)
27 #:use-module (guix build-system cargo) 27 #:use-module (guix build-system cargo)
28 #:use-module (gcrypt hash) 28 #:use-module ((gcrypt hash)
29 #:select ((sha256 . gcrypt-sha256)))
30 #:use-module (guix packages)
29 #:use-module (guix tests) 31 #:use-module (guix tests)
30 #:use-module (gnu packages) 32 #:use-module (gnu packages)
31 #:use-module (ice-9 iconv) 33 #:use-module (ice-9 iconv)
@@ -38,6 +40,8 @@
38;; foo-1.0.0 40;; foo-1.0.0
39;; foo-1.0.3 41;; foo-1.0.3
40;; leaf-alice 0.7.5 42;; leaf-alice 0.7.5
43;; bar-1.0.0
44;; leaf-bob 3.0.1
41;; 45;;
42;; root-1.0.0 46;; root-1.0.0
43;; root-1.0.4 47;; root-1.0.4
@@ -116,6 +120,40 @@
116 ] 120 ]
117}") 121}")
118 122
123(define test-bar-crate
124 "{
125 \"crate\": {
126 \"max_version\": \"1.0.0\",
127 \"name\": \"bar\",
128 \"description\": \"summary\",
129 \"homepage\": \"http://example.com\",
130 \"repository\": \"http://example.com\",
131 \"keywords\": [\"dummy\", \"test\"],
132 \"categories\": [\"test\"],
133 \"actual_versions\": [
134 { \"id\": 234100,
135 \"num\": \"1.0.0\",
136 \"license\": \"MIT OR Apache-2.0\",
137 \"links\": {
138 \"dependencies\": \"/api/v1/crates/bar/1.0.0/dependencies\"
139 },
140 \"yanked\": false
141 }
142 ]
143 }
144}")
145
146(define test-bar-dependencies
147 "{
148 \"dependencies\": [
149 {
150 \"crate_id\": \"leaf-bob\",
151 \"kind\": \"normal\",
152 \"req\": \"3.0.1\"
153 }
154 ]
155}")
156
119(define test-root-crate 157(define test-root-crate
120 "{ 158 "{
121 \"crate\": { 159 \"crate\": {
@@ -399,7 +437,7 @@
399 ("https://crates.io/api/v1/crates/foo/1.0.3/download" 437 ("https://crates.io/api/v1/crates/foo/1.0.3/download"
400 (set! test-source-hash 438 (set! test-source-hash
401 (bytevector->nix-base32-string 439 (bytevector->nix-base32-string
402 (sha256 (string->bytevector "empty file\n" "utf-8")))) 440 (gcrypt-sha256 (string->bytevector "empty file\n" "utf-8"))))
403 (open-input-string "empty file\n")) 441 (open-input-string "empty file\n"))
404 ("https://crates.io/api/v1/crates/foo/1.0.3/dependencies" 442 ("https://crates.io/api/v1/crates/foo/1.0.3/dependencies"
405 (open-input-string test-foo-dependencies)) 443 (open-input-string test-foo-dependencies))
@@ -408,7 +446,7 @@
408 ("https://crates.io/api/v1/crates/leaf-alice/0.7.5/download" 446 ("https://crates.io/api/v1/crates/leaf-alice/0.7.5/download"
409 (set! test-source-hash 447 (set! test-source-hash
410 (bytevector->nix-base32-string 448 (bytevector->nix-base32-string
411 (sha256 (string->bytevector "empty file\n" "utf-8")))) 449 (gcrypt-sha256 (string->bytevector "empty file\n" "utf-8"))))
412 (open-input-string "empty file\n")) 450 (open-input-string "empty file\n"))
413 ("https://crates.io/api/v1/crates/leaf-alice/0.7.5/dependencies" 451 ("https://crates.io/api/v1/crates/leaf-alice/0.7.5/dependencies"
414 (open-input-string test-leaf-alice-dependencies)) 452 (open-input-string test-leaf-alice-dependencies))
@@ -442,7 +480,7 @@
442 (pk 'fail x #f))))) 480 (pk 'fail x #f)))))
443 481
444(unless have-guile-semver? (test-skip 1)) 482(unless have-guile-semver? (test-skip 1))
445(test-assert "cargo-recursive-import" 483(test-assert "crate-recursive-import"
446 ;; Replace network resources with sample data. 484 ;; Replace network resources with sample data.
447 (mock ((guix http-client) http-fetch 485 (mock ((guix http-client) http-fetch
448 (lambda (url . rest) 486 (lambda (url . rest)
@@ -452,7 +490,7 @@
452 ("https://crates.io/api/v1/crates/root/1.0.4/download" 490 ("https://crates.io/api/v1/crates/root/1.0.4/download"
453 (set! test-source-hash 491 (set! test-source-hash
454 (bytevector->nix-base32-string 492 (bytevector->nix-base32-string
455 (sha256 (string->bytevector "empty file\n" "utf-8")))) 493 (gcrypt-sha256 (string->bytevector "empty file\n" "utf-8"))))
456 (open-input-string "empty file\n")) 494 (open-input-string "empty file\n"))
457 ("https://crates.io/api/v1/crates/root/1.0.4/dependencies" 495 ("https://crates.io/api/v1/crates/root/1.0.4/dependencies"
458 (open-input-string test-root-dependencies)) 496 (open-input-string test-root-dependencies))
@@ -461,7 +499,7 @@
461 ("https://crates.io/api/v1/crates/intermediate-a/1.0.42/download" 499 ("https://crates.io/api/v1/crates/intermediate-a/1.0.42/download"
462 (set! test-source-hash 500 (set! test-source-hash
463 (bytevector->nix-base32-string 501 (bytevector->nix-base32-string
464 (sha256 (string->bytevector "empty file\n" "utf-8")))) 502 (gcrypt-sha256 (string->bytevector "empty file\n" "utf-8"))))
465 (open-input-string "empty file\n")) 503 (open-input-string "empty file\n"))
466 ("https://crates.io/api/v1/crates/intermediate-a/1.0.42/dependencies" 504 ("https://crates.io/api/v1/crates/intermediate-a/1.0.42/dependencies"
467 (open-input-string test-intermediate-a-dependencies)) 505 (open-input-string test-intermediate-a-dependencies))
@@ -470,7 +508,7 @@
470 ("https://crates.io/api/v1/crates/intermediate-b/1.2.3/download" 508 ("https://crates.io/api/v1/crates/intermediate-b/1.2.3/download"
471 (set! test-source-hash 509 (set! test-source-hash
472 (bytevector->nix-base32-string 510 (bytevector->nix-base32-string
473 (sha256 (string->bytevector "empty file\n" "utf-8")))) 511 (gcrypt-sha256 (string->bytevector "empty file\n" "utf-8"))))
474 (open-input-string "empty file\n")) 512 (open-input-string "empty file\n"))
475 ("https://crates.io/api/v1/crates/intermediate-b/1.2.3/dependencies" 513 ("https://crates.io/api/v1/crates/intermediate-b/1.2.3/dependencies"
476 (open-input-string test-intermediate-b-dependencies)) 514 (open-input-string test-intermediate-b-dependencies))
@@ -479,7 +517,7 @@
479 ("https://crates.io/api/v1/crates/intermediate-c/1.0.1/download" 517 ("https://crates.io/api/v1/crates/intermediate-c/1.0.1/download"
480 (set! test-source-hash 518 (set! test-source-hash
481 (bytevector->nix-base32-string 519 (bytevector->nix-base32-string
482 (sha256 (string->bytevector "empty file\n" "utf-8")))) 520 (gcrypt-sha256 (string->bytevector "empty file\n" "utf-8"))))
483 (open-input-string "empty file\n")) 521 (open-input-string "empty file\n"))
484 ("https://crates.io/api/v1/crates/intermediate-c/1.0.1/dependencies" 522 ("https://crates.io/api/v1/crates/intermediate-c/1.0.1/dependencies"
485 (open-input-string test-intermediate-c-dependencies)) 523 (open-input-string test-intermediate-c-dependencies))
@@ -488,7 +526,7 @@
488 ("https://crates.io/api/v1/crates/leaf-alice/0.7.5/download" 526 ("https://crates.io/api/v1/crates/leaf-alice/0.7.5/download"
489 (set! test-source-hash 527 (set! test-source-hash
490 (bytevector->nix-base32-string 528 (bytevector->nix-base32-string
491 (sha256 (string->bytevector "empty file\n" "utf-8")))) 529 (gcrypt-sha256 (string->bytevector "empty file\n" "utf-8"))))
492 (open-input-string "empty file\n")) 530 (open-input-string "empty file\n"))
493 ("https://crates.io/api/v1/crates/leaf-alice/0.7.5/dependencies" 531 ("https://crates.io/api/v1/crates/leaf-alice/0.7.5/dependencies"
494 (open-input-string test-leaf-alice-dependencies)) 532 (open-input-string test-leaf-alice-dependencies))
@@ -497,7 +535,7 @@
497 ("https://crates.io/api/v1/crates/leaf-bob/3.0.1/download" 535 ("https://crates.io/api/v1/crates/leaf-bob/3.0.1/download"
498 (set! test-source-hash 536 (set! test-source-hash
499 (bytevector->nix-base32-string 537 (bytevector->nix-base32-string
500 (sha256 (string->bytevector "empty file\n" "utf-8")))) 538 (gcrypt-sha256 (string->bytevector "empty file\n" "utf-8"))))
501 (open-input-string "empty file\n")) 539 (open-input-string "empty file\n"))
502 ("https://crates.io/api/v1/crates/leaf-bob/3.0.1/dependencies" 540 ("https://crates.io/api/v1/crates/leaf-bob/3.0.1/dependencies"
503 (open-input-string test-leaf-bob-dependencies)) 541 (open-input-string test-leaf-bob-dependencies))
@@ -814,85 +852,74 @@
814 852
815 853
816 854
817(define test-doctool-crate 855(define rust-leaf-bob-3
818 "{ 856 (package
819 \"crate\": { 857 (name "rust-leaf-bob")
820 \"max_version\": \"2.2.2\", 858 (version "3.0.1")
821 \"name\": \"leaf-bob\", 859 (source #f)
822 \"description\": \"summary\", 860 (build-system #f)
823 \"homepage\": \"http://example.com\", 861 (home-page #f)
824 \"repository\": \"http://example.com\", 862 (synopsis #f)
825 \"keywords\": [\"dummy\", \"test\"], 863 (description #f)
826 \"categories\": [\"test\"] 864 (license #f)))
827 \"actual_versions\": [
828 { \"id\": 234280,
829 \"num\": \"2.2.2\",
830 \"license\": \"MIT OR Apache-2.0\",
831 \"links\": {
832 \"dependencies\": \"/api/v1/crates/doctool/2.2.2/dependencies\"
833 },
834 \"yanked\": false
835 }
836 ]
837 }
838}")
839
840;; FIXME: This test depends on some existing packages
841(define test-doctool-dependencies
842 "{
843 \"dependencies\": [
844 {
845 \"crate_id\": \"docopt\",
846 \"kind\": \"normal\",
847 \"req\": \"^0.8.1\"
848 }
849 ]
850}")
851
852
853(test-assert "self-test: rust-docopt 0.8.x is gone, please adjust the test case"
854 (not (null? (find-packages-by-name "rust-docopt" "0.8"))))
855 865
856(unless have-guile-semver? (test-skip 1)) 866(unless have-guile-semver? (test-skip 1))
857(test-assert "cargo-recursive-import-hoors-existing-packages" 867(test-assert "crate-recursive-import-honors-existing-packages"
858 (mock ((guix http-client) http-fetch 868 (mock
859 (lambda (url . rest) 869 ((gnu packages) find-packages-by-name
860 (match url 870 (lambda* (name #:optional version)
861 ("https://crates.io/api/v1/crates/doctool" 871 (match name
862 (open-input-string test-doctool-crate)) 872 ("rust-leaf-bob"
863 ("https://crates.io/api/v1/crates/doctool/2.2.2/download" 873 (list rust-leaf-bob-3))
864 (set! test-source-hash 874 (_ '()))))
865 (bytevector->nix-base32-string 875 (mock
866 (sha256 (string->bytevector "empty file\n" "utf-8")))) 876 ((guix http-client) http-fetch
867 (open-input-string "empty file\n")) 877 (lambda (url . rest)
868 ("https://crates.io/api/v1/crates/doctool/2.2.2/dependencies" 878 (match url
869 (open-input-string test-doctool-dependencies)) 879 ("https://crates.io/api/v1/crates/bar"
870 (_ (error "Unexpected URL: " url))))) 880 (open-input-string test-bar-crate))
871 (match (crate-recursive-import "doctool") 881 ("https://crates.io/api/v1/crates/bar/1.0.0/download"
872 (((define-public 'rust-doctool-2 882 (set! test-source-hash
873 (package 883 (bytevector->nix-base32-string
874 (name "rust-doctool") 884 (gcrypt-sha256 (string->bytevector "empty file\n" "utf-8"))))
875 (version "2.2.2") 885 (open-input-string "empty file\n"))
876 (source 886 ("https://crates.io/api/v1/crates/bar/1.0.0/dependencies"
877 (origin 887 (open-input-string test-bar-dependencies))
878 (method url-fetch) 888 ("https://crates.io/api/v1/crates/leaf-bob"
879 (uri (crate-uri "doctool" version)) 889 (open-input-string test-leaf-bob-crate))
880 (file-name 890 ("https://crates.io/api/v1/crates/leaf-bob/3.0.2/download"
881 (string-append name "-" version ".tar.gz")) 891 (set! test-source-hash
882 (sha256 892 (bytevector->nix-base32-string
883 (base32 893 (gcrypt-sha256 (string->bytevector "empty file\n" "utf-8"))))
884 (? string? hash))))) 894 (open-input-string "empty file\n"))
885 (build-system cargo-build-system) 895 ("https://crates.io/api/v1/crates/leaf-bob/3.0.2/dependencies"
886 (arguments 896 (open-input-string test-leaf-bob-dependencies))
887 ('quasiquote (#:cargo-inputs 897 (_ (error "Unexpected URL: " url)))))
888 (("rust-docopt" 898 (match (crate-recursive-import "bar")
889 ('unquote 'rust-docopt-0.8)))))) 899 (((define-public 'rust-bar-1
890 (home-page "http://example.com") 900 (package
891 (synopsis "summary") 901 (name "rust-bar")
892 (description "summary") 902 (version "1.0.0")
893 (license (list license:expat license:asl2.0))))) 903 (source
894 #t) 904 (origin
895 (x 905 (method url-fetch)
896 (pk 'fail x #f))))) 906 (uri (crate-uri "bar" version))
907 (file-name
908 (string-append name "-" version ".tar.gz"))
909 (sha256
910 (base32
911 (? string? hash)))))
912 (build-system cargo-build-system)
913 (arguments
914 ('quasiquote (#:cargo-inputs
915 (("rust-leaf-bob"
916 ('unquote 'rust-leaf-bob-3))))))
917 (home-page "http://example.com")
918 (synopsis "summary")
919 (description "summary")
920 (license (list license:expat license:asl2.0)))))
921 #t)
922 (x
923 (pk 'fail x #f))))))
897 924
898(test-end "crate") 925(test-end "crate")