;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2026 Maxim Cournoyer ;;; ;;; 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 . (use-modules (guix import gradle) (guix tests) (srfi srfi-64)) (define sha256->nix-base32-hash (@@ (guix import gradle) sha256->nix-base32-hash)) ;; An excerpt of the sparrow wallet mitm-cache produced JSON file, exhibiting ;; URL redirection, including one that failed to resolve. (define cache.json "{ \"!version\": 1, \"https://code.sparrowwallet.com/api/packages/sparrowwallet/maven/com/sparrowwallet/bokmakierie/bokmakierie/1.0/bokmakierie-1.0.pom\": { \"hash\": \"sha256-xzj7kEask/noCYciL5yU1viK8XUXsD6zX6ZjsvSjnBE=\" }, \"https://plugins-artifacts.gradle.org/org.gradlex/extra-java-module-info/1.13/108a87b127d3a1a99e59d1e6104a3e91d0b1ff969618cfb5b39e3e27f1feaf6d/extra-java-module-info-1.13.jar\": { \"hash\": \"sha256-EIqHsSfToameWdHmEEo+kdCx/5aWGM+1s54+J/H+r20=\" }, \"https://code.sparrowwallet.com/api/packages/sparrowwallet/maven/com/sparrowwallet/hid4java/0.8.0/hid4java-0.8.0.jar\": { \"hash\": \"sha256-8rksXgbtrtgSyaJv+bl7og+ustabOTt21iD2gsJph6M=\" }, \"https://plugins.gradle.org/m2/org/gradlex/extra-java-module-info/1.13/extra-java-module-info-1.13.jar\": { \"redirect\": \"https://plugins-artifacts.gradle.org/org.gradlex/extra-java-module-info/1.13/108a87b127d3a1a99e59d1e6104a3e91d0b1ff969618cfb5b39e3e27f1feaf6d/extra-java-module-info-1.13.jar\" }, \"https://plugins.gradle.org/m2/org/gradlex/extra-java-module-info/org.gradlex.extra-java-module-info.gradle.plugin/1.13/org.gradlex.extra-java-module-info.gradle.plugin-1.13.pom\": { \"hash\": \"sha256-ll4caPhrb0fP4cqP2rYTPRxz0w4eerkuTHirvGnFs4c=\" }, \"https://example.org/strawberry-jam.jar\": { \"redirect\": \"https://example.org/sadly-unresolvable/strawberry-jam.jar\" }}") (test-begin "gradle") (define cache-entries '()) (test-equal "cache.json is parsed correctly" 5 (begin (set! cache-entries (call-with-input-string cache.json cache.json->entries)) (length cache-entries))) (test-equal "directly referenced entry" (sha256->nix-base32-hash "sha256-8rksXgbtrtgSyaJv+bl7og+ustabOTt21iD2gsJph6M=") (assoc-ref cache-entries "https://code.sparrowwallet.com/api/packages/sparrowwallet/\ maven/com/sparrowwallet/hid4java/0.8.0/hid4java-0.8.0.jar")) (test-equal "indirectly referenced entry" (sha256->nix-base32-hash "sha256-EIqHsSfToameWdHmEEo+kdCx/5aWGM+1s54+J/H+r20=") (assoc-ref cache-entries "https://plugins-artifacts.gradle.org/org.gradlex/\ extra-java-module-info/1.13/108a87b127d3a1a99e59d1e6104a3e91d0b1f\ f969618cfb5b39e3e27f1feaf6d/extra-java-module-info-1.13.jar")) ;;; TODO: Copied tests/machine/hetzner; move to (guix tests). (define-syntax mock* (syntax-rules () ((mock* () body1 body2 ...) (let () body1 body2 ...)) ((mock* ((mod1 sym1 fn1) (mod2 sym2 fn2) ...) body1 body2 ...) (mock (mod1 sym1 fn1) (mock* ((mod2 sym2 fn2) ...) body1) body2 ...)))) (test-assert "gradle-project-url->guix-package" (mock* (((guix import utils) download-git-repository (lambda _ (values "ab99f1d39297e2e84f32033f16368f18e6eeca8e" "dummy-checkout" "0000000000000000000000000000000000000000"))) ((guix import gradle) gradle-project->cache.json (const (open-input-string cache.json)))) (gradle-project-url->guix-package "https://github.com/sparrowwallet/sparrow"))) (test-end "gradle")