From 744f3dfa58bc23d725c22b201dccebb1441bb23e Mon Sep 17 00:00:00 2001 From: Joshua Hoblitt Date: Fri, 1 Dec 2023 14:57:46 -0700 Subject: [PATCH] fwv --- .fixtures.yml | 6 ------ examples/powertop_absent.pp | 3 +++ examples/powertop_present.pp | 1 + manifests/init.pp | 20 +++++++++++++++++++- metadata.json | 7 +------ spec/acceptance/powertop_spec.rb | 29 +++++++++++++++++++++++++++++ spec/classes/powertop_spec.rb | 13 +++++++++++++ 7 files changed, 66 insertions(+), 13 deletions(-) delete mode 100644 .fixtures.yml create mode 100644 examples/powertop_absent.pp create mode 100644 examples/powertop_present.pp create mode 100644 spec/acceptance/powertop_spec.rb create mode 100644 spec/classes/powertop_spec.rb diff --git a/.fixtures.yml b/.fixtures.yml deleted file mode 100644 index 6470f44..0000000 --- a/.fixtures.yml +++ /dev/null @@ -1,6 +0,0 @@ -# This file can be used to install module dependencies for unit testing -# See https://github.com/puppetlabs/puppetlabs_spec_helper#using-fixtures for details ---- -fixtures: - forge_modules: - stdlib: "puppetlabs/stdlib" diff --git a/examples/powertop_absent.pp b/examples/powertop_absent.pp new file mode 100644 index 0000000..85dc459 --- /dev/null +++ b/examples/powertop_absent.pp @@ -0,0 +1,3 @@ +class { 'powertop': + ensure => 'absent', +} diff --git a/examples/powertop_present.pp b/examples/powertop_present.pp new file mode 100644 index 0000000..dcd78a5 --- /dev/null +++ b/examples/powertop_present.pp @@ -0,0 +1 @@ +include powertop diff --git a/manifests/init.pp b/manifests/init.pp index 33e69bd..b2c5d64 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,5 +1,23 @@ # # @summary Manages powertop # -class powertop { +# @param ensure +# Whether powertop should be present or absent. +# +class powertop ( + Enum['present', 'absent'] $ensure = 'present', +) { + $pkg_name = 'powertop' + + package { $pkg_name: + ensure => $ensure, + } + + if $ensure == present { + # powertop service unit tweaks values and then exits. There is no persistent daemon. + service { 'powertop': + enable => true, + require => Package[$pkg_name], + } + } } diff --git a/metadata.json b/metadata.json index 103d95e..107b034 100644 --- a/metadata.json +++ b/metadata.json @@ -5,12 +5,7 @@ "summary": "powertop module", "license": "AGPL-3.0", "source": "https://github.com/lsst-it/puppet-powertop", - "dependencies": [ - { - "name": "puppetlabs/stdlib", - "version_requirement": ">= 8.0.0 < 10.0.0" - } - ], + "dependencies": [], "operatingsystem_support": [ { "operatingsystem": "CentOS", diff --git a/spec/acceptance/powertop_spec.rb b/spec/acceptance/powertop_spec.rb new file mode 100644 index 0000000..3da6db0 --- /dev/null +++ b/spec/acceptance/powertop_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require 'spec_helper_acceptance' + +describe 'powertop class' do + context 'without any parameters' do + include_examples 'the example', 'powertop_present.pp' + + describe package('powertop') do + it { is_expected.to be_installed } + end + + describe service('powertop') do + it { is_expected.to be_enabled } + end + end + + context 'with parameters =>' do + include_examples 'the example', 'powertop_absent.pp' + + describe package('powertop') do + it { is_expected.not_to be_installed } + end + + describe service('powertop') do + it { is_expected.not_to be_enabled } + end + end +end diff --git a/spec/classes/powertop_spec.rb b/spec/classes/powertop_spec.rb new file mode 100644 index 0000000..90e94f2 --- /dev/null +++ b/spec/classes/powertop_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'powertop' do + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:facts) { os_facts } + + it { is_expected.to compile.with_all_deps } + end + end +end