aboutsummaryrefslogtreecommitdiff
path: root/tests/swh.scm
blob: a36f951241174462b68267f775350b5c7f06db87 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (test-swh)
  #:use-module (guix swh)
  #:use-module (guix tests http)
  #:use-module (web response)
  #:use-module (srfi srfi-19)
  #:use-module (srfi srfi-64)
  #:use-module (ice-9 match))

;; Test the JSON mapping machinery used in (guix swh).

(define %origin
  "{ \"origin_visits_url\": \"/visits/42\",
     \"type\": \"git\",
     \"url\": \"http://example.org/guix.git\" }")

(define %visits
  ;; A single visit where 'snapshot_url' is null.
  ;; See <https://bugs.gnu.org/45615>.
  "[ {
    \"origin\": \"https://github.com/Genivia/ugrep\",
    \"visit\": 1,
    \"date\": \"2020-05-17T21:43:45.422977+00:00\",
    \"status\": \"ongoing\",
    \"snapshot\": null,
    \"metadata\": {},
    \"type\": \"git\",
    \"origin_visit_url\": \"https://archive.softwareheritage.org/api/1/origin/https://github.com/Genivia/ugrep/visit/1/\",
    \"snapshot_url\": null
  } ]")

(define %directory-entries
  "[ { \"name\": \"one\",
       \"type\": \"regular\",
       \"length\": 123,
       \"dir_id\": 1 },
     { \"name\": \"two\",
       \"type\": \"regular\",
       \"length\": 456,
       \"dir_id\": 2 } ]")

(define-syntax-rule (with-json-result str exp ...)
  (with-http-server `((200 ,str))
    (parameterize ((%swh-base-url (%local-url)))
      exp ...)))

(test-begin "swh")

(test-equal "lookup-origin"
  (list "git" "http://example.org/guix.git")
  (with-json-result %origin
    (let ((origin (lookup-origin "http://example.org/guix.git")))
      (list (origin-type origin)
            (origin-url origin)))))

(test-equal "lookup-origin, not found"
  #f
  (with-http-server `((404 "Nope."))
    (parameterize ((%swh-base-url (%local-url)))
      (lookup-origin "http://example.org/whatever"))))

(test-equal "origin-visit, no snapshots"
  '("https://github.com/Genivia/ugrep"
    "2020-05-17T21:43:45Z"
    #f)                                      ;see <https://bugs.gnu.org/45615>
  (with-http-server `((200 ,%origin)
                      (200 ,%visits))
    (parameterize ((%swh-base-url (%local-url)))
      (let ((origin (lookup-origin "http://example.org/whatever")))
        (match (origin-visits origin)
          ((visit)
           (list (visit-origin visit)
                 (date->string (visit-date visit) "~4")
                 (visit-snapshot-url visit))))))))

(test-equal "lookup-directory"
  '(("one" 123) ("two" 456))
  (with-json-result %directory-entries
    (map (lambda (entry)
           (list (directory-entry-name entry)
                 (directory-entry-length entry)))
         (lookup-directory "123"))))

(test-equal "rate limit reached"
  3000000000
  (let ((too-many (build-response
                   #:code 429
                   #:reason-phrase "Too many requests"

                   ;; Pretend we've reached the limit and it'll be reset in
                   ;; June 2065.
                   #:headers '((x-ratelimit-remaining . "0")
                               (x-ratelimit-reset . "3000000000")))))
    (with-http-server `((,too-many "Too bad."))
      (parameterize ((%swh-base-url (%local-url)))
        (catch 'swh-error
          (lambda ()
            (lookup-origin "http://example.org/guix.git"))
          (lambda (key url method response)
            ;; Ensure the reset time was recorded.
            (@@ (guix swh) %general-rate-limit-reset-time)))))))

