Fake the store connection in the tests
So that the tests don't require a store connection.
This commit is contained in:
parent
374dc25440
commit
f6f51bbe0d
2 changed files with 115 additions and 88 deletions
|
|
@ -1499,6 +1499,12 @@ SKIP LOCKED")
|
||||||
(string=? priority "t"))))
|
(string=? priority "t"))))
|
||||||
(exec-query conn query)))
|
(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)
|
(define (process-load-new-guix-revision-job id)
|
||||||
(with-postgresql-connection
|
(with-postgresql-connection
|
||||||
(simple-format #f "load-new-guix-revision ~A" id)
|
(simple-format #f "load-new-guix-revision ~A" id)
|
||||||
|
|
@ -1544,12 +1550,12 @@ SKIP LOCKED")
|
||||||
(real-error-port previous-error-port))
|
(real-error-port previous-error-port))
|
||||||
(catch #t
|
(catch #t
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(with-store store
|
(with-store-connection
|
||||||
(set-build-options store #:fallback? #t)
|
(lambda (store)
|
||||||
(load-new-guix-revision conn
|
(load-new-guix-revision conn
|
||||||
store
|
store
|
||||||
git-repository-id
|
git-repository-id
|
||||||
commit)))
|
commit))))
|
||||||
(lambda (key . args)
|
(lambda (key . args)
|
||||||
(simple-format
|
(simple-format
|
||||||
(current-error-port)
|
(current-error-port)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#:use-module (ice-9 match)
|
#:use-module (ice-9 match)
|
||||||
#:use-module (squee)
|
#:use-module (squee)
|
||||||
#:use-module (guix utils)
|
#:use-module (guix utils)
|
||||||
|
#:use-module (guix store)
|
||||||
#:use-module (guix tests)
|
#:use-module (guix tests)
|
||||||
#:use-module (guix-data-service database)
|
#:use-module (guix-data-service database)
|
||||||
#:use-module (tests mock-inferior)
|
#:use-module (tests mock-inferior)
|
||||||
|
|
@ -11,6 +12,8 @@
|
||||||
|
|
||||||
(test-begin "jobs-load-new-guix-revision")
|
(test-begin "jobs-load-new-guix-revision")
|
||||||
|
|
||||||
|
(%daemon-socket-uri "/var/empty/doesnotexist")
|
||||||
|
|
||||||
(with-postgresql-connection
|
(with-postgresql-connection
|
||||||
"test-jobs-load-new-guix-revision"
|
"test-jobs-load-new-guix-revision"
|
||||||
(lambda (conn)
|
(lambda (conn)
|
||||||
|
|
@ -24,31 +27,116 @@
|
||||||
#t
|
#t
|
||||||
(mock
|
(mock
|
||||||
((guix-data-service jobs load-new-guix-revision)
|
((guix-data-service jobs load-new-guix-revision)
|
||||||
channel->derivations-by-system
|
with-store-connection
|
||||||
(lambda (conn store channel)
|
(lambda (f)
|
||||||
'((x86_64-linux
|
(f 'fake-store-connection)))
|
||||||
.
|
|
||||||
((manifest-entry-item . /gnu/store/foo.drv)
|
|
||||||
(profile . /gnu/store/bar.drv))))))
|
|
||||||
|
|
||||||
(mock
|
(mock
|
||||||
((guix-data-service jobs load-new-guix-revision)
|
((guix-data-service jobs load-new-guix-revision)
|
||||||
channel-derivations-by-system->guix-store-item
|
channel->derivations-by-system
|
||||||
(lambda (store channel-derivations-by-system)
|
(lambda (conn store channel)
|
||||||
"/gnu/store/test"))
|
'((x86_64-linux
|
||||||
|
.
|
||||||
|
((manifest-entry-item . /gnu/store/foo.drv)
|
||||||
|
(profile . /gnu/store/bar.drv))))))
|
||||||
|
|
||||||
(mock
|
(mock
|
||||||
((guix-data-service jobs load-new-guix-revision)
|
((guix-data-service jobs load-new-guix-revision)
|
||||||
extract-information-from
|
channel-derivations-by-system->guix-store-item
|
||||||
(lambda (conn store guix-revision-id commit store-path)
|
(lambda (store channel-derivations-by-system)
|
||||||
#t))
|
"/gnu/store/test"))
|
||||||
|
|
||||||
(mock
|
(mock
|
||||||
((guix-data-service model channel-instance)
|
((guix-data-service jobs load-new-guix-revision)
|
||||||
insert-channel-instances
|
extract-information-from
|
||||||
(lambda (conn guix-revision-id derivations-by-system)
|
(lambda (conn store guix-revision-id commit store-path)
|
||||||
#t))
|
#t))
|
||||||
|
|
||||||
|
(mock
|
||||||
|
((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")
|
||||||
|
|
||||||
|
(test-equal "test build store item failure"
|
||||||
|
#f
|
||||||
|
(mock
|
||||||
|
((guix-data-service jobs load-new-guix-revision)
|
||||||
|
with-store-connection
|
||||||
|
(lambda (f)
|
||||||
|
(f 'fake-store-connection)))
|
||||||
|
|
||||||
|
(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)))))
|
||||||
|
|
||||||
|
(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")
|
||||||
|
|
||||||
|
(test-equal "test extract information failure"
|
||||||
|
#f
|
||||||
|
(mock
|
||||||
|
((guix-data-service jobs load-new-guix-revision)
|
||||||
|
with-store-connection
|
||||||
|
(lambda (f)
|
||||||
|
(f 'fake-store-connection)))
|
||||||
|
|
||||||
|
(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)))))
|
||||||
|
|
||||||
|
(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"))
|
||||||
|
|
||||||
|
(mock
|
||||||
|
((guix-data-service jobs load-new-guix-revision)
|
||||||
|
extract-information-from
|
||||||
|
(lambda (conn store git-repository-id commit store-path)
|
||||||
|
#f))
|
||||||
|
|
||||||
(mock
|
(mock
|
||||||
((guix channels)
|
((guix channels)
|
||||||
channel-news-for-commit
|
channel-news-for-commit
|
||||||
|
|
@ -63,73 +151,6 @@
|
||||||
((id)
|
((id)
|
||||||
(process-load-new-guix-revision-job 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")
|
|
||||||
|
|
||||||
(test-equal "test build store item failure"
|
|
||||||
#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)))))
|
|
||||||
|
|
||||||
(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")
|
|
||||||
|
|
||||||
(test-equal "test extract information failure"
|
|
||||||
#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)))))
|
|
||||||
|
|
||||||
(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"))
|
|
||||||
|
|
||||||
(mock
|
|
||||||
((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")
|
(exec-query conn "TRUNCATE load_new_guix_revision_jobs CASCADE")
|
||||||
|
|
||||||
(test-assert "test duplicate job handling"
|
(test-assert "test duplicate job handling"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue