From 9fa59e0aa16d01938882b9ef1e5e568c7201b79b Mon Sep 17 00:00:00 2001 From: Martin Alfke Date: Thu, 21 Nov 2024 14:21:12 +0100 Subject: [PATCH] Updates on config and spec (#98) * Updates on config and spec - on docker we must ensure that both paths are mounted (puppet_dir and puppet_code_dir) - add more spec tests * Fix rubocop * add spec test for image_tag --- manifests/docker.pp | 1 + spec/classes/hdm_docker_spec.rb | 43 ++++++++++++++++++++++++++------- spec/classes/hdm_rvm_spec.rb | 20 +++++++++++++++ 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/manifests/docker.pp b/manifests/docker.pp index f89b490..4c13160 100644 --- a/manifests/docker.pp +++ b/manifests/docker.pp @@ -67,6 +67,7 @@ volumes => [ "${hdm::hdm_path}:${hdm::hdm_path}", "${hdm::puppet_dir}:${hdm::puppet_dir}:ro", + "${hdm::puppet_code_dir}:${hdm::puppet_code_dir}:ro", "${hdm::hdm_path}/hdm.yml:/hdm/config/hdm.yml:ro", "${hdm::hdm_path}/database.yml:/hdm/config/database.yml:ro", ], diff --git a/spec/classes/hdm_docker_spec.rb b/spec/classes/hdm_docker_spec.rb index 0e7d7ff..d65b896 100644 --- a/spec/classes/hdm_docker_spec.rb +++ b/spec/classes/hdm_docker_spec.rb @@ -4,27 +4,52 @@ describe 'hdm' do on_supported_os.each do |os, os_facts| + let(:pre_condition) do + if facts[:os]['family'] == 'Suse' + ' + class { "docker": + acknowledge_unsupported_os => true, + } + ' + end + end + context "on #{os} using docker" do let(:facts) { os_facts } let(:params) do { 'method' => 'docker', - 'version' => '1.0.1', + 'version' => '3.0.0', } end - let(:pre_condition) do - if facts[:os]['family'] == 'Suse' - ' - class { "docker": - acknowledge_unsupported_os => true, - } - ' - end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('hdm::docker') } + it { is_expected.to contain_class('docker') } + it { is_expected.to contain_docker__image('ghcr.io/betadots/hdm').with('image_tag' => '3.0.0') } + it { is_expected.to contain_file('/etc/hdm') } + it { is_expected.to contain_file('/etc/hdm/certs') } + it { is_expected.to contain_file('/etc/hdm/db') } + it { is_expected.to contain_file('/etc/hdm/db/production.sqlite3') } + it { is_expected.to contain_file('/etc/hdm/database.yml') } + it { is_expected.to contain_file('/etc/hdm/hdm.yml').with('content' => %r{hiera_config_file: "hiera.yaml"}) } + end + + context "on #{os} using docker with all parameters" do + let(:facts) { os_facts } + let(:params) do + { + 'method' => 'docker', + 'version' => '3.0.0', + 'puppet_dir' => '/etc/puppetlabs', + 'puppet_code_dir' => '/etc/puppet/code', + } end it { is_expected.to compile.with_all_deps } it { is_expected.to contain_class('docker') } it { is_expected.to contain_file('/etc/hdm/hdm.yml').with('content' => %r{hiera_config_file: "hiera.yaml"}) } + it { is_expected.to contain_docker__run('hdm').with('volumes' => %r{/etc/puppetlabs:/etc/puppetlabs:ro}) } end end end diff --git a/spec/classes/hdm_rvm_spec.rb b/spec/classes/hdm_rvm_spec.rb index dc4a0ee..d648583 100644 --- a/spec/classes/hdm_rvm_spec.rb +++ b/spec/classes/hdm_rvm_spec.rb @@ -14,6 +14,26 @@ end it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('hdm::rvm') } + it { is_expected.to contain_rvm__system_user('hdm') } + it { is_expected.to contain_rvm_gem('bundler') } + it { is_expected.to contain_rvm_system_ruby('ruby-3.3.1') } + it { is_expected.to contain_group('hdm') } + it { is_expected.to contain_user('hdm') } + it { is_expected.to contain_vcsrepo('/etc/hdm') } + it { is_expected.to contain_file('/etc/hdm/config/hdm.yml') } + it { is_expected.to contain_exec('bundle config development') } + it { is_expected.to contain_exec('bundle config path') } + it { is_expected.to contain_exec('bundle db:setup') } + it { is_expected.to contain_exec('bundle install') } + it { is_expected.to contain_exec('bundle rails credentials') } + it { is_expected.to contain_systemd__unit_file('hdm.service') } + + if os_facts[:os]['family'] == 'RedHat' && os_facts[:os]['release']['major'].to_i < 8 + it { is_expected.to contain_package('centos-release-scl') } + it { is_expected.to contain_package('devtoolset-7') } + it { is_expected.to contain_exec('update sqlite') } + end end end end