unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob fad28a228c52709db6e9132fe331916de09f707c 6210 bytes (raw)
name: tests/services/docker.scm 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
 
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2023 Giacomo Leidi <goodoldpaul@autistici.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (tests services docker)
  #:use-module (gnu packages docker)
  #:use-module (gnu services docker)
  #:use-module (guix derivations)
  #:use-module (guix gexp)
  #:use-module (guix monads)
  #:use-module (guix packages)
  #:use-module (guix store)
  #:use-module (guix tests)
  #:use-module (ice-9 match)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-64))


;;; Commentary:
;;;
;;; Unit tests for the (gnu services docker) module.
;;;
;;; Code:


;;;
;;; Unit tests for the oci-container-service-type.
;;;


;;; Access some internals for whitebox testing.
(define %store
  (open-connection-for-tests))
(define (gexp->sexp . x)
  (apply (@@ (guix gexp) gexp->sexp) x))
(define* (gexp->sexp* exp #:optional target)
  (run-with-store %store (gexp->sexp exp (%current-system) target)
                  #:guile-for-build (%guile-for-build)))
(define (list->sexp-list* lst)
  (map (lambda (el)
         (if (gexp? el)
             (gexp->sexp* el)
             el))
       lst))
(define oci-sanitize-mixed-list
  (@@ (gnu services docker) oci-sanitize-mixed-list))
(define (oci-container-configuration->options config)
  (list->sexp-list*
   ((@@ (gnu services docker) oci-container-configuration->options) config)))

(test-begin "oci-containers-service")

(test-group "oci-sanitize-mixed-list"
  (define delimiter "=")
  (define file-like-key
    (plain-file "oci-tests-file-like-key" "some-content"))
  (define mixed-list
    `("any kind of string"
      ("KEY" . "VALUE")
      (,#~(string-append "COMPUTED" "_KEY") . "VALUE")
      (,file-like-key . "VALUE")))

  (test-assertm "successfully lower mixed values"
    (mlet* %store-monad ((ml ->             (oci-sanitize-mixed-list "field-name" mixed-list delimiter))
                         (actual ->         (list->sexp-list* ml))
                         (file-like-item    (lower-object file-like-key))
                         (expected ->       `("any kind of string"
                                              (string-append "KEY" "=" "VALUE")
                                              (string-append (string-append "COMPUTED" "_KEY") "=" "VALUE")
                                              (string-append ,file-like-item "=" "VALUE"))))
      (mbegin %store-monad
        (return
         (every (lambda (pair)
                  (apply (if (string? (first pair))
                             string=?
                             equal?)
                         pair))
                (zip expected actual))))))

  (test-error
   "illegal list values" #t
   (oci-sanitize-mixed-list "field-name" '(("KEY" . "VALUE") #f) delimiter))

  (test-error
   "illegal pair member values" #t
   (oci-sanitize-mixed-list "field-name" '(("KEY" . 1)) delimiter)))

(test-group "oci-container-configuration->options"
  (define config
    (oci-container-configuration
     (image "guix/guix:latest")))

  (test-equal "entrypoint"
    (list "--entrypoint" "entrypoint")
    (oci-container-configuration->options
     (oci-container-configuration
      (inherit config)
      (entrypoint "entrypoint"))))

  (test-equal "environment"
    (list "--env" '(string-append "key" "=" "value")
          "--env" '(string-append "environment" "=" "variable"))
    (oci-container-configuration->options
     (oci-container-configuration
      (inherit config)
      (environment
       '(("key" . "value")
         ("environment" . "variable"))))))

  (test-equal "network"
    (list "--network" "host")
    (oci-container-configuration->options
     (oci-container-configuration
      (inherit config)
      (network "host"))))

  (test-equal "container-user"
    (list "--user" "service-account")
    (oci-container-configuration->options
     (oci-container-configuration
      (inherit config)
      (container-user "service-account"))))

  (test-equal "workdir"
    (list "--workdir" "/srv/http")
    (oci-container-configuration->options
     (oci-container-configuration
      (inherit config)
      (workdir "/srv/http"))))

  (test-equal "ports"
    (list "-p" '(string-append "10443" ":" "443")
          "-p" '(string-append "9022" ":" "22"))
    (oci-container-configuration->options
     (oci-container-configuration
      (inherit config)
      (ports
       '(("10443" . "443")
         ("9022" . "22"))))))

  (test-equal "volumes"
    (list "-v" '(string-append "/gnu/store" ":" "/gnu/store")
          "-v" '(string-append "/var/lib/guix" ":" "/var/lib/guix"))
    (oci-container-configuration->options
     (oci-container-configuration
      (inherit config)
      (volumes
       '(("/gnu/store" . "/gnu/store")
         ("/var/lib/guix" . "/var/lib/guix"))))))

  (test-equal "complete configuration"
    (list "--entrypoint" "entrypoint"
          "--env" '(string-append "key" "=" "value")
          "--network" "host"
          "--user" "service-account"
          "--workdir" "/srv/http"
          "-p" '(string-append "10443" ":" "443")
          "-v" '(string-append "/gnu/store" ":" "/gnu/store"))
    (oci-container-configuration->options
     (oci-container-configuration
      (inherit config)
      (entrypoint "entrypoint")
      (environment
       '(("key" . "value")))
      (network "host")
      (container-user "service-account")
      (workdir "/srv/http")
      (ports
       '(("10443" . "443")))
      (volumes
       '(("/gnu/store" . "/gnu/store")))))))

(test-end "oci-containers-service")

debug log:

solving fad28a228c ...
found fad28a228c in https://yhetil.org/guix-patches/20231203215630.28144-1-goodoldpaul@autistici.org/

applying [1/1] https://yhetil.org/guix-patches/20231203215630.28144-1-goodoldpaul@autistici.org/
diff --git a/tests/services/docker.scm b/tests/services/docker.scm
new file mode 100644
index 0000000000..fad28a228c

Checking patch tests/services/docker.scm...
Applied patch tests/services/docker.scm cleanly.

index at:
100644 fad28a228c52709db6e9132fe331916de09f707c	tests/services/docker.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).