Skip to content

Commit 9465eea

Browse files
author
Helen
authored
Merge pull request #616 from DavidS/modules-3435-fix-stdlib-symlinks
(MODULES-3435) remove symlinks
2 parents 6bab96e + daa80f1 commit 9465eea

File tree

5 files changed

+68
-48
lines changed

5 files changed

+68
-48
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
pkg/
33
Gemfile.lock
44
vendor/
5-
spec/fixtures/
5+
spec/fixtures/manifests/site.pp
6+
spec/fixtures/modules/*
67
.vagrant/
78
.bundle/
89
coverage/
910
log/
1011
.idea/
1112
*.iml
13+
tmp/

spec/fixtures/modules/stdlib/lib

Lines changed: 0 additions & 1 deletion
This file was deleted.

spec/fixtures/modules/stdlib/manifests

Lines changed: 0 additions & 1 deletion
This file was deleted.

spec/functions/load_module_metadata_spec.rb

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,34 @@
55
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
66
it { is_expected.to run.with_params("one", "two", "three").and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
77

8-
it "should json parse the file" do
9-
allow(scope).to receive(:function_get_module_path).with(['science']).and_return('/path/to/module/')
10-
allow(File).to receive(:exists?).with(/metadata.json/).and_return(true)
11-
allow(File).to receive(:read).with(/metadata.json/).and_return('{"name": "spencer-science"}')
8+
describe "when calling with valid arguments" do
9+
before :each do
10+
if RSpec.configuration.puppet_future
11+
allow(File).to receive(:read).with(/\/stdlib\/metadata.json/, {:encoding=>"utf-8"}).and_return('{"name": "puppetlabs-stdlib"}')
12+
else
13+
allow(File).to receive(:read).with(/\/stdlib\/metadata.json/).and_return('{"name": "puppetlabs-stdlib"}')
14+
end
15+
end
16+
it "should json parse the file" do
17+
allow(scope).to receive(:function_get_module_path).with(['science']).and_return('/path/to/module/')
18+
allow(File).to receive(:exists?).with('/path/to/module/metadata.json').and_return(true)
19+
allow(File).to receive(:read).with('/path/to/module/metadata.json').and_return('{"name": "spencer-science"}')
1220

13-
result = subject.call(['science'])
14-
expect(result['name']).to eq('spencer-science')
15-
end
21+
result = subject.call(['science'])
22+
expect(result['name']).to eq('spencer-science')
23+
end
1624

17-
it "should fail by default if there is no metadata.json" do
18-
allow(scope).to receive(:function_get_module_path).with(['science']).and_return('/path/to/module/')
19-
allow(File).to receive(:exists?).with(/metadata.json/).and_return(false)
20-
expect {subject.call(['science'])}.to raise_error(Puppet::ParseError)
21-
end
25+
it "should fail by default if there is no metadata.json" do
26+
allow(scope).to receive(:function_get_module_path).with(['science']).and_return('/path/to/module/')
27+
allow(File).to receive(:exists?).with('/path/to/module/metadata.json').and_return(false)
28+
expect {subject.call(['science'])}.to raise_error(Puppet::ParseError)
29+
end
2230

23-
it "should return nil if user allows empty metadata.json" do
24-
allow(scope).to receive(:function_get_module_path).with(['science']).and_return('/path/to/module/')
25-
allow(File).to receive(:exists?).with(/metadata.json/).and_return(false)
26-
result = subject.call(['science', true])
27-
expect(result).to eq({})
31+
it "should return nil if user allows empty metadata.json" do
32+
allow(scope).to receive(:function_get_module_path).with(['science']).and_return('/path/to/module/')
33+
allow(File).to receive(:exists?).with('/path/to/module/metadata.json').and_return(false)
34+
result = subject.call(['science', true])
35+
expect(result).to eq({})
36+
end
2837
end
2938
end

spec/functions/loadjson_spec.rb

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,46 @@
44
it { is_expected.not_to eq(nil) }
55
it { is_expected.to run.with_params().and_raise_error(ArgumentError, /wrong number of arguments/i) }
66

7-
context 'when a non-existing file is specified' do
8-
let(:filename) { '/tmp/doesnotexist' }
9-
before {
10-
File.expects(:exists?).with(filename).returns(false).once
11-
PSON.expects(:load).never
12-
}
13-
it { is_expected.to run.with_params(filename, {'default' => 'value'}).and_return({'default' => 'value'}) }
14-
end
7+
describe "when calling with valid arguments" do
8+
before :each do
9+
if RSpec.configuration.puppet_future
10+
allow(File).to receive(:read).with(/\/stdlib\/metadata.json/, {:encoding=>"utf-8"}).and_return('{"name": "puppetlabs-stdlib"}')
11+
else
12+
allow(File).to receive(:read).with(/\/stdlib\/metadata.json/).and_return('{"name": "puppetlabs-stdlib"}')
13+
end
14+
end
1515

16-
context 'when an existing file is specified' do
17-
let(:filename) { '/tmp/doesexist' }
18-
let(:data) { { 'key' => 'value' } }
19-
let(:json) { '{"key":"value"}' }
20-
before {
21-
File.expects(:exists?).with(filename).returns(true).once
22-
File.expects(:read).with(filename).returns(json).once
23-
PSON.expects(:load).with(json).returns(data).once
24-
}
25-
it { is_expected.to run.with_params(filename).and_return(data) }
26-
end
16+
context 'when a non-existing file is specified' do
17+
let(:filename) { '/tmp/doesnotexist' }
18+
before {
19+
allow(File).to receive(:exists?).with(filename).and_return(false).once
20+
allow(PSON).to receive(:load).never
21+
}
22+
it { is_expected.to run.with_params(filename, {'default' => 'value'}).and_return({'default' => 'value'}) }
23+
end
24+
25+
context 'when an existing file is specified' do
26+
let(:filename) { '/tmp/doesexist' }
27+
let(:data) { { 'key' => 'value' } }
28+
let(:json) { '{"key":"value"}' }
29+
before {
30+
allow(File).to receive(:exists?).with(filename).and_return(true).once
31+
allow(File).to receive(:read).with(filename).and_return(json).once
32+
allow(File).to receive(:read).with(filename).and_return(json).once
33+
allow(PSON).to receive(:load).with(json).and_return(data).once
34+
}
35+
it { is_expected.to run.with_params(filename).and_return(data) }
36+
end
2737

28-
context 'when the file could not be parsed' do
29-
let(:filename) { '/tmp/doesexist' }
30-
let(:json) { '{"key":"value"}' }
31-
before {
32-
File.expects(:exists?).with(filename).returns(true).once
33-
File.expects(:read).with(filename).returns(json).once
34-
PSON.stubs(:load).with(json).once.raises StandardError, 'Something terrible have happened!'
35-
}
36-
it { is_expected.to run.with_params(filename, {'default' => 'value'}).and_return({'default' => 'value'}) }
38+
context 'when the file could not be parsed' do
39+
let(:filename) { '/tmp/doesexist' }
40+
let(:json) { '{"key":"value"}' }
41+
before {
42+
allow(File).to receive(:exists?).with(filename).and_return(true).once
43+
allow(File).to receive(:read).with(filename).and_return(json).once
44+
allow(PSON).to receive(:load).with(json).once.and_raise StandardError, 'Something terrible have happened!'
45+
}
46+
it { is_expected.to run.with_params(filename, {'default' => 'value'}).and_return({'default' => 'value'}) }
47+
end
3748
end
3849
end

0 commit comments

Comments
 (0)