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, /wrong number of arguments/i) }
6 it { is_expected.to run.with_params("one", "two", "three").and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
8 describe "when calling with valid arguments" do
10 allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/, {:encoding=>"utf-8"}).and_return('{"name": "puppetlabs-stdlib"}')
11 allow(File).to receive(:read).with(/\/(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(/\/(stdlib|test)\/metadata.json/, {:encoding=>"utf-8"}).and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš -
18 allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/).and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš -
22 it "should json parse the file" do
23 if Puppet::Util::Platform.windows?
24 allow(scope).to receive(:function_get_module_path).with(['science']).and_return('C:/path/to/module/')
25 allow(File).to receive(:exists?).with('C:/path/to/module/metadata.json').and_return(true)
26 allow(File).to receive(:read).with('C:/path/to/module/metadata.json').and_return('{"name": "spencer-science"}')
28 allow(scope).to receive(:function_get_module_path).with(['science']).and_return('/path/to/module/')
29 allow(File).to receive(:exists?).with('/path/to/module/metadata.json').and_return(true)
30 allow(File).to receive(:read).with('/path/to/module/metadata.json').and_return('{"name": "spencer-science"}')
33 result = subject.call(['science'])
34 expect(result['name']).to eq('spencer-science')
37 it "should fail by default if there is no metadata.json" do
38 if Puppet::Util::Platform.windows?
39 allow(scope).to receive(:function_get_module_path).with(['science']).and_return('C:/path/to/module/')
40 allow(File).to receive(:exists?).with('C:/path/to/module/metadata.json').and_return(false)
42 allow(scope).to receive(:function_get_module_path).with(['science']).and_return('/path/to/module/')
43 allow(File).to receive(:exists?).with('/path/to/module/metadata.json').and_return(false)
45 expect {subject.call(['science'])}.to raise_error(Puppet::ParseError)
48 it "should return nil if user allows empty metadata.json" do
49 if Puppet::Util::Platform.windows?
50 allow(scope).to receive(:function_get_module_path).with(['science']).and_return('C:/path/to/module/')
51 allow(File).to receive(:exists?).with('C:/path/to/module/metadata.json').and_return(false)
53 allow(scope).to receive(:function_get_module_path).with(['science']).and_return('/path/to/module/')
54 allow(File).to receive(:exists?).with('/path/to/module/metadata.json').and_return(false)
56 result = subject.call(['science', true])
57 expect(result).to eq({})