diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2024-01-25 22:53:56 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2024-02-12 12:03:53 +0100 |
| commit | be773bd192466fa7e26938a157c0885adf46139e (patch) | |
| tree | 4eadde2d4ecbf31b92c34554126ebc6c47055e66 /tests/swh.scm | |
| parent | 1610a632d4b3097282d18af27ff3e9e178d7dfcb (diff) | |
swh: Add bindings for the “ExtID” API.
This interface was deployed at archive.softwareheritage.org a few days
ago. Our main use case will be looking up directories by “nar-sha256”
hashes.
* guix/swh.scm (<external-id>): New JSON-mapped record type.
(lookup-external-id, lookup-directory-by-nar-hash): New procedures.
* tests/swh.scm (%external-id): New variable.
("lookup-directory-by-nar-hash"): New test.
Change-Id: Ib671c7798aeb6f8132ac78f2b06b9285da8e7bd5
Diffstat (limited to 'tests/swh.scm')
| -rw-r--r-- | tests/swh.scm | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/tests/swh.scm b/tests/swh.scm index a36f9512411..e7ced6b50ce 100644 --- a/tests/swh.scm +++ b/tests/swh.scm | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org> | 2 | ;;; Copyright © 2019-2021, 2024 Ludovic Courtès <ludo@gnu.org> |
| 3 | ;;; | 3 | ;;; |
| 4 | ;;; This file is part of GNU Guix. | 4 | ;;; This file is part of GNU Guix. |
| 5 | ;;; | 5 | ;;; |
| @@ -18,6 +18,7 @@ | |||
| 18 | 18 | ||
| 19 | (define-module (test-swh) | 19 | (define-module (test-swh) |
| 20 | #:use-module (guix swh) | 20 | #:use-module (guix swh) |
| 21 | #:use-module (guix base32) | ||
| 21 | #:use-module (guix tests http) | 22 | #:use-module (guix tests http) |
| 22 | #:use-module (web response) | 23 | #:use-module (web response) |
| 23 | #:use-module (srfi srfi-19) | 24 | #:use-module (srfi srfi-19) |
| @@ -56,6 +57,16 @@ | |||
| 56 | \"length\": 456, | 57 | \"length\": 456, |
| 57 | \"dir_id\": 2 } ]") | 58 | \"dir_id\": 2 } ]") |
| 58 | 59 | ||
| 60 | (define %external-id | ||
| 61 | "{ \"extid_type\": \"nar-sha256\", | ||
| 62 | \"extid\": | ||
| 63 | \"0b56ba94c2b83b8f74e3772887c1109135802eb3e8962b628377987fe97e1e63\", | ||
| 64 | \"version\": 0, | ||
| 65 | \"target\": \"swh:1:dir:84a8b34591712c0a90bab0af604188bcd1fe3153\", | ||
| 66 | \"target_url\": | ||
| 67 | \"https://archive.softwareheritage.org/swh:1:dir:84a8b34591712c0a90bab0af604188bcd1fe3153\" | ||
| 68 | }") | ||
| 69 | |||
| 59 | (define-syntax-rule (with-json-result str exp ...) | 70 | (define-syntax-rule (with-json-result str exp ...) |
| 60 | (with-http-server `((200 ,str)) | 71 | (with-http-server `((200 ,str)) |
| 61 | (parameterize ((%swh-base-url (%local-url))) | 72 | (parameterize ((%swh-base-url (%local-url))) |
| @@ -98,6 +109,14 @@ | |||
| 98 | (directory-entry-length entry))) | 109 | (directory-entry-length entry))) |
| 99 | (lookup-directory "123")))) | 110 | (lookup-directory "123")))) |
| 100 | 111 | ||
| 112 | (test-equal "lookup-directory-by-nar-hash" | ||
| 113 | "swh:1:dir:84a8b34591712c0a90bab0af604188bcd1fe3153" | ||
| 114 | (with-json-result %external-id | ||
| 115 | (lookup-directory-by-nar-hash | ||
| 116 | (nix-base32-string->bytevector | ||
| 117 | "0qqygvlpz63phdi2p5p8ncp80dci230qfa3pwds8yfxqqaablmhb") | ||
| 118 | 'sha256))) | ||
| 119 | |||
| 101 | (test-equal "rate limit reached" | 120 | (test-equal "rate limit reached" |
| 102 | 3000000000 | 121 | 3000000000 |
| 103 | (let ((too-many (build-response | 122 | (let ((too-many (build-response |
