guix-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug#73833] [PATCH v2 2/5] tests: go: Add mock-git->origin function.


From: Nicolas Graves
Subject: [bug#73833] [PATCH v2 2/5] tests: go: Add mock-git->origin function.
Date: Fri, 18 Oct 2024 00:25:58 +0200

* tests/go.scm
(mock-git->origin): Add function.
(go-module->guix-package test): Use mock-git->origin.
---
 tests/go.scm | 41 +++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 20 deletions(-)

diff --git a/tests/go.scm b/tests/go.scm
index 8402f3e978..c08a73a850 100644
--- a/tests/go.scm
+++ b/tests/go.scm
@@ -371,6 +371,26 @@ (define (mock-http-get testcase)
           (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")))))
+
 (test-equal "go-module->guix-package"
   '(package
      (name "go-github-com-go-check-check")
@@ -403,26 +423,7 @@ (define (mock-http-get testcase)
             (mock-http-get fixtures-go-check-test))
          (mock ((guix http-client) http-fetch
                 (mock-http-fetch fixtures-go-check-test))
-             (mock ((guix import utils) git->origin
-                    ;; Mock an empty directory by replacing hash.
-                    (lambda* (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"))))))
+             (mock ((guix import utils) git->origin mock-git->origin)
                  (go-module->guix-package* "github.com/go-check/check")))))))
 
 (test-end "go")
-- 
2.46.0






reply via email to

[Prev in Thread] Current Thread [Next in Thread]