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
|
@ -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)
|
||||
|
|
|
@ -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,31 +27,116 @@
|
|||
#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-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
|
||||
((guix channels)
|
||||
channel-news-for-commit
|
||||
|
@ -63,73 +151,6 @@
|
|||
((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")
|
||||
|
||||
(test-assert "test duplicate job handling"
|
||||
|
|
Loading…
Reference in New Issue