(test-assert "%allow-request? and request-rate-limit-reached?"
  ;; Here we test two things: that the rate limit set above is in effect and
  ;; that %ALLOW-REQUEST? is called, and that 'request-rate-limit-reached?'
  ;; returns true.
  (let* ((key (gensym "skip-request"))
         (skip-if-limit-reached
          (lambda (url method)
            (or (not (request-rate-limit-reached? url method))
                (throw key #t)))))
    (parameterize ((%allow-request? skip-if-limit-reached))
      (catch key
        (lambda ()
          (lookup-origin "http://example.org/guix.git")
          #f)
        (const #t)))))

(test-end "swh")

;; Local Variables:
;; eval: (put 'with-json-result 'scheme-indent-function 1)
;; eval: (put 'with-http-server 'scheme-indent-function 1)
;; End:

ckages/web.scm: Likewise. Change-Id: If3d78d31b1491f8a95616e59f50371c2914242d9 Sharlatan Hellseher 2024-07-24gnu: borg: Update to 1.4.0....* gnu/packages/backup.scm (borg): Update to 1.4.0. [source]: Remove obsolete snippet components. [arguments]: Export a newly required environment variable in the 'set-env' phase. Adjust the custom 'install-doc' phase to install miscellaneous documentation into a directory named after the package name and version. Change-Id: I688bb4e6c67506226418b6b4a47595f2a10c10ae Leo Famulari 2024-07-15gnu: restic: Use go-1.17....* gnu/packages/backup.scm (restic): [arguments]: <#:go>: Pin to go-1.17. Change-Id: I63267c2bdb3e983475cf75b285021c71ac578e1a Sharlatan Hellseher 2024-06-19gnu: restic-rest-server: Update to 0.12.1....* gnu/packages/backup.scm (restic-rest-server): Update to 0.12.1. [native-inputs]: Remove go-github-com-coreos-go-systemd-activation; add go-github-com-coreos-go-systemd-v22. Change-Id: I5d43b85f8ba340ef0adedc68ec1c0f01dbe062a0 Sharlatan Hellseher 2024-04-15gnu: borg: Update to 1.2.8....* gnu/packages/backup.scm (borg): Update to 1.2.8. [arguments]: Remove a variety of workarounds that have been obviated by changes upstream and in the Python package build tools. Reviewed-by: Dale Mellor <guix-devel-0brg6a@rdmp.org> Signed-off-by: Christopher Baines <mail@cbaines.net> Change-Id: I031bb4e6ac2f562a3e387a5e815b31416367766f Leo Famulari 2024-04-12gnu: restic-rest-server: Refresh package style....* gnu/packages/backup.scm (restic-rest-server): Use G-expressions. [arguments] <#:phases>: Swap back to standard 'check phase and add 'set-tmpdir phase. [native-inputs]: Swap from propagated-inputs to native-inputs, sort alphabetically. Change-Id: I5010a2dd81b887d8ef10fa27b3ffcb228e08fade Sharlatan Hellseher 2024-04-06gnu: packages: backup: Sort use-module alphabetically....* gnu/packages/backup.scm: Sort use-module alphabetically to ease maintenance. Change-Id: Ibe5288440edbe74d34f528a5867184d551f49e80 Sharlatan Hellseher 2024-04-03gnu: libarchive: Fix a potential security issue....https://github.com/libarchive/libarchive/pull/2101 * gnu/packages/backup.scm (libarchive)[replacement]: New field. (libarchive/fixed): New variable. * gnu/packages/patches/libarchive-remove-potential-backdoor.patch: New file. * gnu/local.mk (dist_patch_DATA): Add it. Change-Id: I939e9b842b10d1a78125da4a4599c38d9c037079 Leo Famulari 2024-03-31gnu: borgmatic: Update to 1.8.9....* gnu/packages/backup.scm (borgmatic): Update to 1.8.9. [arguments]: Apply guix style. [native-inputs]: Apply guix style. [inputs]: Apply guix style. Change-Id: Ic9eb3c9439dc0aade3e4aae0fbe8e2c7bec49754 Signed-off-by: jgart <jgart@dismail.de> Fabio Natali 2024-02-25Merge branch 'master' into gnome-teamLiliana Marie Prikler 2024-02-22gnu: python-ruamel-yaml: Update to 0.18.6....* gnu/package/serialization.scm (python-ruamel-yaml): Update to 0.18.6. (python-ruamel.yaml-0.16): New variable. * gnu/packages/package-management.scm (conda)[inputs]: Replace python-ruamel.yaml with python-ruamel.yaml-0.16. * gnu/packages/backup.scm (borgmatic)[inputs]: Replace python-ruamel.yaml with python-ruamel.yaml-0.16. * gnu/packages/python-xyz.scm (dynaconf)[inputs]: Replace python-ruamel.yaml with python-ruamel.yaml-0.16. Change-Id: Iff9eeeae043c9547d93a6c780f0c30bd760490d9 Change-Id: I43cad7e3936f62d209fbba7e86b93519cfc1c1ba Signed-off-by: Arun Isaac <arunisaac@systemreboot.net> Arun Isaac 2024-02-15gnu: packages: backup: Add golang-xyz....* gnu/packages/backup.scm: Add (gnu packages golang-xyz) module. Change-Id: I848acb1dea36c59031bc60107179b3bc0d14636d Sharlatan Hellseher 2024-02-13Merge branch 'master' into gnome-teamLiliana Marie Prikler 2024-02-13gnu: go-golang-org-x-crypto: Move to golang-build....* gnu/packages/golang.scm (go-golang-org-x-crypto): Move from here ... * gnu/packages/golang-build.scm: ... to here. * gnu/packages/backup.scm: Add (gnu packages golang-build) module. * gnu/packages/crypto.scm: As above. Change-Id: I5daad7fe90e1507958fe73c04fc043ebbc006395 Sharlatan Hellseher 2024-02-12gnu: disarchive: Update to 0.6.0....* gnu/packages/backup.scm (disarchive): Update to 0.6.0; add 'guile-bzip2' as an input. * gnu/packages/package-management.scm (guix): Add 'guile-bzip2' as an input to enable bzip2 support when using Disarchive. * guix/self.scm (%packages): Add 'guile-bzip2'. (compiled-guix): Include 'guile-bzip2' as a dependency when building the 'guix' command. * etc/disarchive-manifest.scm (tarball-origin?): Include bzip2 tarballs. Co-authored-by: Ludovic Courtès <ludovic.courtes@inria.fr> Change-Id: I4da479054f6bef225f5ea979c091152f8a9e51d5 Timothy Sample 2024-02-03Merge branch 'master' into gnome-teamLiliana Marie Prikler 2024-02-03gnu: duplicity: Wrap for GI_TYPELIB_PATH....* gnu/packages/backup.scm (duplicity) [native-inputs]: Add gobject-introspection. [inputs]: Add bash-minimal. [#:phases]: Add 'gi-wrap. Change-Id: If9d6a6bb0e855a4d775c1e4adb3b07f71be43090 Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com> Vivien Kraus 2024-01-28gnu: go-github-com-minio-sha256-simd: Move to (gnu packages golang-crypto)....* gnu/packages/golang.scm (go-github-com-minio-sha256-simd): Move from here ... * gnu/packages/golang-crypto.scm: ... to here. * gnu/packages/backup.scm: Add (gnu packages golang-crypto) to used modules. Change-Id: I4e57a1bee0c7e19a9bb60ce5ff72ccd5e42deea5 Sharlatan Hellseher 2024-01-03gnu: go-github-com-gorilla-handlers: Move to (gnu packages golang-web)....* gnu/packages/golang.scm (go-github-com-gorilla-handlers): Move from here... * gnu/packages/golang-web.scm: ...to here. * gnu/packages/backup.scm: Add (gnu packages golang-web) module. Change-Id: I7535bdecc681e230f4aee70115a3dea847d40e6f Sharlatan Hellseher 2023-12-16gnu: Borg: Update to 1.2.7....* gnu/packages/backup.scm (borg): Update to 1.2.7. [inputs]: Replace python-msgpack-1.0.2 with python-msgpack. Change-Id: I8529d737d90105f877f1c099f4b3afa9b0ed9fa8 Leo Famulari