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"}')
12 # Additional modules used by litmus which are identified while running these dues to being in fixtures
13 allow(File).to receive(:read).with(%r{\/(provision|puppet_agent|facts)\/metadata.json}, :encoding => 'utf-8')
16 context 'when calling with valid utf8 and double byte character arguments' do
18 allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}, :encoding => 'utf-8').and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš -
20 allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}).and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš -
24 let(:prefix) { 'C:' if Puppet::Util::Platform.windows? }
26 it 'jsons parse the file' do
27 allow(scope).to receive(:function_get_module_path).with(['science']).and_return("#{prefix}/path/to/module/")
28 allow(File).to receive(:exists?).with("#{prefix}/path/to/module/metadata.json").and_return(true)
29 allow(File).to receive(:read).with("#{prefix}/path/to/module/metadata.json").and_return('{"name": "spencer-science"}')
31 result = subject.execute('science')
32 expect(result['name']).to eq('spencer-science')
35 it 'fails by default if there is no metadata.json' do
36 allow(scope).to receive(:function_get_module_path).with(['science']).and_return("#{prefix}/path/to/module/")
37 allow(File).to receive(:exists?).with("#{prefix}/path/to/module/metadata.json").and_return(false)
38 expect { subject.call(['science']) }.to raise_error(Puppet::ParseError)
41 it 'returns nil if user allows empty metadata.json' do
42 allow(scope).to receive(:function_get_module_path).with(['science']).and_return("#{prefix}/path/to/module/")
43 allow(File).to receive(:exists?).with("#{prefix}/path/to/module/metadata.json").and_return(false)
44 result = subject.execute('science', true)
45 expect(result).to eq({})