From 45f40456d0019f6a1ae71b2d92eb368b93464b64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 19 Dec 2024 11:43:32 -1000 Subject: [PATCH 1/3] Improve template consistency and make it more concise --- templates/source_deb822.epp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/templates/source_deb822.epp b/templates/source_deb822.epp index 10802b05d5..99cd246903 100644 --- a/templates/source_deb822.epp +++ b/templates/source_deb822.epp @@ -12,12 +12,12 @@ | -%> # <%= $comment %> Enabled: <%= $enabled %> -Types: <% $types.each |String $type| { -%> <%= $type %> <% } %> -URIs: <% $uris.each | String $uri | { -%> <%= $uri %> <% } %> -Suites: <% $suites.each | String $suite | { -%> <%= $suite %> <% } %> -Components: <% $components.each | String $component | { -%> <%= $component %> <% } %> +Types: <%= $types.join(' ') %> +URIs: <%= $uris.join(' ') %> +Suites: <%= $suites.join(' ') %> +Components: <%= $components.join(' ') %> <% if $architectures { -%> -Architectures:<% $architectures.each | String $arch | { %> <%= $arch %><% } %> +Architectures: <%= $architectures.join(' ') %> <%- } -%> <% if $allow_insecure { -%> Allow-Insecure: <%= $allow_insecure %> @@ -29,8 +29,5 @@ Trusted: <%= $repo_trusted %> Check-Valid-Until: <%= $check_valid_until %> <% } -%> <% if $signed_by { -%> -Signed-By: <% if type($signed_by) =~ Type[Array] { -%><%- $signed_by.each |String $keyring| { -%><%= $keyring %> <% } -%> -<%- } -%> -<%- elsif type($signed_by) =~ Type[String] { -%> -<%= $signed_by -%> -<%- }} %> +Signed-By: <%= [$signed_by].flatten.join(' ') %> +<% } -%> From 06f1ef7e6af4eca2193c2c8e0dd202b62add29ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 19 Dec 2024 11:44:56 -1000 Subject: [PATCH 2/3] Fix epp parameter tag While here, further validate provided data. --- templates/source_deb822.epp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/templates/source_deb822.epp b/templates/source_deb822.epp index 99cd246903..248833a706 100644 --- a/templates/source_deb822.epp +++ b/templates/source_deb822.epp @@ -1,14 +1,15 @@ -<% | String $comment, +<%- | + String[1] $comment, Enum['yes','no'] $enabled, - Array[String] $types, - Array[String] $uris, - Array[String] $suites, - Array[String] $components, - Optional[Array] $architectures = undef, + Array[String[1]] $types, + Array[String[1]] $uris, + Array[String[1]] $suites, + Array[String[1]] $components, + Optional[Array[String[1]]] $architectures = undef, Optional[Enum['yes','no']] $allow_insecure = undef, Optional[Enum['yes','no']] $repo_trusted = undef, Optional[Enum['yes','no']] $check_valid_until = undef, - Optional[Variant[Stdlib::AbsolutePath,Array[String]]] $signed_by = undef, + Optional[Variant[Stdlib::AbsolutePath,Array[String[1]]]] $signed_by = undef, | -%> # <%= $comment %> Enabled: <%= $enabled %> From 98215792e8c4bd21eb6b3d605a732bb971687b3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 19 Dec 2024 11:47:58 -1000 Subject: [PATCH 3/3] Improve tests Test the generated content as a whole instead of part of line by part of line, add add missing parameters to improve coverage. --- spec/defines/source_spec.rb | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/spec/defines/source_spec.rb b/spec/defines/source_spec.rb index 9c619439c0..2d5b45f9d6 100644 --- a/spec/defines/source_spec.rb +++ b/spec/defines/source_spec.rb @@ -435,31 +435,51 @@ end it { is_expected.to contain_apt__setting("sources-#{title}").with_notify_update(true) } + it { is_expected.to contain_apt__setting("sources-#{title}").with_content(<<~SOURCE) } + # This file is managed by Puppet. DO NOT EDIT. + # my_source + Enabled: yes + Types: deb + URIs: http://debian.mirror.iweb.ca/debian/ + Suites: stretch + Components: main contrib non-free + SOURCE end context 'complex deb822 source' do let :params do super().merge( { + enabled: false, types: ['deb', 'deb-src'], location: ['http://fr.debian.org/debian', 'http://de.debian.org/debian'], release: ['stable', 'stable-updates', 'stable-backports'], repos: ['main', 'contrib', 'non-free'], architecture: ['amd64', 'i386'], allow_unsigned: true, - notify_update: false + allow_insecure: true, + notify_update: false, + check_valid_until: false, + keyring: '/foo' }, ) end it { is_expected.to contain_apt__setting("sources-#{title}").with_notify_update(false) } - it { is_expected.to contain_apt__setting("sources-#{title}").with_content(%r{Enabled: yes}) } - it { is_expected.to contain_apt__setting("sources-#{title}").with_content(%r{Types: deb deb-src}) } - it { is_expected.to contain_apt__setting("sources-#{title}").with_content(%r{URIs: http://fr.debian.org/debian http://de.debian.org/debian}) } - it { is_expected.to contain_apt__setting("sources-#{title}").with_content(%r{Suites: stable stable-updates stable-backports}) } - it { is_expected.to contain_apt__setting("sources-#{title}").with_content(%r{Components: main contrib non-free}) } - it { is_expected.to contain_apt__setting("sources-#{title}").with_content(%r{Architectures: amd64 i386}) } - it { is_expected.to contain_apt__setting("sources-#{title}").with_content(%r{Trusted: yes}) } + it { is_expected.to contain_apt__setting("sources-#{title}").with_content(<<~SOURCE) } + # This file is managed by Puppet. DO NOT EDIT. + # my_source + Enabled: no + Types: deb deb-src + URIs: http://fr.debian.org/debian http://de.debian.org/debian + Suites: stable stable-updates stable-backports + Components: main contrib non-free + Architectures: amd64 i386 + Allow-Insecure: yes + Trusted: yes + Check-Valid-Until: no + Signed-By: /foo + SOURCE end context '.list backwards compatibility' do