Skip to content

Commit

Permalink
rubocop: autofix
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Apr 9, 2021
1 parent 929f784 commit 927ee2e
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 74 deletions.
14 changes: 4 additions & 10 deletions lib/puppet/provider/zypprepo/inifile.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Description of zypper repositories
require 'puppet/util/inifile'


Puppet::Type.type(:zypprepo).provide(:inifile) do
desc <<-EOD
Manage zypper repo configurations by parsing zypper INI configuration files.
Expand Down Expand Up @@ -59,13 +58,10 @@ def self.prefetch(resources)
repos = instances
resources.each_key do |name|
provider = repos.find { |repo| repo.name == name }
if provider
resources[name].provider = provider
end
resources[name].provider = provider if provider
end
end


#
# @api private
# @param conf [String] Configuration file to look for directories in.
Expand Down Expand Up @@ -180,8 +176,7 @@ def self.store(resource)
next unless Puppet::FileSystem.exist?(file)
current_mode = Puppet::FileSystem.stat(file).mode & 0o777
next if current_mode == target_mode
resource.info _('changing mode of %{file} from %{current_mode} to %{target_mode}') %
{ file: file, current_mode: '%03o' % current_mode, target_mode: '%03o' % target_mode }
resource.info format(_('changing mode of %{file} from %{current_mode} to %{target_mode}'), file: file, current_mode: format('%03o', current_mode), target_mode: format('%03o', target_mode))
Puppet::FileSystem.chmod(target_mode, file)
end
end
Expand Down Expand Up @@ -280,7 +275,7 @@ def descr
end

def descr=(value)
value = ((value == :absent) ? nil : value)
value = (value == :absent ? nil : value)
current_section['name'] = value
@property_hash[:descr] = value
end
Expand All @@ -296,7 +291,7 @@ def get_property(property)
end

def set_property(property, value)
value = ((value == :absent) ? nil : value)
value = (value == :absent ? nil : value)
current_section[property.to_s] = value
@property_hash[property] = value
end
Expand All @@ -308,5 +303,4 @@ def section(name)
def current_section
self.class.section(name)
end

end
4 changes: 2 additions & 2 deletions lib/puppet/type/zypprepo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
ZYPP_BOOLEAN_DOC = 'Valid values are: false/0/no or true/1/yes.'.freeze

munge_zypp_bool = proc do |val|
(val.to_s == 'absent') ? :absent : val.to_s.capitalize
val.to_s == 'absent' ? :absent : val.to_s.capitalize
end

VALID_SCHEMES = ['file', 'http', 'https', 'ftp', 'cd'].freeze
VALID_SCHEMES = %w[file http https ftp cd].freeze

newparam(:name, namevar: true) do
desc "The name of the repository. This corresponds to the
Expand Down
6 changes: 2 additions & 4 deletions spec/lib/puppet_spec/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module PuppetSpec::Compiler
def compile_to_catalog(string, node = Puppet::Node.new('test'))
Puppet[:code] = string
# see lib/puppet/indirector/catalog/compiler.rb#filter
Puppet::Parser::Compiler.compile(node).filter { |r| r.virtual? }
Puppet::Parser::Compiler.compile(node).filter(&:virtual?)
end

