unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob 21fdc3a4eb1b9ca49fbf9da4510a7672c454fb3d 7304 bytes (raw)
name: tests/juliahub.scm 	 # note: path name is non-authoritative(*)

  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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
 
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2024 Nicolas Graves <ngraves@ngraves.fr>
;;;
;;; 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/>.

;;; Summary
;; Tests for guix/import/juliahub.scm

(define-module (tests-import-juliahub)
  #:use-module (guix base32)
  #:use-module (json)
  #:use-module (guix import juliahub)
  #:use-module (guix import utils)
  #:use-module ((guix utils) #:select (call-with-temporary-directory))
  #:use-module (guix tests)
  #:use-module (ice-9 match)
  #:use-module (srfi srfi-19)
  #:use-module (srfi srfi-64)
  #:use-module (srfi srfi-71)
  #:use-module (web response))

;; XXX: Copied from tests/go.scm

(define (mock-http-fetch testcase)
  (lambda (url . rest)
    (let ((body (assoc-ref testcase url)))
      (if body
          (open-input-string body)
          (error "mocked http-fetch Unexpected URL: " url)))))

(define (mock-http-get testcase)
  (lambda (url . rest)
    (let ((body (assoc-ref testcase url))
          (response-header
             (build-response
                #:version '(1 . 1)
                #:code 200
                #:reason-phrase "Ok"
                #:headers `(
                            (content-type text/html (charset . "utf-8"))
                            (date . ,(make-date 0 10 58 12 6 3 2021 0))
                            (transfer-encoding (chunked)))
                #:port #f
                #:validate-headers? #t)))
      (if body
          (values response-header body)
          (error "mocked http-get Unexpected URL: " url)))))

;; Mock an empty directory by replacing hash.
(define* (mock-git->origin repo-url ref #:key (ref->commit #f))
  (let* ((version (if (pair? ref)
                      (cdr ref)
                      #f))
         (vcommit (match ref->commit
                    (#t    commit)
                    (#f    version)
                    ((? procedure?) (ref->commit version))
                    (_     #f))))
    `(origin
       (method git-fetch)
       (uri (git-reference
             (url ,(and (not (eq? repo-url 'null)) repo-url))
             (commit ,vcommit)))
       (file-name (git-file-name name version))
       (sha256
        (base32
         "0sjjj9z1dhilhpc8pq4154czrb79z9cm044jvn75kxcjv6v5l2m5")))))

;; Fixtures.

(define fixture-pkg.json
  (scm->json-string
   `(("hosted_uri" . "https://git.savannah.gnu.org/cgit/MyPackage.git")
     ("installable" . "missing")
     ("license" . "GPL-3.0")
     ("tags" . #("my-tag"))
     ("uuid" . "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa")
     ("url" . "https://git.savannah.gnu.org/cgit/MyPackage.git")
     ("contributors" . #((("url" . "https://github.com/me") ("type" . "User") ("contributions" . 1) ("name" . "me"))))
     ("success" . #t)
     ("reversedeps" . #())
     ("pkgeval"
      ("report_url" . "https://github.com/JuliaCI/NanosoldierReports/blob/master/pkgeval/by_date/2024-02/01/report.md")
      ("version" ("minor" . 18) ("patch" . 1) ("build" . #()) ("prerelease" . #()) ("major" . 1))
      ("reason" . "time_limit")
      ("log_url" . "https://s3.amazonaws.com/julialang-reports/nanosoldier/pkgeval/by_date/2024-02/01/MyPackage.jl.primary.log")
      ("status" . "fail")
      ("duration" . 0))
     ("stargazers_count" . 0)
     ("deps" . #((("slug" . "3FQLY")
                  ("registry" . "")
                  ("versions" . #("0.0.0" "1.6.0-1"))
                  ("uuid" . "de0858da-6303-5e67-8744-51eddeeeb8d7")
                  ("name" . "Printf")
                  ("direct" . #t))
                 (("slug" . "SIw1t")
                  ("registry" . "")
                  ("versions" . #("*" "0.0.0" "1"))
                  ("uuid" . "cf7118a7-6976-5b1a-9a39-7adc72f591a4")
                  ("name" . "UUIDs")
                  ("direct" . #f))
                 (("slug" . "THl1k")
                  ("registry" . "General")
                  ("versions" . #("0.7" "1" "1-1.10" "1.0-1.5" "1.3.0-1" "1.6.0-1" "1.9.0-1" "1.9.4-1"))
                  ("uuid" . "1222c4b2-2114-5bfd-aeef-88e4692bbb3e")
                  ("name" . "julia")
                  ("direct" . #f))
                 (("slug" . "THl1k")
                  ("registry" . "General")
                  ("versions" . #("1.6.0-1"))
                  ("uuid" . "1222c4b2-2114-5bfd-aeef-88e4692bbb3e")
                  ("name" . "julia")
                  ("direct" . #t))))
     ("description" . "My description")
     ("version" . "1.0.0")
     ("documenter_errored" . "missing")
     ("slug" . "MySlg")
     ("owner" . "me")
     ("release_date" . "Feb 2024")
     ("name" . "MyPackage.jl")
     ("readme" . "My readme")
     ("homepage" . "https://git.savannah.gnu.org/cgit/MyPackage.git")
     ("doctype" . "hosted")
     ("license_url" . "/docs/MyPackage/MySlg/1.0.0/_packagesource/LICENSE.md"))))

(define fixtures-juliahub-check-test
  `(("https://docs.juliahub.com/MyPackage/" . "\
<head>
<meta http-equiv=\"refresh\" content=\"0; url=MySlg/1.0.0\" />
</head>")
    ("https://raw.githubusercontent.com/JuliaRegistries/General/master\
/M/MyPackage/Package.toml" . "\
name = \"MyPackage\"
uuid = \"aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa\"
repo = \"https://git.savannah.gnu.org/cgit/MyPackage.git\"
")
    ("https://docs.juliahub.com/MyPackage/MySlg/1.0.0/pkg.json" . ,fixture-pkg.json)))

(test-begin "juliahub")

;;; Unit tests for (guix import juliahub)

(test-equal "juliahub-redirect"
  "https://docs.juliahub.com/MyPackage/MySlg/1.0.0/"
  (mock ((web client) http-get
         (mock-http-get fixtures-juliahub-check-test))
        (mock ((guix http-client) http-fetch
               (mock-http-fetch fixtures-juliahub-check-test))
              ((@@ (guix import juliahub) juliahub-url) "MyPackage"))))

(test-equal "julia-general-registry-parsing"
  "https://git.savannah.gnu.org/cgit/MyPackage.git"
  (mock ((web client) http-get
         (mock-http-get fixtures-juliahub-check-test))
        (mock ((guix http-client) http-fetch
               (mock-http-fetch fixtures-juliahub-check-test))
              (assoc-ref
               ((@@ (guix import juliahub) ini-fetch)
                ((@@ (guix import juliahub) general-url) "MyPackage" "Package.toml"))
               'repo))))

(test-equal "juliahub-fetch"
  #t
  (mock ((web client) http-get
         (mock-http-get fixtures-juliahub-check-test))
        (mock ((guix http-client) http-fetch
               (mock-http-fetch fixtures-juliahub-check-test))
              (mock ((guix import utils) git->origin mock-git->origin)
                    ((@@ (guix import juliahub) juliahub-package?)
                     ((@@ (guix import juliahub) juliahub-fetch) "MyPackage"))))))

(test-end "juliahub")

debug log:

solving 21fdc3a4eb ...
found 21fdc3a4eb in https://yhetil.org/guix-patches/20240203230807.25751-6-ngraves@ngraves.fr/

applying [1/1] https://yhetil.org/guix-patches/20240203230807.25751-6-ngraves@ngraves.fr/
diff --git a/tests/juliahub.scm b/tests/juliahub.scm
new file mode 100644
index 0000000000..21fdc3a4eb

Checking patch tests/juliahub.scm...
Applied patch tests/juliahub.scm cleanly.

index at:
100644 21fdc3a4eb1b9ca49fbf9da4510a7672c454fb3d	tests/juliahub.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).