[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#62202] [PATCH v4 6/6] tests: juliahub: Add unit tests for (guix imp
From: |
Nicolas Graves |
Subject: |
[bug#62202] [PATCH v4 6/6] tests: juliahub: Add unit tests for (guix import juliahub). |
Date: |
Tue, 09 Apr 2024 09:29:59 +0200 |
On 2024-04-01 22:50, Ludovic Courtès wrote:
> Hi,
>
> As part of this v4, I would recommend merging patches 2, 3, and 6, such
> that there’s a single self-contained patch adding ‘guix import
> juliahub’. (That’s what we usually do and I find it clearer because we
> immediately see what goes together.)
>
> Nicolas Graves <ngraves@ngraves.fr> skribis:
>
>> * tests/juliahub.scm : Add unit tests juliahub-redirect,
>> julia-general-registry-parsing, juliahub-fetch.
>
> Just “New file.”
>
> Some of the other files lack a commit log; we can add it for you, but
> it’d be great if you could do it upfront.
>
>> ---
>> tests/juliahub.scm | 185 +++++++++++++++++++++++++++++++++++++++++++++
>
> Please add it to ‘Makefile.am’.
>
> [...]
>
>> +(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)
>
> I strongly encourage using ‘with-http-server’ using the same strategy
> that’s used in ‘tests/pypi.scm’ and others instead of mocking. (‘mock’
> is very sensitive to inlining, plus you sorta have to make assumptions
> about the code path to be able to mock the right things.)
I can't however mock a git server, right? I still must mock at least the
git repo instead of getting it through a custom server, or is there a
better solution here?
>
>> +(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"))))))
>
> Checking for ‘juliahub-package?’ doesn’t tell us much; what about
> checking the whole package, similar to what is done in other importer
> tests?
>
> Thanks,
> Ludo’.
--
Best regards,
Nicolas Graves