From 2f41fe79be6873c4329881fbce6bde671666e16e Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Mon, 24 Feb 2020 21:35:44 +0000 Subject: 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. --- tests/model-license-set.scm | 63 ++++++++++++++++++++------------------- tests/model-license.scm | 64 +++++++++++++++++++--------------------- tests/model-package-metadata.scm | 16 +++++----- tests/model-package.scm | 16 +++++----- 4 files changed, 78 insertions(+), 81 deletions(-) (limited to 'tests') diff --git a/tests/model-license-set.scm b/tests/model-license-set.scm index 62fd899..5c63b94 100644 --- a/tests/model-license-set.scm +++ b/tests/model-license-set.scm @@ -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) diff --git a/tests/model-license.scm b/tests/model-license.scm index 9e9d8b2..32b5623 100644 --- a/tests/model-license.scm +++ b/tests/model-license.scm @@ -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) diff --git a/tests/model-package-metadata.scm b/tests/model-package-metadata.scm index d80d6fd..81741b5 100644 --- a/tests/model-package-metadata.scm +++ b/tests/model-package-metadata.scm @@ -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 () diff --git a/tests/model-package.scm b/tests/model-package.scm index 57a3142..0f2c796 100644 --- a/tests/model-package.scm +++ b/tests/model-package.scm @@ -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 -- cgit v1.2.3