diff options
| author | Rodion Goritskov <rodion@goritskov.com> | 2025-07-19 10:52:11 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2025-09-26 21:39:40 +0200 |
| commit | 054aae7bb201f6ba83390017a4cc644061a6abda (patch) | |
| tree | dcb79b68c76b50984c0f397d6477ba60382de22a /gnu/tests | |
| parent | d411aff61193c9ce542aa66c047d91e00660586d (diff) | |
services: Add miniflux-service-type.
* doc/guix.texi: Document Miniflux service and configuration.
* gnu/services/web.scm: New service.
* gnu/services/web.scm: Define shepherd service and account roles.
* gnu/tests/web.scm: (%miniflux-create-admin-credentials,
miniflux-base-system, %test-miniflux-admin-string, %test-miniflux-admin-file,
%test-miniflux-socket): Add system tests for Miniflux service.
Change-Id: I4a336e677ec8b46aed632f0ded9cc11c2d38975f
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'gnu/tests')
| -rw-r--r-- | gnu/tests/web.scm | 194 |
1 files changed, 193 insertions, 1 deletions
diff --git a/gnu/tests/web.scm b/gnu/tests/web.scm index 431996ede48..419b5f0b5bf 100644 --- a/gnu/tests/web.scm +++ b/gnu/tests/web.scm | |||
| @@ -5,6 +5,7 @@ | |||
| 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> |
| 7 | ;;; Copyright © 2024 Maxim Cournoyer <maxim@guixotic.coop> | 7 | ;;; Copyright © 2024 Maxim Cournoyer <maxim@guixotic.coop> |
| 8 | ;;; Copyright © 2025 Rodion Goritskov <rodion@goritskov.com> | ||
| 8 | ;;; | 9 | ;;; |
| 9 | ;;; This file is part of GNU Guix. | 10 | ;;; This file is part of GNU Guix. |
| 10 | ;;; | 11 | ;;; |
| @@ -37,6 +38,7 @@ | |||
| 37 | #:use-module (gnu packages base) | 38 | #:use-module (gnu packages base) |
| 38 | #:use-module (gnu packages databases) | 39 | #:use-module (gnu packages databases) |
| 39 | #:use-module (gnu packages guile-xyz) | 40 | #:use-module (gnu packages guile-xyz) |
| 41 | #:use-module (gnu packages gnupg) | ||
| 40 | #:use-module (gnu packages patchutils) | 42 | #:use-module (gnu packages patchutils) |
| 41 | #:use-module (gnu packages python) | 43 | #:use-module (gnu packages python) |
| 42 | #:use-module (gnu packages tls) | 44 | #:use-module (gnu packages tls) |
| @@ -56,7 +58,10 @@ | |||
| 56 | %test-hpcguix-web | 58 | %test-hpcguix-web |
| 57 | %test-anonip | 59 | %test-anonip |
| 58 | %test-patchwork | 60 | %test-patchwork |
| 59 | %test-agate)) | 61 | %test-agate |
| 62 | %test-miniflux-admin-string | ||
| 63 | %test-miniflux-admin-file | ||
| 64 | %test-miniflux-socket)) | ||
| 60 | 65 | ||
| 61 | (define %index.html-contents | 66 | (define %index.html-contents |
| 62 | ;; Contents of the /index.html file. | 67 | ;; Contents of the /index.html file. |
| @@ -848,3 +853,190 @@ HTTP-PORT." | |||
| 848 | (name "agate") | 853 | (name "agate") |
| 849 | (description "Connect to a running Agate service.") | 854 | (description "Connect to a running Agate service.") |
| 850 | (value (run-agate-test name %agate-os %index.gmi-contents)))) | 855 | (value (run-agate-test name %agate-os %index.gmi-contents)))) |
| 856 | |||
| 857 | |||
| 858 | ;;; | ||
| 859 | ;;; Miniflux | ||
| 860 | ;;; | ||
| 861 | |||
| 862 | (define %miniflux-create-admin-credentials | ||
| 863 | #~(begin | ||
| 864 | (mkdir "/var/miniflux") | ||
| 865 | (call-with-output-file "/var/miniflux/admin-username" | ||
| 866 | (lambda (port) | ||
| 867 | (display "test" port))) | ||
| 868 | (call-with-output-file "/var/miniflux/admin-password" | ||
| 869 | (lambda (port) | ||
| 870 | (display "testpassword" port))))) | ||
| 871 | |||
| 872 | (define miniflux-base-system | ||
| 873 | (lambda (miniflux-config) | ||
| 874 | (simple-operating-system | ||
| 875 | (simple-service 'create-admin-credentials | ||
| 876 | activation-service-type | ||
| 877 | %miniflux-create-admin-credentials) | ||
| 878 | (service dhcpcd-service-type) | ||
| 879 | (service postgresql-service-type | ||
| 880 | (postgresql-configuration | ||
| 881 | (postgresql postgresql-13))) | ||
| 882 | (service miniflux-service-type | ||
| 883 | miniflux-config)))) | ||
| 884 | |||
| 885 | (define %miniflux-with-admin-as-string | ||
| 886 | (miniflux-base-system | ||
| 887 | (miniflux-configuration | ||
| 888 | (listen-address "0.0.0.0:8080") | ||
| 889 | (create-administrator-account? #t) | ||
| 890 | (administrator-account-name "test") | ||
| 891 | (administrator-account-password "testpassword")))) | ||
| 892 | |||
| 893 | (define %miniflux-with-admin-as-file | ||
| 894 | (miniflux-base-system | ||
| 895 | (miniflux-configuration | ||
| 896 | (listen-address "0.0.0.0:8080") | ||
| 897 | (create-administrator-account? #t) | ||
| 898 | (administrator-account-name "/var/miniflux/admin-username") | ||
| 899 | (administrator-account-password "/var/miniflux/admin-password")))) | ||
| 900 | |||
| 901 | (define %miniflux-with-socket | ||
| 902 | (miniflux-base-system | ||
| 903 | (miniflux-configuration | ||
| 904 | (listen-address "/var/run/miniflux/miniflux.sock")))) | ||
| 905 | |||
| 906 | (define* (run-miniflux-test name test-os) | ||
| 907 | (define os | ||
| 908 | (marionette-operating-system | ||
| 909 | test-os | ||
| 910 | #:imported-modules '((gnu services herd) | ||
| 911 | (guix combinators)))) | ||
| 912 | |||
| 913 | (define forwarded-port 8080) | ||
| 914 | |||
| 915 | (define vm | ||
| 916 | (virtual-machine | ||
| 917 | (operating-system os) | ||
| 918 | (memory-size 512) | ||
| 919 | (port-forwardings `((8080 . ,forwarded-port))))) | ||
| 920 | |||
| 921 | (define test | ||
| 922 | (with-extensions (list guile-gcrypt) | ||
| 923 | (with-imported-modules '((gnu build marionette)) | ||
| 924 | #~(begin | ||
| 925 | (use-modules (srfi srfi-64) | ||
| 926 | (srfi srfi-11) | ||
| 927 | (gnu build marionette) | ||
| 928 | (web client) | ||
| 929 | (web uri) | ||
| 930 | (web response) | ||
| 931 | (ice-9 match) | ||
| 932 | (ice-9 iconv) | ||
| 933 | (gcrypt base64)) | ||
| 934 | |||
| 935 | (define marionette | ||
| 936 | (make-marionette (list #$vm))) | ||
| 937 | |||
| 938 | (test-runner-current (system-test-runner #$output)) | ||
| 939 | (test-begin #$name) | ||
| 940 | |||
| 941 | (test-assert "Check Miniflux service is running" | ||
| 942 | (begin | ||
| 943 | (#$retry-on-error | ||
| 944 | (lambda () | ||
| 945 | (marionette-eval | ||
| 946 | '(begin | ||
| 947 | (use-modules (gnu services herd)) | ||
| 948 | (match (start-service '#$(string->symbol "miniflux")) | ||
| 949 | (#f #f) | ||
| 950 | (('service response-parts ...) | ||
| 951 | (match (assq-ref response-parts 'running) | ||
| 952 | (#f #f) | ||
| 953 | ((running) #t))))) | ||
| 954 | marionette)) | ||
| 955 | #:delay 1 | ||
| 956 | #:times 10))) | ||
| 957 | |||
| 958 | (test-assert "Miniflux TCP port ready, IPv4" | ||
| 959 | (wait-for-tcp-port #$forwarded-port marionette)) | ||
| 960 | |||
| 961 | (test-assert "Miniflux login page is opened" | ||
| 962 | (begin | ||
| 963 | (wait-for-tcp-port #$forwarded-port marionette) | ||
| 964 | (#$retry-on-error | ||
| 965 | (lambda () | ||
| 966 | (let-values (((_ text) | ||
| 967 | (http-get | ||
| 968 | #$(format #f "http://localhost:~A/" forwarded-port) | ||
| 969 | #:decode-body? #t))) | ||
| 970 | (string-contains text "<title>Sign In - Miniflux</title>"))) | ||
| 971 | #:times 10 | ||
| 972 | #:delay 2))) | ||
| 973 | |||
| 974 | (define authorization-header | ||
| 975 | (let ((encoded (base64-encode (string->bytevector "test:testpassword" "utf-8")))) | ||
| 976 | `(authorization . (basic . ,encoded)))) | ||
| 977 | |||
| 978 | (test-equal "Miniflux initial admin API call is successful" | ||
| 979 | 200 | ||
| 980 | (begin | ||
| 981 | (wait-for-tcp-port #$forwarded-port marionette) | ||
| 982 | (#$retry-on-error | ||
| 983 | (lambda () | ||
| 984 | (let-values (((response _) | ||
| 985 | (http-get #$(format #f "http://localhost:~A/v1/me" forwarded-port) | ||
| 986 | #:headers (list authorization-header) | ||
| 987 | #:decode-body? #t))) | ||
| 988 | |||
| 989 | (response-code response))) | ||
| 990 | #:times 10 | ||
| 991 | #:delay 2))) | ||
| 992 | |||
| 993 | (test-end))))) | ||
| 994 | (gexp->derivation (string-append name "-test") test)) | ||
| 995 | |||
| 996 | (define* (run-miniflux-socket-test name test-os) | ||
| 997 | (define os | ||
| 998 | (marionette-operating-system | ||
| 999 | test-os | ||
| 1000 | #:imported-modules '((gnu services herd) | ||
| 1001 | (guix combinators)))) | ||
| 1002 | |||
| 1003 | (define vm | ||
| 1004 | (virtual-machine | ||
| 1005 | (operating-system os) | ||
| 1006 | (memory-size 512))) | ||
| 1007 | |||
| 1008 | (define test | ||
| 1009 | (with-imported-modules '((gnu build marionette)) | ||
| 1010 | #~(begin | ||
| 1011 | (use-modules (srfi srfi-64) | ||
| 1012 | (gnu build marionette)) | ||
| 1013 | |||
| 1014 | (define marionette | ||
| 1015 | (make-marionette (list #$vm))) | ||
| 1016 | |||
| 1017 | (test-runner-current (system-test-runner #$output)) | ||
| 1018 | (test-begin #$name) | ||
| 1019 | |||
| 1020 | (test-assert "Check socket file is created" | ||
| 1021 | (wait-for-unix-socket "/var/run/miniflux/miniflux.sock" marionette)) | ||
| 1022 | |||
| 1023 | (test-end)))) | ||
| 1024 | (gexp->derivation (string-append name "-test") test)) | ||
| 1025 | |||
| 1026 | (define %test-miniflux-admin-string | ||
| 1027 | (system-test | ||
| 1028 | (name "miniflux-admin-string") | ||
| 1029 | (description "Run Miniflux with initial admin credentials as string.") | ||
| 1030 | (value (run-miniflux-test name %miniflux-with-admin-as-string)))) | ||
| 1031 | |||
| 1032 | (define %test-miniflux-admin-file | ||
| 1033 | (system-test | ||
| 1034 | (name "miniflux-admin-file") | ||
| 1035 | (description "Run Miniflux with initial admin credentials as file.") | ||
| 1036 | (value (run-miniflux-test name %miniflux-with-admin-as-file)))) | ||
| 1037 | |||
| 1038 | (define %test-miniflux-socket | ||
| 1039 | (system-test | ||
| 1040 | (name "miniflux-socket") | ||
| 1041 | (description "Run Miniflux on unix socket.") | ||
| 1042 | (value (run-miniflux-socket-test name %miniflux-with-socket)))) | ||
