Adapt some license related code to work without mock in the tests
With Guile 3, there's a potential for mock to work in even fewer circumstances. So, adapt the code to enable writing the tests without mock.
This commit is contained in:
parent
ce10833459
commit
2f41fe79be
7 changed files with 88 additions and 92 deletions
|
|
@ -3,45 +3,46 @@
|
|||
#:use-module (guix utils)
|
||||
#:use-module (guix tests)
|
||||
#:use-module (guix-data-service database)
|
||||
#:use-module (tests mock-inferior)
|
||||
#:use-module (guix-data-service model license)
|
||||
#:use-module (guix-data-service model license-set))
|
||||
|
||||
(use-modules (tests driver))
|
||||
|
||||
(test-begin "test-model-license-set")
|
||||
|
||||
(mock
|
||||
((guix-data-service model license)
|
||||
inferior-packages->license-data
|
||||
(lambda (inf packages)
|
||||
'((("License 1"
|
||||
"https://gnu.org/licenses/test-1.html"
|
||||
"https://example.com/why-license-1"))
|
||||
(("License 1"
|
||||
"https://gnu.org/licenses/test-1.html"
|
||||
#f)
|
||||
("License 2"
|
||||
#f
|
||||
#f)))))
|
||||
(define license-data
|
||||
'((("License 1"
|
||||
"https://gnu.org/licenses/test-1.html"
|
||||
"https://example.com/why-license-1"))
|
||||
(("License 1"
|
||||
"https://gnu.org/licenses/test-1.html"
|
||||
#f)
|
||||
("License 2"
|
||||
#f
|
||||
#f))))
|
||||
|
||||
(with-postgresql-connection
|
||||
"test-model-license-set"
|
||||
(lambda (conn)
|
||||
(check-test-database! conn)
|
||||
(with-postgresql-connection
|
||||
"test-model-license-set"
|
||||
(lambda (conn)
|
||||
(check-test-database! conn)
|
||||
|
||||
(with-postgresql-transaction
|
||||
conn
|
||||
(lambda (conn)
|
||||
(test-assert "works"
|
||||
(inferior-packages->license-set-ids conn #f #f)))
|
||||
#:always-rollback? #t)
|
||||
(with-postgresql-transaction
|
||||
conn
|
||||
(lambda (conn)
|
||||
(test-assert "works"
|
||||
(inferior-packages->license-set-ids
|
||||
conn
|
||||
(inferior-packages->license-id-lists conn license-data))))
|
||||
#:always-rollback? #t)
|
||||
|
||||
(with-postgresql-transaction
|
||||
conn
|
||||
(lambda (conn)
|
||||
(test-equal "works repeatedly"
|
||||
(inferior-packages->license-set-ids conn #f #f)
|
||||
(inferior-packages->license-set-ids conn #f #f)))
|
||||
#:always-rollback? #t))))
|
||||
(with-postgresql-transaction
|
||||
conn
|
||||
(lambda (conn)
|
||||
(let ((license-id-lists
|
||||
(inferior-packages->license-id-lists conn license-data)))
|
||||
(test-equal "works repeatedly"
|
||||
(inferior-packages->license-set-ids conn license-id-lists)
|
||||
(inferior-packages->license-set-ids conn license-id-lists))))
|
||||
#:always-rollback? #t)))
|
||||
|
||||
(test-end)
|
||||
|
|
|
|||
|
|
@ -3,46 +3,42 @@
|
|||
#:use-module (guix utils)
|
||||
#:use-module (guix tests)
|
||||
#:use-module (guix-data-service database)
|
||||
#:use-module (tests mock-inferior)
|
||||
#:use-module (guix-data-service model license))
|
||||
|
||||
(test-begin "test-model-license")
|
||||
|
||||
(mock
|
||||
((guix-data-service model license)
|
||||
inferior-packages->license-data
|
||||
(lambda (inf packages)
|
||||
'((("License 1"
|
||||
"https://gnu.org/licenses/test-1.html"
|
||||
"https://example.com/why-license-1"))
|
||||
(("License 1"
|
||||
"https://gnu.org/licenses/test-1.html"
|
||||
#f)
|
||||
("License 2"
|
||||
"https://gnu.org/licenses/test-2.html"
|
||||
#f)
|
||||
("License 3"
|
||||
#f
|
||||
#f)))))
|
||||
(define license-data
|
||||
'((("License 1"
|
||||
"https://gnu.org/licenses/test-1.html"
|
||||
"https://example.com/why-license-1"))
|
||||
(("License 1"
|
||||
"https://gnu.org/licenses/test-1.html"
|
||||
#f)
|
||||
("License 2"
|
||||
"https://gnu.org/licenses/test-2.html"
|
||||
#f)
|
||||
("License 3"
|
||||
#f
|
||||
#f))))
|
||||
|
||||
(with-postgresql-connection
|
||||
"test-model-license"
|
||||
(lambda (conn)
|
||||
(check-test-database! conn)
|
||||
(with-postgresql-connection
|
||||
"test-model-license"
|
||||
(lambda (conn)
|
||||
(check-test-database! conn)
|
||||
|
||||
(with-postgresql-transaction
|
||||
conn
|
||||
(lambda (conn)
|
||||
(test-assert "works"
|
||||
(inferior-packages->license-id-lists conn #f #f)))
|
||||
#:always-rollback? #t)
|
||||
(with-postgresql-transaction
|
||||
conn
|
||||
(lambda (conn)
|
||||
(test-assert "works"
|
||||
(inferior-packages->license-id-lists conn license-data)))
|
||||
#:always-rollback? #t)
|
||||
|
||||
(with-postgresql-transaction
|
||||
conn
|
||||
(lambda (conn)
|
||||
(test-equal "works repeatedly"
|
||||
(inferior-packages->license-id-lists conn #f #f)
|
||||
(inferior-packages->license-id-lists conn #f #f)))
|
||||
#:always-rollback? #t))))
|
||||
(with-postgresql-transaction
|
||||
conn
|
||||
(lambda (conn)
|
||||
(test-equal "works repeatedly"
|
||||
(inferior-packages->license-id-lists conn license-data)
|
||||
(inferior-packages->license-id-lists conn license-data)))
|
||||
#:always-rollback? #t)))
|
||||
|
||||
(test-end)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#:use-module (guix utils)
|
||||
#:use-module (guix tests)
|
||||
#:use-module (tests mock-inferior)
|
||||
#:use-module (guix-data-service model license)
|
||||
#:use-module (guix-data-service model license-set)
|
||||
#:use-module (guix-data-service database))
|
||||
|
||||
|
|
@ -28,15 +29,14 @@
|
|||
(location #f)))
|
||||
|
||||
(define (test-license-set-ids conn)
|
||||
(mock
|
||||
((guix-data-service model license)
|
||||
inferior-packages->license-data
|
||||
(lambda (inf packages)
|
||||
'((("License 1"
|
||||
"https://gnu.org/licenses/test-1.html"
|
||||
"https://example.com/why-license-1")))))
|
||||
(let ((license-id-lists
|
||||
(inferior-packages->license-id-lists
|
||||
conn
|
||||
'((("License 1"
|
||||
"https://gnu.org/licenses/test-1.html"
|
||||
"https://example.com/why-license-1"))))))
|
||||
|
||||
(inferior-packages->license-set-ids conn #f #f)))
|
||||
(inferior-packages->license-set-ids conn license-id-lists)))
|
||||
|
||||
(with-mock-inferior-packages
|
||||
(lambda ()
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#:use-module (guix utils)
|
||||
#:use-module (guix tests)
|
||||
#:use-module (tests mock-inferior)
|
||||
#:use-module (guix-data-service model license)
|
||||
#:use-module (guix-data-service model license-set)
|
||||
#:use-module (guix-data-service model package)
|
||||
#:use-module (guix-data-service model package-metadata)
|
||||
|
|
@ -31,15 +32,14 @@
|
|||
(location #f)))
|
||||
|
||||
(define (test-license-set-ids conn)
|
||||
(mock
|
||||
((guix-data-service model license)
|
||||
inferior-packages->license-data
|
||||
(lambda (inf packages)
|
||||
'((("License 1"
|
||||
"https://gnu.org/licenses/test-1.html"
|
||||
"https://example.com/why-license-1")))))
|
||||
(let ((license-id-lists
|
||||
(inferior-packages->license-id-lists
|
||||
conn
|
||||
'((("License 1"
|
||||
"https://gnu.org/licenses/test-1.html"
|
||||
"https://example.com/why-license-1"))))))
|
||||
|
||||
(inferior-packages->license-set-ids conn #f #f)))
|
||||
(inferior-packages->license-set-ids conn license-id-lists)))
|
||||
|
||||
(define mock-inferior-packages
|
||||
(list mock-inferior-package-foo
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue