summaryrefslogtreecommitdiff
path: root/tests/swh.scm
diff options
context:
space:
mode:
Diffstat (limited to 'tests/swh.scm')
-rw-r--r--tests/swh.scm95
1 files changed, 94 insertions, 1 deletions
diff --git a/tests/swh.scm b/tests/swh.scm
index a36f951241..11dcbdddd8 100644
--- a/tests/swh.scm
+++ b/tests/swh.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2019-2021, 2024 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -18,6 +18,7 @@
(define-module (test-swh)
#:use-module (guix swh)
+ #:use-module (guix base32)
#:use-module (guix tests http)
#:use-module (web response)
#:use-module (srfi srfi-19)
@@ -56,6 +57,16 @@
\"length\": 456,
\"dir_id\": 2 } ]")
+(define %external-id
+ "{ \"extid_type\": \"nar-sha256\",
+ \"extid\":
+\"0b56ba94c2b83b8f74e3772887c1109135802eb3e8962b628377987fe97e1e63\",
+ \"version\": 0,
+ \"target\": \"swh:1:dir:84a8b34591712c0a90bab0af604188bcd1fe3153\",
+ \"target_url\":
+\"https://archive.softwareheritage.org/swh:1:dir:84a8b34591712c0a90bab0af604188bcd1fe3153\"
+ }")
+
(define-syntax-rule (with-json-result str exp ...)
(with-http-server `((200 ,str))
(parameterize ((%swh-base-url (%local-url)))
@@ -98,6 +109,88 @@
(directory-entry-length entry)))
(lookup-directory "123"))))
+(test-equal "lookup-origin-revision"
+ '("cd86c72084993d9ef26fc9e24b73cea612b8c97b"
+ "d173c707ee88e3c89401ad77fafa65fcd9e9f5be")
+ (let ()
+ ;; Make sure that 'lookup-origin-revision' does the job, and in particular
+ ;; that it doesn't stop until it has found an actual revision:
+ ;; 'git-checkout visits point to directories instead of revisions.
+ ;; See <https://issues.guix.gnu.org/69070>.
+ (define visits
+ ;; Two visits of differing types: the first visit (type 'git-checkout')
+ ;; points to a directory, the second one (type 'git') points to a
+ ;; revision.
+ "[ {
+ \"origin\": \"https://example.org/repo.git\",
+ \"visit\": 1,
+ \"type\": \"git-checkout\",
+ \"date\": \"2020-05-17T21:43:45.422977+00:00\",
+ \"status\": \"full\",
+ \"metadata\": {},
+ \"type\": \"git-checkout\",
+ \"origin_visit_url\": \"/visit/42\",
+ \"snapshot_url\": \"/snapshot/1\"
+ }, {
+ \"origin\": \"https://example.org/repo.git\",
+ \"visit\": 2,
+ \"type\": \"git\",
+ \"date\": \"2020-05-17T21:43:49.422977+00:00\",
+ \"status\": \"full\",
+ \"metadata\": {},
+ \"type\": \"git\",
+ \"origin_visit_url\": \"/visit/41\",
+ \"snapshot_url\": \"/snapshot/2\"
+ } ]")
+ (define snapshot-for-git-checkout
+ "{ \"id\": 42,
+ \"branches\": { \"1.3.2\": {
+ \"target\": \"e4a4be18fae8d9c6528abff3bc9088feb19a76c7\",
+ \"target_type\": \"directory\",
+ \"target_url\": \"/directory/e4a4be18fae8d9c6528abff3bc9088feb19a76c7\"
+ }}
+ }")
+ (define snapshot-for-git
+ "{ \"id\": 42,
+ \"branches\": { \"1.3.2\": {
+ \"target\": \"e4a4be18fae8d9c6528abff3bc9088feb19a76c7\",
+ \"target_type\": \"revision\",
+ \"target_url\": \"/revision/e4a4be18fae8d9c6528abff3bc9088feb19a76c7\"
+ }}
+ }")
+ (define revision
+ "{ \"author\": {},
+ \"committer\": {},
+ \"committer_date\": \"2018-05-17T21:43:49.422977+00:00\",
+ \"date\": \"2018-05-17T21:43:49.422977+00:00\",
+ \"directory\": \"d173c707ee88e3c89401ad77fafa65fcd9e9f5be\",
+ \"directory_url\": \"/directory/d173c707ee88e3c89401ad77fafa65fcd9e9f5be\",
+ \"id\": \"cd86c72084993d9ef26fc9e24b73cea612b8c97b\",
+ \"merge\": false,
+ \"message\": \"Fix.\",
+ \"parents\": [],
+ \"type\": \"what type?\"
+ }")
+
+ (with-http-server `((200 ,%origin)
+ (200 ,visits)
+ (200 ,snapshot-for-git-checkout)
+ (200 ,snapshot-for-git)
+ (200 ,revision))
+ (parameterize ((%swh-base-url (%local-url)))
+ (let ((revision (lookup-origin-revision "https://example.org/repo.git"
+ "1.3.2")))
+ (list (revision-id revision)
+ (revision-directory revision)))))))
+
+(test-equal "lookup-directory-by-nar-hash"
+ "swh:1:dir:84a8b34591712c0a90bab0af604188bcd1fe3153"
+ (with-json-result %external-id
+ (lookup-directory-by-nar-hash
+ (nix-base32-string->bytevector
+ "0qqygvlpz63phdi2p5p8ncp80dci230qfa3pwds8yfxqqaablmhb")
+ 'sha256)))
+
(test-equal "rate limit reached"
3000000000
(let ((too-many (build-response