projects/guix·blob python-team · refs

85 lines · 2.9 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2023 Maxim Cournoyer <[email protected]>
3;;;
4;;; This file is part of GNU Guix.
5;;;
6;;; GNU Guix is free software; you can redistribute it and/or modify it
7;;; under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 3 of the License, or (at
9;;; your option) any later version.
10;;;
11;;; GNU Guix is distributed in the hope that it will be useful, but
12;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19;;; Commentary:
20;;;
21;;; Unit tests for the (gnu services vpn) module.
22;;;
23;;; Code:
24
25(define-module (tests services vpn)
26 #:use-module (gnu packages vpn)
27 #:use-module (gnu services vpn)
28 #:use-module (guix gexp)
29 #:use-module (ice-9 match)
30 #:use-module (srfi srfi-1)
31 #:use-module (srfi srfi-64))
32
33;;; Access some internals for whitebox testing.
34(define ipv4-address? (@@ (gnu services vpn) ipv4-address?))
35(define ipv6-address? (@@ (gnu services vpn) ipv6-address?))
36(define host-name? (@@ (gnu services vpn) host-name?))
37(define endpoint-host-names
38 (@@ (gnu services vpn) endpoint-host-names))
39
40(test-begin "vpn-services")
41
42(test-assert "ipv4-address?"
43 (every ipv4-address?
44 (list "192.95.5.67:1234"
45 "10.0.0.1")))
46
47(test-assert "ipv6-address?"
48 (every ipv6-address?
49 (list "[2001:db8::c05f:543]:2468"
50 "2001:db8::c05f:543"
51 "2001:db8:855b:0000:0000:0567:5673:23b5"
52 "2001:db8:855b::0567:5673:23b5")))
53
54(define %wireguard-peers
55 (list (wireguard-peer
56 (name "dummy1")
57 (public-key "VlesLiEB5BFd//OD2ILKXviolfz+hodG6uZ+XjoalC8=")
58 (endpoint "some.dynamic-dns.service:53281")
59 (allowed-ips '()))
60 (wireguard-peer
61 (name "dummy2")
62 (public-key "AlesLiEB5BFd//OD2ILKXviolfz+hodG6uZ+XgoalC9=")
63 (endpoint "example.org")
64 (allowed-ips '()))
65 (wireguard-peer
66 (name "dummy3")
67 (public-key "BlesLiEB5BFd//OD2ILKXviolfz+hodG6uZ+XgoalC7=")
68 (endpoint "10.0.0.7:7777")
69 (allowed-ips '()))
70 (wireguard-peer
71 (name "dummy4")
72 (public-key "ClesLiEB5BFd//OD2ILKXviolfz+hodG6uZ+XgoalC6=")
73 (endpoint "[2345:0425:2CA1::0567:5673:23b5]:44444")
74 (allowed-ips '()))))
75
76(test-equal "endpoint-host-names"
77 ;; The first element of the pair the public Wireguard key associated to a
78 ;; host name.
79 '(("VlesLiEB5BFd//OD2ILKXviolfz+hodG6uZ+XjoalC8=" .
80 "some.dynamic-dns.service:53281")
81 ("AlesLiEB5BFd//OD2ILKXviolfz+hodG6uZ+XgoalC9=" .
82 "example.org"))
83 (endpoint-host-names %wireguard-peers))
84
85(test-end "vpn-services")