;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2022 Xinglu Chen ;;; ;;; 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 . (define-module (test-import-repology) #:use-module (guix download) #:use-module (guix git-download) #:use-module (guix import repology) #:use-module (guix packages) #:use-module (guix tests) #:use-module (guix upstream) #:use-module (json) #:use-module (srfi srfi-64)) (test-begin "repology") (define package-using-git-repository (dummy-package "foo" (version "1.0") (source (origin (method git-fetch) (uri (git-reference (url "https://git.example.org/foo") (commit "1.0"))) (sha256 #f))))) (define package-using-tarball (dummy-package "foo" (version "1.0") (source (origin (method git-fetch) (uri (string-append "https://example.org/foo-" version ".tar.gz")) (sha256 #f))))) (define package-using-tarball-multiple-urls (dummy-package "foo" (version "1.0") (source (origin (method git-fetch) (uri (list (string-append "https://example.org/foo-" version ".tar.gz") (string-append "https://mirror.example.org/foo-" version ".tar.gz"))) (sha256 #f))))) (define %test-json "[ { \"repo\": \"aur\", \"srcname\": \"foo\", \"binname\": \"foo\", \"visiblename\": \"foo\", \"version\": \"1.0.r25.gb86405a\", \"maintainers\": [ \"bob@aur\" ], \"licenses\": [ \"LGPL3+\" ], \"summary\": \"foo bar\" \"status\": \"rolling\", \"origversion\": \"1.0.r25.gb86405a-1\" }, { \"repo\": \"gnuguix\", \"srcname\": \"foo\", \"binname\": \"foo\", \"visiblename\": \"foo\", \"version\": \"1.0\", \"summary\": \"foo bar\", \"status\": \"outdated\", \"origversion\": null }, { \"repo\": \"nix_unstable\", \"name\": \"foo\", \"visiblename\": \"foo\", \"version\": \"2.0\", \"maintainers\": [ \"bob@example.org\" ], \"licenses\": [ \"LGPL-3.0-or-later\" ], \"summary\": \"foo bar\", \"status\": \"newest\", \"origversion\": null } ]") (define (latest-release package) (mock ((guix import json) json-fetch (lambda (url) (json-string->scm %test-json))) (repology-latest-release package))) (test-equal "package using Git repo: version" "2.0" (upstream-source-version (latest-release package-using-git-repository))) (test-equal "package using Git repo: git-reference" (list (git-reference (url "https://git.example.org/foo") (commit "2.0"))) (upstream-source-urls (latest-release package-using-git-repository))) (test-equal "package using tarball: version" "2.0" (upstream-source-version (latest-release package-using-tarball))) (test-equal "package using tarball: URL" (list "https://example.org/foo-2.0.tar.gz") (upstream-source-urls (latest-release package-using-tarball))) (test-equal "package using tarball: multiple URLs" (list "https://example.org/foo-2.0.tar.gz" "https://mirror.example.org/foo-2.0.tar.gz") (upstream-source-urls (latest-release package-using-tarball-multiple-urls))) (test-end "repology")