diff options
| author | Christopher Baines <mail@cbaines.net> | 2019-05-03 19:55:35 +0100 |
|---|---|---|
| committer | Christopher Baines <mail@cbaines.net> | 2019-05-31 20:22:23 +0100 |
| commit | 2177d9222f8c228fe5cd4e9c98d96f97e9601b86 (patch) | |
| tree | be75f7252b9cfbb9b98b329d2dc2153198d1ad58 /gnu/tests/web.scm | |
| parent | 4764c6cc4671c06a2dd6be41b4b512fd80fa759a (diff) | |
services: Add patchwork.
* gnu/service/web.scm (<patchwork-database-configuration>
<patchwork-settings-module>, <patchwork-configuration>): New record types.
(patchwork-virtualhost): New procedure.
(patchwork-service-type): New variable.
* gnu/tests/web.scm (%test-patchwork): New variable.
* doc/guix.text (Web Services): Document it.
Diffstat (limited to 'gnu/tests/web.scm')
| -rw-r--r-- | gnu/tests/web.scm | 164 |
1 files changed, 162 insertions, 2 deletions
diff --git a/gnu/tests/web.scm b/gnu/tests/web.scm index 319655396a8..7c1c0aa511e 100644 --- a/gnu/tests/web.scm +++ b/gnu/tests/web.scm | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2017 Ludovic Courtès <ludo@gnu.org> | 2 | ;;; Copyright © 2017 Ludovic Courtès <ludo@gnu.org> |
| 3 | ;;; Copyright © 2017 Christopher Baines <mail@cbaines.net> | 3 | ;;; Copyright © 2017, 2019 Christopher Baines <mail@cbaines.net> |
| 4 | ;;; Copyright © 2017, 2018 Clément Lassieur <clement@lassieur.org> | 4 | ;;; Copyright © 2017, 2018 Clément Lassieur <clement@lassieur.org> |
| 5 | ;;; Copyright © 2018 Pierre-Antoine Rouby <pierre-antoine.rouby@inria.fr> | 5 | ;;; Copyright © 2018 Pierre-Antoine Rouby <pierre-antoine.rouby@inria.fr> |
| 6 | ;;; Copyright © 2018 Marius Bakke <mbakke@fastmail.com> | 6 | ;;; Copyright © 2018 Marius Bakke <mbakke@fastmail.com> |
| @@ -28,15 +28,29 @@ | |||
| 28 | #:use-module (gnu system vm) | 28 | #:use-module (gnu system vm) |
| 29 | #:use-module (gnu services) | 29 | #:use-module (gnu services) |
| 30 | #:use-module (gnu services web) | 30 | #:use-module (gnu services web) |
| 31 | #:use-module (gnu services databases) | ||
| 32 | #:use-module (gnu services getmail) | ||
| 31 | #:use-module (gnu services networking) | 33 | #:use-module (gnu services networking) |
| 34 | #:use-module (gnu services shepherd) | ||
| 35 | #:use-module (gnu services mail) | ||
| 36 | #:use-module (gnu packages databases) | ||
| 37 | #:use-module (gnu packages patchutils) | ||
| 38 | #:use-module (gnu packages python) | ||
| 39 | #:use-module (gnu packages web) | ||
| 40 | #:use-module (guix packages) | ||
| 41 | #:use-module (guix modules) | ||
| 42 | #:use-module (guix records) | ||
| 32 | #:use-module (guix gexp) | 43 | #:use-module (guix gexp) |
| 33 | #:use-module (guix store) | 44 | #:use-module (guix store) |
| 45 | #:use-module (guix utils) | ||
| 46 | #:use-module (ice-9 match) | ||
| 34 | #:export (%test-httpd | 47 | #:export (%test-httpd |
| 35 | %test-nginx | 48 | %test-nginx |
| 36 | %test-varnish | 49 | %test-varnish |
| 37 | %test-php-fpm | 50 | %test-php-fpm |
| 38 | %test-hpcguix-web | 51 | %test-hpcguix-web |
| 39 | %test-tailon)) | 52 | %test-tailon |
| 53 | %test-patchwork)) | ||
| 40 | 54 | ||
| 41 | (define %index.html-contents | 55 | (define %index.html-contents |
| 42 | ;; Contents of the /index.html file. | 56 | ;; Contents of the /index.html file. |
| @@ -498,3 +512,149 @@ HTTP-PORT." | |||
| 498 | (name "tailon") | 512 | (name "tailon") |
| 499 | (description "Connect to a running Tailon server.") | 513 | (description "Connect to a running Tailon server.") |
| 500 | (value (run-tailon-test)))) | 514 | (value (run-tailon-test)))) |
| 515 | |||
| 516 | |||
| 517 | ;;; | ||
| 518 | ;;; Patchwork | ||
| 519 | ;;; | ||
| 520 | |||
| 521 | (define patchwork-initial-database-setup-service | ||
| 522 | (match-lambda | ||
| 523 | (($ <patchwork-database-configuration> | ||
| 524 | engine name user password host port) | ||
| 525 | |||
| 526 | (define start-gexp | ||
| 527 | #~(lambda () | ||
| 528 | (let ((pid (primitive-fork)) | ||
| 529 | (postgres (getpwnam "postgres"))) | ||
| 530 | (if (eq? pid 0) | ||
| 531 | (dynamic-wind | ||
| 532 | (const #t) | ||
| 533 | (lambda () | ||
| 534 | (setgid (passwd:gid postgres)) | ||
| 535 | (setuid (passwd:uid postgres)) | ||
| 536 | (primitive-exit | ||
| 537 | (if (and | ||
| 538 | (zero? | ||
| 539 | (system* #$(file-append postgresql "/bin/createuser") | ||
| 540 | #$user)) | ||
| 541 | (zero? | ||
| 542 | (system* #$(file-append postgresql "/bin/createdb") | ||
| 543 | "-O" #$user #$name))) | ||
| 544 | 0 | ||
| 545 | 1))) | ||
| 546 | (lambda () | ||
| 547 | (primitive-exit 1))) | ||
| 548 | (zero? (cdr (waitpid pid))))))) | ||
| 549 | |||
| 550 | (shepherd-service | ||
| 551 | (requirement '(postgres)) | ||
| 552 | (provision '(patchwork-postgresql-user-and-database)) | ||
| 553 | (start start-gexp) | ||
| 554 | (stop #~(const #f)) | ||
| 555 | (respawn? #f) | ||
| 556 | (documentation "Setup patchwork database."))))) | ||
| 557 | |||
| 558 | (define (patchwork-os patchwork) | ||
| 559 | (simple-operating-system | ||
| 560 | (service dhcp-client-service-type) | ||
| 561 | (service httpd-service-type | ||
| 562 | (httpd-configuration | ||
| 563 | (config | ||
| 564 | (httpd-config-file | ||
| 565 | (listen '("8080")))))) | ||
| 566 | (service postgresql-service-type) | ||
| 567 | (service patchwork-service-type | ||
| 568 | (patchwork-configuration | ||
| 569 | (patchwork patchwork) | ||
| 570 | (domain "localhost") | ||
| 571 | (settings-module | ||
| 572 | (patchwork-settings-module | ||
| 573 | (allowed-hosts (list domain)) | ||
| 574 | (default-from-email ""))) | ||
| 575 | (getmail-retriever-config | ||
| 576 | (getmail-retriever-configuration | ||
| 577 | (type "SimpleIMAPSSLRetriever") | ||
| 578 | (server "imap.example.com") | ||
| 579 | (port 993) | ||
| 580 | (username "username") | ||
| 581 | (password "password") | ||
| 582 | (extra-parameters | ||
| 583 | '((mailboxes . ("INBOX")))))))) | ||
| 584 | (simple-service 'patchwork-database-setup | ||
| 585 | shepherd-root-service-type | ||
| 586 | (list | ||
| 587 | (patchwork-initial-database-setup-service | ||
| 588 | (patchwork-database-configuration)))))) | ||
| 589 | |||
| 590 | (define (run-patchwork-test patchwork) | ||
| 591 | "Run tests in %NGINX-OS, which has nginx running and listening on | ||
| 592 | HTTP-PORT." | ||
| 593 | (define os | ||
| 594 | (marionette-operating-system | ||
| 595 | (patchwork-os patchwork) | ||
| 596 | #:imported-modules '((gnu services herd) | ||
| 597 | (guix combinators)))) | ||
| 598 | |||
| 599 | (define forwarded-port 8080) | ||
| 600 | |||
| 601 | (define vm | ||
| 602 | (virtual-machine | ||
| 603 | (operating-system os) | ||
| 604 | (port-forwardings `((8080 . ,forwarded-port))))) | ||
| 605 | |||
| 606 | (define test | ||
| 607 | (with-imported-modules '((gnu build marionette)) | ||
| 608 | #~(begin | ||
| 609 | (use-modules (srfi srfi-11) (srfi srfi-64) | ||
| 610 | (gnu build marionette) | ||
| 611 | (web uri) | ||
| 612 | (web client) | ||
| 613 | (web response)) | ||
| 614 | |||
| 615 | (define marionette | ||
| 616 | (make-marionette (list #$vm))) | ||
| 617 | |||
| 618 | (mkdir #$output) | ||
| 619 | (chdir #$output) | ||
| 620 | |||
| 621 | (test-begin "patchwork") | ||
| 622 | |||
| 623 | (test-assert "patchwork-postgresql-user-and-service started" | ||
| 624 | (marionette-eval | ||
| 625 | '(begin | ||
| 626 | (use-modules (gnu services herd)) | ||
| 627 | (match (start-service 'patchwork-postgresql-user-and-database) | ||
| 628 | (#f #f) | ||
| 629 | (('service response-parts ...) | ||
| 630 | (match (assq-ref response-parts 'running) | ||
| 631 | ((#t) #t) | ||
| 632 | ((pid) (number? pid)))))) | ||
| 633 | marionette)) | ||
| 634 | |||
| 635 | (test-assert "httpd running" | ||
| 636 | (marionette-eval | ||
| 637 | '(begin | ||
| 638 | (use-modules (gnu services herd)) | ||
| 639 | (start-service 'httpd)) | ||
| 640 | marionette)) | ||
| 641 | |||
| 642 | (test-equal "http-get" | ||
| 643 | 200 | ||
| 644 | (let-values | ||
| 645 | (((response text) | ||
| 646 | (http-get #$(simple-format | ||
| 647 | #f "http://localhost:~A/" forwarded-port) | ||
| 648 | #:decode-body? #t))) | ||
| 649 | (response-code response))) | ||
| 650 | |||
| 651 | (test-end) | ||
| 652 | (exit (= (test-runner-fail-count (test-runner-current)) 0))))) | ||
| 653 | |||
| 654 | (gexp->derivation "patchwork-test" test)) | ||
| 655 | |||
| 656 | (define %test-patchwork | ||
| 657 | (system-test | ||
| 658 | (name "patchwork") | ||
| 659 | (description "Connect to a running Patchwork service.") | ||
| 660 | (value (run-patchwork-test patchwork)))) | ||
