Subject: Re: [bug#62202] [PATCH v4 6/6] tests: juliahub: Add unit tests for (guix import juliahub).

From: Nicolas Graves <[email-masked]>
Date: Tue, 02 Apr 2024 13:52:33 +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.)

Will do.
>
> Nicolas Graves <[email-masked]> 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.

Sorry for these past contribution, I do it now.
>
>> ---
>>  tests/juliahub.scm | 185 +++++++++++++++++++++++++++++++++++++++++++++
>
> Please add it to ‘Makefile.am’.

Will do.
>
> [...]
>
>> +(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.)
>
>> +(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?

Couldn't manage to get it to work, don't remember why exactly but it was
related to gexps. Will retry it when moving to 'with-http-server' as
advised. 

> Thanks,
> Ludo’.

-- 
Best regards,
Nicolas Graves