3 describe 'load_module_metadata' do
4 it { is_expected.not_to eq(nil) }
5 it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
6 it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
8 describe 'when calling with valid arguments' do
10 allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}, :encoding => 'utf-8').and_return('{"name": "puppetlabs-stdlib"}')
11 allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}).and_return('{"name": "puppetlabs-stdlib"}')
14 context 'when calling with valid utf8 and double byte character arguments' do
16 allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}, :encoding => 'utf-8').and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš -
18 allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}).and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš -
22 let(:prefix) { 'C:' if Puppet::Util::Platform.windows? }
24 it 'jsons parse the file' do
25 allow(scope).to receive(:function_get_module_path).with(['science']).and_return("#{prefix}/path/to/module/")
26 allow(File).to receive(:exists?).with("#{prefix}/path/to/module/metadata.json").and_return(true)
27 allow(File).to receive(:read).with("#{prefix}/path/to/module/metadata.json").and_return('{"name": "spencer-science"}')
29 result = subject.execute('science')
30 expect(result['name']).to eq('spencer-science')
33 it 'fails by default if there is no metadata.json' do
34 allow(scope).to receive(:function_get_module_path).with(['science']).and_return("#{prefix}/path/to/module/")
35 allow(File).to receive(:exists?).with("#{prefix}/path/to/module/metadata.json").and_return(false)
36 expect { subject.call(['science']) }.to raise_error(Puppet::ParseError)
39 it 'returns nil if user allows empty metadata.json' do
40 allow(scope).to receive(:function_get_module_path).with(['science']).and_return("#{prefix}/path/to/module/")
41 allow(File).to receive(:exists?).with("#{prefix}/path/to/module/metadata.json").and_return(false)
42 result = subject.execute('science', true)
43 expect(result).to eq({})