Skip to content

Commit 07f803e

Browse files
committed
Fix rubocop issues
1 parent a6284ac commit 07f803e

File tree

5 files changed

+161
-173
lines changed

5 files changed

+161
-173
lines changed

lib/puppet/provider/oratab/parsed.rb

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,32 @@
33
require 'puppet/provider/parsedfile'
44

55
oratab = case Facter.value(:operatingsystem)
6-
when 'Solaris'
7-
'/var/opt/oracle/oratab'
8-
else
9-
'/etc/oratab'
10-
end
11-
12-
Puppet::Type.type(:oratab).provide(:parsed, :parent => Puppet::Provider::ParsedFile, :default_target => oratab, :filetype => :flat) do
6+
when 'Solaris'
7+
'/var/opt/oracle/oratab'
8+
else
9+
'/etc/oratab'
10+
end
1311

14-
text_line :comment, :match => /^\s*#/
15-
text_line :blank, :match => /^\s*$/
12+
Puppet::Type.type(:oratab).provide(:parsed, parent: Puppet::Provider::ParsedFile, default_target: oratab, filetype: :flat) do
13+
text_line :comment, match: %r{^\s*#}
14+
text_line :blank, match: %r{^\s*$}
1615

17-
record_line :parsed, :fields => %w{name home atboot description},
18-
:optional => %w{description},
19-
:match => /^\s*(.*?):(.*?):(.*?)\s*(?:#\s*(.*))?$/,
20-
:post_parse => proc { |h|
16+
record_line :parsed, fields: ['name', 'home', 'atboot', 'description'],
17+
optional: ['description'],
18+
match: %r{^\s*(.*?):(.*?):(.*?)\s*(?:#\s*(.*))?$},
19+
post_parse: proc { |h|
2120
h[:atboot] = :yes if h[:atboot] == 'Y'
2221
h[:atboot] = :no if h[:atboot] == 'N'
2322
h
2423
},
25-
:pre_gen => proc { |h|
24+
pre_gen: proc { |h|
2625
h[:atboot] = 'Y' if h[:atboot] == :yes
2726
h[:atboot] = 'N' if h[:atboot] == :no
2827
h
2928
},
30-
:to_line => proc { |h|
29+
to_line: proc { |h|
3130
str = "#{h[:name]}:#{h[:home]}:#{h[:atboot]}"
32-
if description = h[:description] and description != :absent and !description.empty?
31+
if ((description = h[:description])) && (description != :absent) && !description.empty?
3332
str += " # #{description}"
3433
end
3534
str

lib/puppet/type/oratab.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
require 'puppet/provider/parsedfile'
44

55
Puppet::Type.newtype(:oratab) do
6-
76
@doc = "Define database instaces in /etc/oratab with instance name
87
home directory and a flag which indicates if the instance should
98
be started together with the database"
@@ -14,8 +13,8 @@
1413
isnamevar
1514

1615
validate do |value|
17-
raise Puppet::Error, "Name must not contain whitespace: #{value}" if value =~ /\s/
18-
raise Puppet::Error, "Name must not be empty" if value.empty?
16+
raise Puppet::Error, "Name must not contain whitespace: #{value}" if %r{\s}.match?(value)
17+
raise Puppet::Error, 'Name must not be empty' if value.empty?
1918
end
2019
end
2120

@@ -26,7 +25,7 @@
2625
path"
2726

2827
validate do |value|
29-
raise Puppet::Error, "Home must be an absolute path: #{value}" unless value =~ /^\//
28+
raise Puppet::Error, "Home must be an absolute path: #{value}" unless %r{^/}.match?(value)
3029
end
3130
end
3231

@@ -42,11 +41,10 @@
4241
newproperty(:description) do
4342
desc "An optional description that will be added as an inline comment
4443
in the target file"
45-
4644
end
4745

4846
newproperty(:target) do
49-
desc "The path of the target file to store the instance information in"
47+
desc 'The path of the target file to store the instance information in'
5048

5149
defaultto do
5250
if @resource.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile)

spec/integration/provider/oratab/parsed_spec.rb

100644100755
Lines changed: 60 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,29 @@
33
require 'spec_helper'
44
require 'puppet/file_bucket/dipper'
55

6-
describe Puppet::Type.type(:oratab).provider(:parsed), '(integration)' do
6+
describe Puppet::Type.type(:oratab).provider(:parsed) do
77
include PuppetlabsSpec::Files
88

99
before :each do
1010
allow(described_class).to receive(:suitable?).and_return(true)
1111
allow(described_class).to receive(:default_target).and_return(fake_oratab)
1212
allow(Puppet::Type.type(:oratab)).to receive(:defaultprovider).and_return(described_class)
13+
allow(Puppet::FileBucket::Dipper).to receive(:new).and_return(dipper)
14+
end
15+
16+
let :dipper do
17+
instance_double(Puppet::FileBucket::Dipper, backup: nil, 'name=': nil)
18+
end
19+
20+
let :catalog do
21+
c = Puppet::Resource::Catalog.new
22+
c.host_config = false
23+
c
1324
end
1425

1526
let :fake_oratab do
1627
filename = tmpfilename('oratab')
17-
unless File.exists? filename
28+
unless File.exist? filename
1829
FileUtils.cp(my_fixture('input'), filename)
1930
end
2031
filename
@@ -23,75 +34,75 @@
2334
# this resource is absent in our fake oratab
2435
let :resource_absent do
2536
Puppet::Type.type(:oratab).new(
26-
:name => 'NO_SUCH_DATABASE',
27-
:ensure => :absent
37+
name: 'NO_SUCH_DATABASE',
38+
ensure: :absent,
2839
)
2940
end
3041

3142
# this resource is present in our fake oratab and completly insync
3243
let :resource_present do
3344
Puppet::Type.type(:oratab).new(
34-
:name => 'DB_INSYNC',
35-
:ensure => :present,
36-
:home => '/u01/app/oracle/product/10.1.0/db_1',
37-
:atboot => :yes
45+
name: 'DB_INSYNC',
46+
ensure: :present,
47+
home: '/u01/app/oracle/product/10.1.0/db_1',
48+
atboot: :yes,
3849
)
3950
end
4051

4152
# this resource is not present in our fake oratab
4253
let :resource_create do
4354
Puppet::Type.type(:oratab).new(
44-
:name => 'DB_CREATE',
45-
:ensure => :present,
46-
:home => '/u01/app/oracle/product/10.1.0/db_2',
47-
:description => 'added by puppet',
48-
:atboot => :no
55+
name: 'DB_CREATE',
56+
ensure: :present,
57+
home: '/u01/app/oracle/product/10.1.0/db_2',
58+
description: 'added by puppet',
59+
atboot: :no,
4960
)
5061
end
5162

5263
# this resource is present in our fake oratab
5364
let :resource_delete do
5465
Puppet::Type.type(:oratab).new(
55-
:name => 'DB_DELETE',
56-
:ensure => :absent
66+
name: 'DB_DELETE',
67+
ensure: :absent,
5768
)
5869
end
5970

6071
# this resource is present in our fake oratab but with :home => '/u01/app/oracle/product/10.1.0/db_4'
6172
let :resource_sync_home do
62-
Puppet::Type.type(:oratab).new(
63-
:name => 'DB_SYNC_HOME',
64-
:ensure => :present,
65-
:home => '/new/home'
66-
)
73+
Puppet::Type.type(:oratab).new(
74+
name: 'DB_SYNC_HOME',
75+
ensure: :present,
76+
home: '/new/home',
77+
)
6778
end
6879

6980
# this resource is present in our fake oratab but with :atboot => :no
7081
let :resource_sync_atboot do
71-
Puppet::Type.type(:oratab).new(
72-
:name => 'DB_SYNC_ATBOOT',
73-
:ensure => :present,
74-
:home => '/u01/app/oracle/product/10.1.0/db_1',
75-
:atboot => :yes
76-
)
82+
Puppet::Type.type(:oratab).new(
83+
name: 'DB_SYNC_ATBOOT',
84+
ensure: :present,
85+
home: '/u01/app/oracle/product/10.1.0/db_1',
86+
atboot: :yes,
87+
)
7788
end
7889

7990
# this resource is present in our fake oratab but with :description => 'change me'
8091
let :resource_sync_description do
8192
Puppet::Type.type(:oratab).new(
82-
:name => 'DB_SYNC_DESCRIPTION',
83-
:ensure => :present,
84-
:atboot => :no,
85-
:description => 'new desc'
93+
name: 'DB_SYNC_DESCRIPTION',
94+
ensure: :present,
95+
atboot: :no,
96+
description: 'new desc',
8697
)
8798
end
8899

89100
# this resource is present in our fake oratab but with :description => 'delete me'
90101
let :resource_delete_description do
91102
Puppet::Type.type(:oratab).new(
92-
:name => 'DB_DELETE_DESCRIPTION',
93-
:ensure => :present,
94-
:description => ''
103+
name: 'DB_DELETE_DESCRIPTION',
104+
ensure: :present,
105+
description: '',
95106
)
96107
end
97108

@@ -100,9 +111,6 @@
100111
end
101112

102113
def run_in_catalog(*resources)
103-
allow_any_instance_of(Puppet::FileBucket::Dipper).to receive(:backup)
104-
catalog = Puppet::Resource::Catalog.new
105-
catalog.host_config = false
106114
resources.each do |resource|
107115
expect(resource).not_to receive(:err)
108116
catalog.add_resource(resource)
@@ -111,60 +119,59 @@ def run_in_catalog(*resources)
111119
end
112120

113121
def check_content_against(fixture)
114-
content = File.read(fake_oratab).lines.map{|l| l.chomp}.reject{|l| l=~ /^\s*#|^\s*$/}.sort.join("\n")
115-
expected_content = File.read(my_fixture(fixture)).lines.map{|l| l.chomp}.reject{|l| l=~ /^\s*#|^\s*$/}.sort.join("\n")
122+
content = File.read(fake_oratab).lines.map { |l| l.chomp }.reject { |l| l =~ %r{^\s*#|^\s*$} }.sort.join("\n")
123+
expected_content = File.read(my_fixture(fixture)).lines.map { |l| l.chomp }.reject { |l| l =~ %r{^\s*#|^\s*$} }.sort.join("\n")
116124
expect(content).to eq(expected_content)
117125
end
118126

119-
describe "when managing one resource" do
120-
121-
describe "with ensure set to absent" do
122-
it "should do nothing if already absent" do
127+
describe 'when managing one resource' do
128+
describe 'with ensure set to absent' do
129+
it 'does nothing if already absent' do
123130
run_in_catalog(resource_absent)
124131
check_content_against('input')
125132
end
126133

127-
it "should remove oratab entry if currently present" do
134+
it 'removes oratab entry if currently present' do
128135
run_in_catalog(resource_delete)
129136
check_content_against('output_single_delete')
130137
end
131138
end
132139

133-
describe "with ensure set to present" do
134-
it "should do nothing if already present and in sync" do
140+
describe 'with ensure set to present' do
141+
it 'does nothing if already present and in sync' do
135142
run_in_catalog(resource_present)
136143
check_content_against('input')
137144
end
138145

139-
it "should create an oratab entry if currently absent" do
146+
it 'creates an oratab entry if currently absent' do
140147
run_in_catalog(resource_create)
141148
check_content_against('output_single_create')
142149
end
143150

144-
it "should sync home if out of sync" do
151+
it 'syncs home if out of sync' do
145152
run_in_catalog(resource_sync_home)
146153
check_content_against('output_single_sync_home')
147154
end
148155

149-
it "should sync atboot if out of sync" do
156+
it 'syncs atboot if out of sync' do
150157
run_in_catalog(resource_sync_atboot)
151158
check_content_against('output_single_sync_atboot')
152159
end
153160

154-
it "should sync description if out sync" do
161+
it 'syncs description if out sync' do
155162
run_in_catalog(resource_sync_description)
156163
check_content_against('output_single_sync_description')
157164
end
158165

159-
it "should remove the description (including the #-sign) if description is empty" do
166+
it 'removes the description (including the #-sign) if description is empty' do
160167
run_in_catalog(resource_delete_description)
161168
check_content_against('output_single_sync_description_delete')
162169
end
163170
end
164171
end
165172

166-
describe "when managing multiple resources" do
167-
it "should to the right thing (tm)" do
173+
describe 'when managing multiple resources' do
174+
it 'toes the right thing (tm)' do
168175
run_in_catalog(
169176
resource_absent,
170177
resource_present,
@@ -173,10 +180,9 @@ def check_content_against(fixture)
173180
resource_sync_home,
174181
resource_sync_atboot,
175182
resource_sync_description,
176-
resource_delete_description
183+
resource_delete_description,
177184
)
178185
check_content_against('output_multiple')
179186
end
180187
end
181-
182188
end

0 commit comments

Comments
 (0)