jovandeginste / puppet-scoop

Manage your scoops with Puppet
Apache License 2.0
2 stars 1 forks source link

add doc about how to unit test with this module #2

Closed hopenbr closed 2 years ago

hopenbr commented 2 years ago

We are using this module within other modules that need to be unit tested

the Scoop module was failing b/c of missing facts, see error message below

I wanted to see if we could get this added to Doc, plus post it here just in case some else needed help

ERROR

Failure/Error: it { is_expected.to compile }
error during compilation: Evaluation Error: Error while evaluating a Resource Statement, 
Evaluation Error: Operator '[]' is not applicable to an Undef Value. \
(file: spec/fixtures/modules/scoop/manifests/package.pp, line: 21, column: 27) 
(file: manifests/init.pp, line: 19) 
on node MyMac

manifests/init.pp is my module that calls scoop

line 19 is

scoop::package { '7zip':
    ensure => 'present',
  }

To remove this error needed to add facts to test run (describe ), in below manager.

let(:facts) do
        os_facts.merge(
        'scoop'        => {
          'exec'       => 'c:\\programdata\\scoop\\shims\\scoop',
          'basedir'    => 'c:\\programdata\\scoop',
          'buckets'    => [
            'main'
          ],
          'packages'   => {
            'git'      =>
            {
              'name'    => 'git',
              'version' => '2.33.1.windows.1',
              'bucket'  => 'main',
              'global'  =>  true,
            }
          }
        }
        )
        end

tests like below started to work as well, just need to add one package, not all of them

it { is_expected.to contain_scoop__package('7zip').with('ensure' => 'present') }
jovandeginste commented 2 years ago

Thank you for this!

jovandeginste commented 2 years ago

I added a file: https://github.com/jovandeginste/puppet-scoop/blob/master/TESTING.md