diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2017-07-18 10:41:51 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2017-07-20 11:57:13 +0200 |
| commit | 8b113790fa3bfd2300c737901ba161f079fedbdf (patch) | |
| tree | 72b7aa4fa9be2a6c129b97b04a11cfbe0d298a79 /gnu/tests/mail.scm | |
| parent | ed419fa0c56e6ff3aa8bd8e8f100a81442c51e6d (diff) | |
tests: Use 'virtual-machine' records instead of monadic procedures.
* gnu/tests/base.scm (%test-basic-os): Use 'let*' instead of 'mlet*' and
'virtual-machine' instead of 'system-qemu-image/shared-store-script'.
(run-mcron-test): Likewise.
(run-nss-mdns-test): Likewise.
* gnu/tests/dict.scm (run-dicod-test): Likewise.
* gnu/tests/mail.scm (run-opensmtpd-test): Likewise.
(run-exim-test): Likewise.
* gnu/tests/messaging.scm (run-xmpp-test): Likewise.
* gnu/tests/networking.scm (run-inetd-test): Likewise.
* gnu/tests/nfs.scm (run-nfs-test): Likewise.
* gnu/tests/ssh.scm (run-ssh-test): Likewise.
* gnu/tests/web.scm (run-nginx-test): Likewise.
Diffstat (limited to 'gnu/tests/mail.scm')
| -rw-r--r-- | gnu/tests/mail.scm | 388 |
1 files changed, 194 insertions, 194 deletions
diff --git a/gnu/tests/mail.scm b/gnu/tests/mail.scm index 247f4f667f1..312df9b1cd3 100644 --- a/gnu/tests/mail.scm +++ b/gnu/tests/mail.scm | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2016 Sou Bunnbu <iyzsong@member.fsf.org> | 2 | ;;; Copyright © 2016 Sou Bunnbu <iyzsong@member.fsf.org> |
| 3 | ;;; Copyright © 2017 Carlo Zancanaro <carlo@zancanaro.id.au> | 3 | ;;; Copyright © 2017 Carlo Zancanaro <carlo@zancanaro.id.au> |
| 4 | ;;; Copyright © 2017 Ludovic Courtès <ludo@gnu.org> | ||
| 4 | ;;; | 5 | ;;; |
| 5 | ;;; This file is part of GNU Guix. | 6 | ;;; This file is part of GNU Guix. |
| 6 | ;;; | 7 | ;;; |
| @@ -25,7 +26,6 @@ | |||
| 25 | #:use-module (gnu services mail) | 26 | #:use-module (gnu services mail) |
| 26 | #:use-module (gnu services networking) | 27 | #:use-module (gnu services networking) |
| 27 | #:use-module (guix gexp) | 28 | #:use-module (guix gexp) |
| 28 | #:use-module (guix monads) | ||
| 29 | #:use-module (guix store) | 29 | #:use-module (guix store) |
| 30 | #:use-module (ice-9 ftw) | 30 | #:use-module (ice-9 ftw) |
| 31 | #:export (%test-opensmtpd | 31 | #:export (%test-opensmtpd |
| @@ -44,105 +44,105 @@ accept from any for local deliver to mbox | |||
| 44 | 44 | ||
| 45 | (define (run-opensmtpd-test) | 45 | (define (run-opensmtpd-test) |
| 46 | "Return a test of an OS running OpenSMTPD service." | 46 | "Return a test of an OS running OpenSMTPD service." |
| 47 | (mlet* %store-monad ((command (system-qemu-image/shared-store-script | 47 | (define vm |
| 48 | (marionette-operating-system | 48 | (virtual-machine |
| 49 | %opensmtpd-os | 49 | (operating-system (marionette-operating-system |
| 50 | #:imported-modules '((gnu services herd))) | 50 | %opensmtpd-os |
| 51 | #:graphic? #f))) | 51 | #:imported-modules '((gnu services herd)))) |
| 52 | (define test | 52 | (port-forwardings '((1025 . 25))))) |
| 53 | (with-imported-modules '((gnu build marionette)) | 53 | |
| 54 | #~(begin | 54 | (define test |
| 55 | (use-modules (rnrs base) | 55 | (with-imported-modules '((gnu build marionette)) |
| 56 | (srfi srfi-64) | 56 | #~(begin |
| 57 | (ice-9 rdelim) | 57 | (use-modules (rnrs base) |
| 58 | (ice-9 regex) | 58 | (srfi srfi-64) |
| 59 | (gnu build marionette)) | 59 | (ice-9 rdelim) |
| 60 | 60 | (ice-9 regex) | |
| 61 | (define marionette | 61 | (gnu build marionette)) |
| 62 | (make-marionette | 62 | |
| 63 | ;; Enable TCP forwarding of the guest's port 25. | 63 | (define marionette |
| 64 | '(#$command "-net" "user,hostfwd=tcp::1025-:25"))) | 64 | (make-marionette '(#$vm))) |
| 65 | 65 | ||
| 66 | (define (read-reply-code port) | 66 | (define (read-reply-code port) |
| 67 | "Read a SMTP reply from PORT and return its reply code." | 67 | "Read a SMTP reply from PORT and return its reply code." |
| 68 | (let* ((line (read-line port)) | 68 | (let* ((line (read-line port)) |
| 69 | (mo (string-match "([0-9]+)([ -]).*" line)) | 69 | (mo (string-match "([0-9]+)([ -]).*" line)) |
| 70 | (code (string->number (match:substring mo 1))) | 70 | (code (string->number (match:substring mo 1))) |
| 71 | (finished? (string= " " (match:substring mo 2)))) | 71 | (finished? (string= " " (match:substring mo 2)))) |
| 72 | (if finished? | 72 | (if finished? |
| 73 | code | 73 | code |
| 74 | (read-reply-code port)))) | 74 | (read-reply-code port)))) |
| 75 | 75 | ||
| 76 | (mkdir #$output) | 76 | (mkdir #$output) |
| 77 | (chdir #$output) | 77 | (chdir #$output) |
| 78 | 78 | ||
| 79 | (test-begin "opensmptd") | 79 | (test-begin "opensmptd") |
| 80 | 80 | ||
| 81 | (test-assert "service is running" | 81 | (test-assert "service is running" |
| 82 | (marionette-eval | 82 | (marionette-eval |
| 83 | '(begin | 83 | '(begin |
| 84 | (use-modules (gnu services herd)) | 84 | (use-modules (gnu services herd)) |
| 85 | (start-service 'smtpd) | 85 | (start-service 'smtpd) |
| 86 | #t) | 86 | #t) |
| 87 | marionette)) | 87 | marionette)) |
| 88 | 88 | ||
| 89 | (test-assert "mbox is empty" | 89 | (test-assert "mbox is empty" |
| 90 | (marionette-eval | 90 | (marionette-eval |
| 91 | '(and (file-exists? "/var/mail") | 91 | '(and (file-exists? "/var/mail") |
| 92 | (not (file-exists? "/var/mail/root"))) | 92 | (not (file-exists? "/var/mail/root"))) |
| 93 | marionette)) | 93 | marionette)) |
| 94 | 94 | ||
| 95 | (test-eq "accept an email" | 95 | (test-eq "accept an email" |
| 96 | #t | 96 | #t |
| 97 | (let* ((smtp (socket AF_INET SOCK_STREAM 0)) | 97 | (let* ((smtp (socket AF_INET SOCK_STREAM 0)) |
| 98 | (addr (make-socket-address AF_INET INADDR_LOOPBACK 1025))) | 98 | (addr (make-socket-address AF_INET INADDR_LOOPBACK 1025))) |
| 99 | (connect smtp addr) | 99 | (connect smtp addr) |
| 100 | ;; Be greeted. | 100 | ;; Be greeted. |
| 101 | (read-reply-code smtp) ;220 | 101 | (read-reply-code smtp) ;220 |
| 102 | ;; Greet the server. | 102 | ;; Greet the server. |
| 103 | (write-line "EHLO somehost" smtp) | 103 | (write-line "EHLO somehost" smtp) |
| 104 | (read-reply-code smtp) ;250 | 104 | (read-reply-code smtp) ;250 |
| 105 | ;; Set sender email. | 105 | ;; Set sender email. |
| 106 | (write-line "MAIL FROM: <someone>" smtp) | 106 | (write-line "MAIL FROM: <someone>" smtp) |
| 107 | (read-reply-code smtp) ;250 | 107 | (read-reply-code smtp) ;250 |
| 108 | ;; Set recipient email. | 108 | ;; Set recipient email. |
| 109 | (write-line "RCPT TO: <root>" smtp) | 109 | (write-line "RCPT TO: <root>" smtp) |
| 110 | (read-reply-code smtp) ;250 | 110 | (read-reply-code smtp) ;250 |
| 111 | ;; Send message. | 111 | ;; Send message. |
| 112 | (write-line "DATA" smtp) | 112 | (write-line "DATA" smtp) |
| 113 | (read-reply-code smtp) ;354 | 113 | (read-reply-code smtp) ;354 |
| 114 | (write-line "Subject: Hello" smtp) | 114 | (write-line "Subject: Hello" smtp) |
| 115 | (newline smtp) | 115 | (newline smtp) |
| 116 | (write-line "Nice to meet you!" smtp) | 116 | (write-line "Nice to meet you!" smtp) |
| 117 | (write-line "." smtp) | 117 | (write-line "." smtp) |
| 118 | (read-reply-code smtp) ;250 | 118 | (read-reply-code smtp) ;250 |
| 119 | ;; Say goodbye. | 119 | ;; Say goodbye. |
| 120 | (write-line "QUIT" smtp) | 120 | (write-line "QUIT" smtp) |
| 121 | (read-reply-code smtp) ;221 | 121 | (read-reply-code smtp) ;221 |
| 122 | (close smtp) | 122 | (close smtp) |
| 123 | #t)) | 123 | #t)) |
| 124 | 124 | ||
| 125 | (test-assert "mail arrived" | 125 | (test-assert "mail arrived" |
| 126 | (marionette-eval | 126 | (marionette-eval |
| 127 | '(begin | 127 | '(begin |
| 128 | (use-modules (ice-9 popen) | 128 | (use-modules (ice-9 popen) |
| 129 | (ice-9 rdelim)) | 129 | (ice-9 rdelim)) |
| 130 | 130 | ||
| 131 | (define (queue-empty?) | 131 | (define (queue-empty?) |
| 132 | (eof-object? | 132 | (eof-object? |
| 133 | (read-line | 133 | (read-line |
| 134 | (open-input-pipe "smtpctl show queue")))) | 134 | (open-input-pipe "smtpctl show queue")))) |
| 135 | 135 | ||
| 136 | (let wait () | 136 | (let wait () |
| 137 | (if (queue-empty?) | 137 | (if (queue-empty?) |
| 138 | (file-exists? "/var/mail/root") | 138 | (file-exists? "/var/mail/root") |
| 139 | (begin (sleep 1) (wait))))) | 139 | (begin (sleep 1) (wait))))) |
| 140 | marionette)) | 140 | marionette)) |
| 141 | 141 | ||
| 142 | (test-end) | 142 | (test-end) |
| 143 | (exit (= (test-runner-fail-count (test-runner-current)) 0))))) | 143 | (exit (= (test-runner-fail-count (test-runner-current)) 0))))) |
| 144 | 144 | ||
| 145 | (gexp->derivation "opensmtpd-test" test))) | 145 | (gexp->derivation "opensmtpd-test" test)) |
| 146 | 146 | ||
| 147 | (define %test-opensmtpd | 147 | (define %test-opensmtpd |
| 148 | (system-test | 148 | (system-test |
| @@ -179,100 +179,100 @@ acl_check_data: | |||
| 179 | 179 | ||
| 180 | (define (run-exim-test) | 180 | (define (run-exim-test) |
| 181 | "Return a test of an OS running an Exim service." | 181 | "Return a test of an OS running an Exim service." |
| 182 | (mlet* %store-monad ((command (system-qemu-image/shared-store-script | 182 | (define vm |
| 183 | (marionette-operating-system | 183 | (virtual-machine |
| 184 | %exim-os | 184 | (operating-system (marionette-operating-system |
| 185 | #:imported-modules '((gnu services herd))) | 185 | %exim-os |
| 186 | #:graphic? #f))) | 186 | #:imported-modules '((gnu services herd)))) |
| 187 | (define test | 187 | (port-forwardings '((1025 . 25))))) |
| 188 | (with-imported-modules '((gnu build marionette) | 188 | |
| 189 | (ice-9 ftw)) | 189 | (define test |
| 190 | #~(begin | 190 | (with-imported-modules '((gnu build marionette) |
| 191 | (use-modules (rnrs base) | 191 | (ice-9 ftw)) |
| 192 | (srfi srfi-64) | 192 | #~(begin |
| 193 | (ice-9 ftw) | 193 | (use-modules (rnrs base) |
| 194 | (ice-9 rdelim) | 194 | (srfi srfi-64) |
| 195 | (ice-9 regex) | 195 | (ice-9 ftw) |
| 196 | (gnu build marionette)) | 196 | (ice-9 rdelim) |
| 197 | 197 | (ice-9 regex) | |
| 198 | (define marionette | 198 | (gnu build marionette)) |
| 199 | (make-marionette | 199 | |
| 200 | ;; Enable TCP forwarding of the guest's port 25. | 200 | (define marionette |
| 201 | '(#$command "-net" "user,hostfwd=tcp::1025-:25"))) | 201 | (make-marionette '(#$vm))) |
| 202 | 202 | ||
| 203 | (define (read-reply-code port) | 203 | (define (read-reply-code port) |
| 204 | "Read a SMTP reply from PORT and return its reply code." | 204 | "Read a SMTP reply from PORT and return its reply code." |
| 205 | (let* ((line (read-line port)) | 205 | (let* ((line (read-line port)) |
| 206 | (mo (string-match "([0-9]+)([ -]).*" line)) | 206 | (mo (string-match "([0-9]+)([ -]).*" line)) |
| 207 | (code (string->number (match:substring mo 1))) | 207 | (code (string->number (match:substring mo 1))) |
| 208 | (finished? (string= " " (match:substring mo 2)))) | 208 | (finished? (string= " " (match:substring mo 2)))) |
| 209 | (if finished? | 209 | (if finished? |
| 210 | code | 210 | code |
| 211 | (read-reply-code port)))) | 211 | (read-reply-code port)))) |
| 212 | 212 | ||
| 213 | (define smtp (socket AF_INET SOCK_STREAM 0)) | 213 | (define smtp (socket AF_INET SOCK_STREAM 0)) |
| 214 | (define addr (make-socket-address AF_INET INADDR_LOOPBACK 1025)) | 214 | (define addr (make-socket-address AF_INET INADDR_LOOPBACK 1025)) |
| 215 | 215 | ||
| 216 | (mkdir #$output) | 216 | (mkdir #$output) |
| 217 | (chdir #$output) | 217 | (chdir #$output) |
| 218 | 218 | ||
| 219 | (test-begin "exim") | 219 | (test-begin "exim") |
| 220 | 220 | ||
| 221 | (test-assert "service is running" | 221 | (test-assert "service is running" |
| 222 | (marionette-eval | 222 | (marionette-eval |
| 223 | '(begin | 223 | '(begin |
| 224 | (use-modules (gnu services herd)) | 224 | (use-modules (gnu services herd)) |
| 225 | (start-service 'exim) | 225 | (start-service 'exim) |
| 226 | #t) | 226 | #t) |
| 227 | marionette)) | 227 | marionette)) |
| 228 | 228 | ||
| 229 | (sleep 1) ;; give the service time to start talking | 229 | (sleep 1) ;; give the service time to start talking |
| 230 | 230 | ||
| 231 | (connect smtp addr) | 231 | (connect smtp addr) |
| 232 | ;; Be greeted. | 232 | ;; Be greeted. |
| 233 | (test-eq "greeting received" | 233 | (test-eq "greeting received" |
| 234 | 220 (read-reply-code smtp)) | 234 | 220 (read-reply-code smtp)) |
| 235 | ;; Greet the server. | 235 | ;; Greet the server. |
| 236 | (write-line "EHLO somehost" smtp) | 236 | (write-line "EHLO somehost" smtp) |
| 237 | (test-eq "greeting successful" | 237 | (test-eq "greeting successful" |
| 238 | 250 (read-reply-code smtp)) | 238 | 250 (read-reply-code smtp)) |
| 239 | ;; Set sender email. | 239 | ;; Set sender email. |
| 240 | (write-line "MAIL FROM: test@example.com" smtp) | 240 | (write-line "MAIL FROM: test@example.com" smtp) |
| 241 | (test-eq "sender set" | 241 | (test-eq "sender set" |
| 242 | 250 (read-reply-code smtp)) ;250 | 242 | 250 (read-reply-code smtp)) ;250 |
| 243 | ;; Set recipient email. | 243 | ;; Set recipient email. |
| 244 | (write-line "RCPT TO: root@komputilo" smtp) | 244 | (write-line "RCPT TO: root@komputilo" smtp) |
| 245 | (test-eq "recipient set" | 245 | (test-eq "recipient set" |
| 246 | 250 (read-reply-code smtp)) ;250 | 246 | 250 (read-reply-code smtp)) ;250 |
| 247 | ;; Send message. | 247 | ;; Send message. |
| 248 | (write-line "DATA" smtp) | 248 | (write-line "DATA" smtp) |
| 249 | (test-eq "data begun" | 249 | (test-eq "data begun" |
| 250 | 354 (read-reply-code smtp)) ;354 | 250 | 354 (read-reply-code smtp)) ;354 |
| 251 | (write-line "Subject: Hello" smtp) | 251 | (write-line "Subject: Hello" smtp) |
| 252 | (newline smtp) | 252 | (newline smtp) |
| 253 | (write-line "Nice to meet you!" smtp) | 253 | (write-line "Nice to meet you!" smtp) |
| 254 | (write-line "." smtp) | 254 | (write-line "." smtp) |
| 255 | (test-eq "message sent" | 255 | (test-eq "message sent" |
| 256 | 250 (read-reply-code smtp)) ;250 | 256 | 250 (read-reply-code smtp)) ;250 |
| 257 | ;; Say goodbye. | 257 | ;; Say goodbye. |
| 258 | (write-line "QUIT" smtp) | 258 | (write-line "QUIT" smtp) |
| 259 | (test-eq "quit successful" | 259 | (test-eq "quit successful" |
| 260 | 221 (read-reply-code smtp)) ;221 | 260 | 221 (read-reply-code smtp)) ;221 |
| 261 | (close smtp) | 261 | (close smtp) |
| 262 | 262 | ||
| 263 | (test-eq "the email is received" | 263 | (test-eq "the email is received" |
| 264 | 1 | 264 | 1 |
| 265 | (marionette-eval | 265 | (marionette-eval |
| 266 | '(begin | 266 | '(begin |
| 267 | (use-modules (ice-9 ftw)) | 267 | (use-modules (ice-9 ftw)) |
| 268 | (length (scandir "/var/spool/exim/msglog" | 268 | (length (scandir "/var/spool/exim/msglog" |
| 269 | (lambda (x) (not (string-prefix? "." x)))))) | 269 | (lambda (x) (not (string-prefix? "." x)))))) |
| 270 | marionette)) | 270 | marionette)) |
| 271 | 271 | ||
| 272 | (test-end) | 272 | (test-end) |
| 273 | (exit (= (test-runner-fail-count (test-runner-current)) 0))))) | 273 | (exit (= (test-runner-fail-count (test-runner-current)) 0))))) |
| 274 | 274 | ||
| 275 | (gexp->derivation "exim-test" test))) | 275 | (gexp->derivation "exim-test" test)) |
| 276 | 276 | ||
| 277 | (define %test-exim | 277 | (define %test-exim |
| 278 | (system-test | 278 | (system-test |
