Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / load_module_metadata_spec.rb
1 require 'spec_helper'
2
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) }
7
8   describe 'when calling with valid arguments' do
9     before :each 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')
14     end
15
16     context 'when calling with valid utf8 and double byte character arguments' do
17       before :each do
18         allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}, :encoding => 'utf-8').and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš -
19 この文字"}')
20         allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}).and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš -
21 この文字"}')
22       end
23
24       let(:prefix) { 'C:' if Puppet::Util::Platform.windows? }
25
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"}')
30
31         result = subject.execute('science')
32         expect(result['name']).to eq('spencer-science')
33       end
34
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)
39       end
40
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({})
46       end
47     end
48   end
49 end