From 3373a5284a728a0cd283349450d480b2bd051a52 Mon Sep 17 00:00:00 2001 From: Ramesh Sencha Date: Thu, 28 Sep 2023 17:28:02 +0530 Subject: [PATCH] (CAT-1483) - Generating expected source list based on inputs --- manifests/source.pp | 9 +++++++-- spec/defines/source_spec.rb | 18 ++++++++++++++++++ templates/source.list.epp | 6 +++--- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/manifests/source.pp b/manifests/source.pp index 2386c0a5f3..dac455fcaf 100644 --- a/manifests/source.pp +++ b/manifests/source.pp @@ -94,6 +94,12 @@ $_release = $release } + if $release =~ Pattern[/\/$/] { + $_components = $_release + } else { + $_components = "${_release} ${repos}" + } + if $ensure == 'present' { if ! $location { fail('cannot create a source entry without specifying a location') @@ -151,8 +157,7 @@ }, ), 'location' => $_location, - 'release' => $_release, - 'repos' => $repos, + 'components' => $_components, } ) diff --git a/spec/defines/source_spec.rb b/spec/defines/source_spec.rb index d9627172be..2db3764a72 100644 --- a/spec/defines/source_spec.rb +++ b/spec/defines/source_spec.rb @@ -427,6 +427,24 @@ it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{hello\.there main}) } end + context 'with release is /' do + let(:params) { { location: 'hello.there', release: '/' } } + + it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{hello\.there /}) } + end + + context 'with release is test/' do + let(:params) { { location: 'hello.there', release: 'test/' } } + + it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{hello\.there test/}) } + end + + context 'with release is test/test1' do + let(:params) { { location: 'hello.there', release: 'test/test' } } + + it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{hello\.there test/test main}) } + end + context 'with invalid pin' do let :params do { diff --git a/templates/source.list.epp b/templates/source.list.epp index 2b8dd6e57d..577f9db0cd 100644 --- a/templates/source.list.epp +++ b/templates/source.list.epp @@ -1,8 +1,8 @@ -<%- | String $comment, Hash $includes, Hash $options, $location, $release, String $repos | -%> +<%- | String $comment, Hash $includes, Hash $options, $location, String $components | -%> # <%= $comment %> <%- if $includes['deb'] { -%> -deb <% if !$options.empty() { -%>[<%= $options.map |$key, $value| { if !$value.empty() { "${key}=${value}" } }.join(" ") %>] <% } -%> <%= $location %> <%= $release %> <%= $repos %> +deb <% if !$options.empty() { -%>[<%= $options.map |$key, $value| { if !$value.empty() { "${key}=${value}" } }.join(" ") %>] <% } -%> <%= $location %> <%= $components %> <%- } -%> <%- if $includes['src'] { -%> -deb-src <% if !$options.empty() { -%>[<%= $options.map |$key, $value| { if !$value.empty() { "${key}=${value}" } }.join(" ") %>] <% } -%> <%= $location %> <%= $release %> <%= $repos %> +deb-src <% if !$options.empty() { -%>[<%= $options.map |$key, $value| { if !$value.empty() { "${key}=${value}" } }.join(" ") %>] <% } -%> <%= $location %> <%= $components %> <%- } -%>