def compile_to_ral(manifest, node = Puppet::Node.new('test'))
Expand All @@ -23,9 +23,7 @@ def apply_compiled_manifest(manifest, prioritizer = Puppet::Graph::SequentialPri
# rubocop:enable RSpec/AnyInstance
end
catalog = compile_to_ral(manifest)
if block_given?
catalog.resources.each { |res| yield res }
end
catalog.resources.each { |res| yield res } if block_given?
transaction = Puppet::Transaction.new(catalog,
Puppet::Transaction::Report.new(*args),
prioritizer)
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/puppet_spec/files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ def self.record_tmp(tmp)
end

def expect_file_mode(file, mode)
actual_mode = '%o' % Puppet::FileSystem.stat(file).mode
actual_mode = format('%o', Puppet::FileSystem.stat(file).mode)
target_mode = if Puppet.features.microsoft_windows?
mode
else
'10' + '%04i' % mode.to_i
'10' + format('%04i', mode.to_i)
end
expect(actual_mode).to eq(target_mode)
end
Expand Down
39 changes: 19 additions & 20 deletions spec/unit/provider/zypprepo/inifile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ module PuppetSpec
require 'spec_helper'
require 'puppet_spec/compiler'
require 'puppet_spec/files'

# rubocop:disable RSpec/MessageSpies
describe Puppet::Type.type(:zypprepo).provider(:inifile) do
include PuppetSpec::Files
include PuppetSpec::Compiler

after(:each) do
after do
described_class.clear
end

Expand All @@ -28,18 +28,17 @@ module PuppetSpec
expect(actual).to include('/etc/zypp/repos.d/first.repo')
expect(actual).to include('/etc/zypp/repos.d/second.repo')
end

end

describe 'generating the virtual inifile' do
let(:files) { ['/etc/zypp/repos.d/first.repo', '/etc/zypp/repos.d/second.repo'] }
# rubocop:disable RSpec/VerifiedDoubles
let(:collection) { double('virtual inifile') }

before(:each) do
before do
described_class.clear
expect(Puppet::Util::IniConfig::FileCollection).to receive(:new).and_return collection
expect(Puppet::Util::IniConfig::FileCollection).to receive(:new).and_return collection # rubocop:disable RSpec/ExpectInHook
end

it 'reads all files in the directories specified by self.repofiles' do
expect(described_class).to receive(:repofiles).and_return(files)

Expand Down Expand Up @@ -68,20 +67,20 @@ module PuppetSpec
let(:main_section) do
sect = Puppet::Util::IniConfig::Section.new('main', '/some/imaginary/file')
sect.entries << ['distroverpkg', 'sles-release']
sect.entries << ['plugins', '1']
sect.entries << %w[plugins 1]

sect
end

let(:updates_section) do
sect = Puppet::Util::IniConfig::Section.new('updates', '/some/imaginary/file')
sect.entries << ['name', 'Some long description of the repo']
sect.entries << ['enabled', '1']
sect.entries << %w[enabled 1]

sect
end

before :each do
before do
allow(described_class).to receive(:virtual_inifile).and_return(virtual_inifile)
end

Expand All @@ -108,12 +107,12 @@ module PuppetSpec

let(:ini_section) { double('ini file section') }

before(:each) do
before do
allow(described_class).to receive(:virtual_inifile).and_return(collection)
end

describe 'and the requested section exists' do
before(:each) do
before do
allow(collection).to receive(:[]).with('updates').and_return ini_section
end

Expand Down Expand Up @@ -147,7 +146,7 @@ module PuppetSpec
descr: 'Puppet Labs Products SLES 12 - $basearch',
enabled: '1',
gpgcheck: '1',
gpgkey: 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs',
gpgkey: 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs'
)
end

Expand All @@ -159,7 +158,7 @@ module PuppetSpec
double('inifile puppetlabs section', name: 'puppetlabs-products')
end

before(:each) do
before do
type_instance.provider = provider
allow(described_class).to receive(:section).with('puppetlabs-products').and_return(section)
end
Expand Down Expand Up @@ -216,7 +215,7 @@ module PuppetSpec
describe 'reposdir' do
let(:defaults) { ['/etc/zypp/repos.d'] }

before(:each) do
before do
allow(Puppet::FileSystem).to receive(:exist?).with('/etc/zypp/repos.d').and_return(true)
end

Expand Down Expand Up @@ -277,10 +276,10 @@ module PuppetSpec
let(:pfile) { double('zypp.conf physical file') }
let(:sect) { double('ini section') }

before(:each) do
before do
allow(Puppet::FileSystem).to receive(:exist?).with('/etc/zypp/zypp.conf').and_return true
allow(Puppet::Util::IniConfig::PhysicalFile).to receive(:new).with('/etc/zypp/zypp.conf').and_return pfile
expect(pfile).to receive(:read)
expect(pfile).to receive(:read) # rubocop:disable RSpec/ExpectInHook
end

it 'creates a PhysicalFile to parse the given file' do
Expand Down Expand Up @@ -316,7 +315,7 @@ module PuppetSpec
descr: 'Puppet Labs Products SLES 12 - $basearch',
enabled: '1',
gpgcheck: '1',
gpgkey: 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs',
gpgkey: 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs'
)
end

Expand All @@ -327,7 +326,7 @@ module PuppetSpec
let(:zypprepo_dir) { tmpdir('zypprepo_integration_specs') }
let(:zypprepo_conf_file) { tmpfile('zypprepo_conf_file', zypprepo_dir) }

before :each do
before do
allow(described_class).to receive(:reposdir).and_return [zypprepo_dir]
type_instance.provider = provider
end
Expand Down Expand Up @@ -396,6 +395,6 @@ module PuppetSpec
provider.flush
end
end

end

# rubocop:enable RSpec/MessageSpies
# rubocop:enaable RSpec/VerifiedDoubles
Loading

0 comments on commit 927ee2e

Please sign in to comment.