aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2020-02-14 09:18:28 +0000
committerChristopher Baines <mail@cbaines.net>2020-02-14 09:18:28 +0000
commitf6f51bbe0dc89dfec6d1d6e74818ad1f9c2d6dbc (patch)
treef176b42c47b4b7e136fedd9f302bf560249c445c
parent374dc25440efaef619cdc8d3288261c20ce45858 (diff)
downloaddata-service-f6f51bbe0dc89dfec6d1d6e74818ad1f9c2d6dbc.tar
data-service-f6f51bbe0dc89dfec6d1d6e74818ad1f9c2d6dbc.tar.gz
Fake the store connection in the tests
So that the tests don't require a store connection.
-rw-r--r--guix-data-service/jobs/load-new-guix-revision.scm18
-rw-r--r--tests/jobs-load-new-guix-revision.scm157
2 files changed, 101 insertions, 74 deletions
diff --git a/guix-data-service/jobs/load-new-guix-revision.scm b/guix-data-service/jobs/load-new-guix-revision.scm
index dc18267..349d40a 100644
--- a/guix-data-service/jobs/load-new-guix-revision.scm
+++ b/guix-data-service/jobs/load-new-guix-revision.scm
@@ -1499,6 +1499,12 @@ SKIP LOCKED")
(string=? priority "t"))))
(exec-query conn query)))
+(define (with-store-connection f)
+ (with-store store
+ (set-build-options store #:fallback? #t)
+
+ (f store)))
+
(define (process-load-new-guix-revision-job id)
(with-postgresql-connection
(simple-format #f "load-new-guix-revision ~A" id)
@@ -1544,12 +1550,12 @@ SKIP LOCKED")
(real-error-port previous-error-port))
(catch #t
(lambda ()
- (with-store store
- (set-build-options store #:fallback? #t)
- (load-new-guix-revision conn
- store
- git-repository-id
- commit)))
+ (with-store-connection
+ (lambda (store)
+ (load-new-guix-revision conn
+ store
+ git-repository-id
+ commit))))
(lambda (key . args)
(simple-format
(current-error-port)
diff --git a/tests/jobs-load-new-guix-revision.scm b/tests/jobs-load-new-guix-revision.scm
index e101bce..859c63f 100644
--- a/tests/jobs-load-new-guix-revision.scm
+++ b/tests/jobs-load-new-guix-revision.scm
@@ -3,6 +3,7 @@
#:use-module (ice-9 match)
#:use-module (squee)
#:use-module (guix utils)
+ #:use-module (guix store)
#:use-module (guix tests)
#:use-module (guix-data-service database)
#:use-module (tests mock-inferior)
@@ -11,6 +12,8 @@
(test-begin "jobs-load-new-guix-revision")
+(%daemon-socket-uri "/var/empty/doesnotexist")
+
(with-postgresql-connection
"test-jobs-load-new-guix-revision"
(lambda (conn)
@@ -24,44 +27,50 @@
#t
(mock
((guix-data-service jobs load-new-guix-revision)
- channel->derivations-by-system
- (lambda (conn store channel)
- '((x86_64-linux
- .
- ((manifest-entry-item . /gnu/store/foo.drv)
- (profile . /gnu/store/bar.drv))))))
+ with-store-connection
+ (lambda (f)
+ (f 'fake-store-connection)))
(mock
((guix-data-service jobs load-new-guix-revision)
- channel-derivations-by-system->guix-store-item
- (lambda (store channel-derivations-by-system)
- "/gnu/store/test"))
+ channel->derivations-by-system
+ (lambda (conn store channel)
+ '((x86_64-linux
+ .
+ ((manifest-entry-item . /gnu/store/foo.drv)
+ (profile . /gnu/store/bar.drv))))))
(mock
((guix-data-service jobs load-new-guix-revision)
- extract-information-from
- (lambda (conn store guix-revision-id commit store-path)
- #t))
+ channel-derivations-by-system->guix-store-item
+ (lambda (store channel-derivations-by-system)
+ "/gnu/store/test"))
(mock
- ((guix-data-service model channel-instance)
- insert-channel-instances
- (lambda (conn guix-revision-id derivations-by-system)
+ ((guix-data-service jobs load-new-guix-revision)
+ extract-information-from
+ (lambda (conn store guix-revision-id commit store-path)
#t))
(mock
- ((guix channels)
- channel-news-for-commit
- (lambda (channel commit)
- '()))
-
- (match (enqueue-load-new-guix-revision-job
- conn
- (git-repository-url->git-repository-id conn "test-url")
- "test-commit"
- "test-source")
- ((id)
- (process-load-new-guix-revision-job id)))))))))
+ ((guix-data-service model channel-instance)
+ insert-channel-instances
+ (lambda (conn guix-revision-id derivations-by-system)
+ #t))
+
+ (mock
+ ((guix channels)
+ channel-news-for-commit
+ (lambda (channel commit)
+ '()))
+
+ (match (enqueue-load-new-guix-revision-job
+ conn
+ (git-repository-url->git-repository-id conn "test-url")
+ "test-commit"
+ "test-source")
+ ((id)
+ (process-load-new-guix-revision-job id))))))))))
(exec-query conn "TRUNCATE guix_revisions CASCADE")
(exec-query conn "TRUNCATE load_new_guix_revision_jobs CASCADE")
@@ -70,26 +79,32 @@
#f
(mock
((guix-data-service jobs load-new-guix-revision)
- channel->derivations-by-system
- (lambda (conn store channel)
- '(x86_64-linux
- .
- ((manifest-entry-item . /gnu/store/foo.drv)
- (profile . /gnu/store/bar.drv)))))
+ with-store-connection
+ (lambda (f)
+ (f 'fake-store-connection)))
(mock
((guix-data-service jobs load-new-guix-revision)
- channel-derivations-by-system->guix-store-item
- (lambda (store channel-derivations-by-system)
- #f))
-
- (match (enqueue-load-new-guix-revision-job
- conn
- (git-repository-url->git-repository-id conn "test-url")
- "test-commit"
- "test-source")
- ((id)
- (process-load-new-guix-revision-job id))))))
+ channel->derivations-by-system
+ (lambda (conn store channel)
+ '(x86_64-linux
+ .
+ ((manifest-entry-item . /gnu/store/foo.drv)
+ (profile . /gnu/store/bar.drv)))))
+
+ (mock
+ ((guix-data-service jobs load-new-guix-revision)
+ channel-derivations-by-system->guix-store-item
+ (lambda (store channel-derivations-by-system)
+ #f))
+
+ (match (enqueue-load-new-guix-revision-job
+ conn
+ (git-repository-url->git-repository-id conn "test-url")
+ "test-commit"
+ "test-source")
+ ((id)
+ (process-load-new-guix-revision-job id)))))))
(exec-query conn "TRUNCATE load_new_guix_revision_jobs CASCADE")
@@ -97,38 +112,44 @@
#f
(mock
((guix-data-service jobs load-new-guix-revision)
- channel->derivations-by-system
- (lambda (conn store channel)
- '(x86_64-linux
- .
- ((manifest-entry-item . /gnu/store/foo.drv)
- (profile . /gnu/store/bar.drv)))))
+ with-store-connection
+ (lambda (f)
+ (f 'fake-store-connection)))
(mock
((guix-data-service jobs load-new-guix-revision)
- channel-derivations-by-system->guix-store-item
- (lambda (store channel-derivations-by-system)
- "/gnu/store/test"))
+ channel->derivations-by-system
+ (lambda (conn store channel)
+ '(x86_64-linux
+ .
+ ((manifest-entry-item . /gnu/store/foo.drv)
+ (profile . /gnu/store/bar.drv)))))
(mock
((guix-data-service jobs load-new-guix-revision)
- extract-information-from
- (lambda (conn store git-repository-id commit store-path)
- #f))
+ channel-derivations-by-system->guix-store-item
+ (lambda (store channel-derivations-by-system)
+ "/gnu/store/test"))
(mock
- ((guix channels)
- channel-news-for-commit
- (lambda (channel commit)
- '()))
-
- (match (enqueue-load-new-guix-revision-job
- conn
- (git-repository-url->git-repository-id conn "test-url")
- "test-commit"
- "test-source")
- ((id)
- (process-load-new-guix-revision-job id))))))))
+ ((guix-data-service jobs load-new-guix-revision)
+ extract-information-from
+ (lambda (conn store git-repository-id commit store-path)
+ #f))
+
+ (mock
+ ((guix channels)
+ channel-news-for-commit
+ (lambda (channel commit)
+ '()))
+
+ (match (enqueue-load-new-guix-revision-job
+ conn
+ (git-repository-url->git-repository-id conn "test-url")
+ "test-commit"
+ "test-source")
+ ((id)
+ (process-load-new-guix-revision-job id)))))))))
(exec-query conn "TRUNCATE load_new_guix_revision_jobs CASCADE")