From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id mKJ3DLT5bGV2LwEAG6o9tA:P1 (envelope-from ) for ; Sun, 03 Dec 2023 22:57:08 +0100 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id mKJ3DLT5bGV2LwEAG6o9tA (envelope-from ) for ; Sun, 03 Dec 2023 22:57:08 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A30F55B630 for ; Sun, 3 Dec 2023 22:57:07 +0100 (CET) Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=autistici.org header.s=stigmate header.b=C+OW7s7w; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1701640628; a=rsa-sha256; cv=none; b=XWTT3GFetyl1cIVoomv3/lT42fqYVhqUdJIky3d7Nq+XEQtLKD2EqEOfrXmVQnuuoa6IPe wjp+Lj+wldXBDu6gQrkcN6fMxEWIEfZvgMp0OMLjy6w/6e19KlNPL3j8c4p6d0JyUcISh/ 7oKLTe4OiwjGn2Pn4sYwEABLvkHeP34hi5yjjohZKoxvp5XjWPD1u6QMj/Ox5ExKvZ8RZ5 Lfkd9ZYu4RTNi5yxPAwXU+TwU7PEyGeGY7QD7kNBCA3ONNd6bBbzQblg+h4tUetbBOij44 k4BOMGh1pYE7NqW2t3OT+aKzZF8D6+lo6NXDAIGVcglhXabN9OTJiPM1P0OpLQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=autistici.org header.s=stigmate header.b=C+OW7s7w; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1701640628; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=+c+LP5Pl+Jam/PArkvV5F/+9iVUrD5pHIyKiEYyu8dg=; b=hChgMQL80hob8bOp6vhMQtF3qOosrgQi94Cvyd+TMsTl5C3PBp4RFo4PPzlBo/rhmiU6kc FbCQ4Qss5qkUsg5LX2EkS8FILX1+cWFIUXWTddUlBW6N/RDneDCzp9CMszju33MwuZYe8n 0omHHd3C4i8lT9opanTYOb0CyYuCW/TfONh/tJxl+AeVeZUp4gDurvu83ryPc1Px2VHkGO eJeeA6MKkmYx4cYGBRKfXvSNLI8rOe+GqL8E227fzUYXtYLCg+Gqyxkj7C87pWZzh3ZfGq Ew91/soaZ/f3C2xc13ot+snYfvBMh4MTUomvEhxc+cfSpiBxhSF1Hr9xbhrELw== Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9uSL-0005di-Mc; Sun, 03 Dec 2023 16:56:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r9uSJ-0005TX-Sc for guix-patches@gnu.org; Sun, 03 Dec 2023 16:56:51 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9uSJ-0001Eo-J8 for guix-patches@gnu.org; Sun, 03 Dec 2023 16:56:51 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r9uST-0000YW-Mr for guix-patches@gnu.org; Sun, 03 Dec 2023 16:57:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#67613] [PATCH] tests: Add oci-container-service-type unit tests. References: <10a8cae4-a5a2-a2e0-fa64-95650ae2e703@autistici.org> In-Reply-To: <10a8cae4-a5a2-a2e0-fa64-95650ae2e703@autistici.org> Resent-From: Giacomo Leidi Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 03 Dec 2023 21:57:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67613 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 67613@debbugs.gnu.org Cc: Giacomo Leidi Received: via spool by 67613-submit@debbugs.gnu.org id=B67613.17016406142123 (code B ref 67613); Sun, 03 Dec 2023 21:57:01 +0000 Received: (at 67613) by debbugs.gnu.org; 3 Dec 2023 21:56:54 +0000 Received: from localhost ([127.0.0.1]:32903 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r9uSL-0000YA-Lz for submit@debbugs.gnu.org; Sun, 03 Dec 2023 16:56:54 -0500 Received: from confino.investici.org ([93.190.126.19]:39489) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r9uSJ-0000Xz-PO for 67613@debbugs.gnu.org; Sun, 03 Dec 2023 16:56:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1701640600; bh=+c+LP5Pl+Jam/PArkvV5F/+9iVUrD5pHIyKiEYyu8dg=; h=From:To:Cc:Subject:Date:From; b=C+OW7s7wRgtpPmFJp6wGxNSZJ2haTRYCvEssSuwpJvd41bQEKfEN74oknHnIV5yr9 LTzD+mOEQ7Sg5BYV6Vzx0T7NEFcil6fmeL/Wgv9WmsEvoQmFP0u2cjFgaMwNHgrd90 Q3myBD5WP1kDfwimAGVEMzpJPc5XfdnliRZ9a8f0= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4Sk0xh2MrCz11Cc; Sun, 3 Dec 2023 21:56:40 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@autistici.org) by localhost (Postfix) with ESMTPSA id 4Sk0xh13fdz11CX; Sun, 3 Dec 2023 21:56:40 +0000 (UTC) Date: Sun, 3 Dec 2023 22:56:28 +0100 Message-ID: <20231203215630.28144-1-goodoldpaul@autistici.org> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Giacomo Leidi X-ACL-Warn: , Giacomo Leidi via Guix-patches From: Giacomo Leidi via Guix-patches via Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: -6.74 X-Spam-Score: -6.74 X-Migadu-Queue-Id: A30F55B630 X-TUID: h52tH+kZ5vze This patch is a followup to issue #66160 and issue #67574. It introduces unit tests for the oci-container-service-type. 8 out 11 tests depend on issue #67574 being merged since issue #66160 was merged with a blocking bug from the beginning. * gnu/services/docker.scm: Export oci-container-configuration-container-user and oci-container-configuration-workdir. * tests/services/docker.scm: New file. * Makefile.am (SCM_TESTS): Register it. Change-Id: I47ed0fe36060ba84dd50b548a66f36e3df8a3710 --- Makefile.am | 1 + gnu/services/docker.scm | 2 + tests/services/docker.scm | 187 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 190 insertions(+) create mode 100644 tests/services/docker.scm diff --git a/Makefile.am b/Makefile.am index cbc3191dfc..91f7a77a94 100644 --- a/Makefile.am +++ b/Makefile.am @@ -564,6 +564,7 @@ SCM_TESTS = \ tests/services.scm \ tests/services/file-sharing.scm \ tests/services/configuration.scm \ + tests/services/docker.scm \ tests/services/lightdm.scm \ tests/services/linux.scm \ tests/services/pam-mount.scm \ diff --git a/gnu/services/docker.scm b/gnu/services/docker.scm index ebea0a473a..263cb41df3 100644 --- a/gnu/services/docker.scm +++ b/gnu/services/docker.scm @@ -58,6 +58,8 @@ (define-module (gnu services docker) oci-container-configuration-network oci-container-configuration-ports oci-container-configuration-volumes + oci-container-configuration-container-user + oci-container-configuration-workdir oci-container-service-type oci-container-shepherd-service)) diff --git a/tests/services/docker.scm b/tests/services/docker.scm new file mode 100644 index 0000000000..fad28a228c --- /dev/null +++ b/tests/services/docker.scm @@ -0,0 +1,187 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2023 Giacomo Leidi +;;; +;;; 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 . + +(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") base-commit: 2c9ac9ab20c76abe570ff83f8746fa089fea3047 -- 2.41.0