Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rubocop: Fix Layout cops #123

Merged
merged 1 commit into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,3 @@ Style/TrailingCommaInArguments:

Metrics:
Enabled: false

Layout:
Enabled: false
2 changes: 1 addition & 1 deletion beaker-rspec.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>= 2.7.0', '<4.0.0'

s.files = `git ls-files`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
s.require_paths = ['lib']

# Testing dependencies
Expand Down
1 change: 0 additions & 1 deletion lib/beaker-rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ module BeakerRSpec
require 'beaker-rspec/beaker_shim'
require 'beaker-rspec/spec_helper'
require 'beaker-rspec/version'

end
1 change: 0 additions & 1 deletion lib/beaker-rspec/beaker_shim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,5 @@ def default_node
def cleanup
@network_manager.cleanup
end

end
end
36 changes: 15 additions & 21 deletions lib/beaker-rspec/helpers/serverspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
set :backend, 'BeakerDispatch'

module Specinfra

# Accessor for current example
def cur_example
Specinfra.backend.example
Expand All @@ -30,10 +29,8 @@ def cygwin_backend
def exec_backend
@exec_backend ||= Specinfra::Backend::BeakerExec.instance
end

end


# Override existing specinfra configuration to avoid conflicts
# with beaker's shell, stdout, stderr defines
module Specinfra
Expand All @@ -55,17 +52,16 @@ class << self
dockerfile_finalizer
].freeze
end

end
end

module Specinfra::Helper::Os

@@known_nodes = {}

def os
working_node_name = get_working_node.to_s
@@known_nodes[working_node_name] = property[:os] = detect_os unless @@known_nodes[working_node_name] # haven't seen this yet, better detect the os
# haven't seen this yet, better detect the os
@@known_nodes[working_node_name] = property[:os] = detect_os unless @@known_nodes[working_node_name]
@@known_nodes[working_node_name]
end

Expand All @@ -75,9 +71,11 @@ def os
# when we know that we have a windows node
def detect_os
return Specinfra.configuration.os if Specinfra.configuration.os

backend = Specinfra.backend
node = get_working_node
return {family: 'windows'} if node['platform'].include?('windows')
return { family: 'windows' } if node['platform'].include?('windows')

Specinfra::Helper::DetectOs.subclasses.each do |c|
res = c.detect
if res
Expand All @@ -92,7 +90,6 @@ class Specinfra::CommandFactory
class << self
# Force creation of a windows command
def get_windows_cmd(meth, *args)

action, resource_type, subaction = breakdown(meth)
method = action
method += "_#{subaction}" if subaction
Expand All @@ -104,17 +101,19 @@ def get_windows_cmd(meth, *args)
command_class = version_class.const_get(resource_type.to_camel_case)

command_class = command_class.create
raise NotImplementedError, "#{method} is not implemented in #{command_class}" unless command_class.respond_to?(method)
unless command_class.respond_to?(method)
raise NotImplementedError,
"#{method} is not implemented in #{command_class}"
end

command_class.send(method, *args)
end

end
end

module Specinfra
# Rewrite the runner to use the appropriate backend based upon platform information
class Runner

def self.method_missing(meth, *args)
backend = Specinfra.backend
node = get_working_node
Expand All @@ -134,7 +133,6 @@ def self.method_missing(meth, *args)
end
end


def self.run(meth, *args)
backend = Specinfra.backend
cmd = Specinfra.command.get(meth, *args)
Expand Down Expand Up @@ -179,14 +177,12 @@ def ssh_exec!(node, command)
stderr: r.stderr,
}
end

end
end

# Used as a container for the two backends, dispatches as windows/nix depending on node platform
module Specinfra::Backend
class BeakerDispatch < BeakerBase

def dispatch_method(meth, *args)
if get_working_node['platform'].include?('windows')
cygwin_backend.send(meth, *args)
Expand All @@ -195,7 +191,7 @@ def dispatch_method(meth, *args)
end
end

def run_command(cmd, opts={})
def run_command(cmd, opts = {})
dispatch_method('run_command', cmd, opts)
end

Expand All @@ -222,8 +218,8 @@ class BeakerCygwin < BeakerBase
def run_command(cmd, _opt = {})
node = get_working_node
script = create_script(cmd)
#when node is not cygwin rm -rf will fail so lets use native del instead
#There should be a better way to do this, but for now , this works
# when node is not cygwin rm -rf will fail so lets use native del instead
# There should be a better way to do this, but for now , this works
if node.is_cygwin?
delete_command = 'rm -rf'
redirection = '< /dev/null'
Expand All @@ -233,8 +229,8 @@ def run_command(cmd, _opt = {})
end
on node, "#{delete_command} script.ps1"
create_remote_file(node, 'script.ps1', script)
#When using cmd on a pswindows node redirection should be set to < NUl
#when using a cygwing one, /dev/null should be fine
# When using cmd on a pswindows node redirection should be set to < NUl
# when using a cygwing one, /dev/null should be fine
ret = ssh_exec!(node, "powershell.exe -File script.ps1 #{redirection}")

if @example
Expand All @@ -250,7 +246,6 @@ def run_command(cmd, _opt = {})
# Backend for running serverspec commands on non-windows test nodes
module Specinfra::Backend
class BeakerExec < BeakerBase

# Run a unix style command using serverspec. Defaults to running on the 'default_node'
# test node, otherwise uses the node specified in @example.metadata[:node]
# @param [String] cmd The serverspec command to executed
Expand Down Expand Up @@ -289,6 +284,5 @@ def add_pre_command(cmd)
cmd
end
end

end
end
12 changes: 6 additions & 6 deletions lib/beaker-rspec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
# Define persistant default node
c.add_setting :default_node, default: nil

#default option values
# default option values
defaults = {
nodeset: 'default',
}
#read env vars
# read env vars
env_vars = {
color: ENV['BEAKER_COLOR'] || ENV['BEAKER_color'] || ENV.fetch('RS_COLOR', nil),
nodeset: ENV['BEAKER_SET'] || ENV['BEAKER_set'] || ENV.fetch('RS_SET', nil),
Expand All @@ -32,9 +32,9 @@
debug: ENV['BEAKER_DEBUG'] || ENV['BEAKER_debug'] || ENV.fetch('RS_DEBUG', nil),
destroy: ENV['BEAKER_DESTROY'] || ENV['BEAKER_destroy'] || ENV.fetch('RS_DESTROY', nil),
optionsfile: ENV['BEAKER_OPTIONS_FILE'] || ENV['BEAKER_options_file'] || ENV.fetch('RS_OPTIONS_FILE', nil),
}.delete_if {|_key, value| value.nil?}
#combine defaults and env_vars to determine overall options
options = defaults.merge(env_vars)
}.delete_if { |_key, value| value.nil? }
# combine defaults and env_vars to determine overall options
options = defaults.merge(env_vars)

# process options to construct beaker command string
nodesetdir = options[:nodesetdir] || File.join('spec', 'acceptance', 'nodesets')
Expand All @@ -43,7 +43,7 @@
keyfile = options[:keyfile] ? ['--keyfile', options[:keyfile]] : nil
debug = options[:debug] && options[:debug] != 'no' ? ['--log-level', 'debug'] : nil
color = options[:color] == 'no' ? ['--no-color'] : nil
options_file = options[:optionsfile] ? ['--options-file',options[:optionsfile]] : nil
options_file = options[:optionsfile] ? ['--options-file', options[:optionsfile]] : nil

# Configure all nodes in nodeset
c.setup([fresh_nodes, '--hosts', nodesetfile, keyfile, debug, color, options_file].flatten.compact)
Expand Down
9 changes: 4 additions & 5 deletions spec/acceptance/example_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'spec_helper'

describe 'ignore' do

example 'ignore' do
hosts.each do |host|
on host, 'echo hello'
Expand All @@ -17,8 +16,8 @@
end

example 'access the logger' do
logger.debug("hi, i'm a debug message")
logger.notify("hi, I'm a notify message")
logger.debug("hi, i'm a debug message")
logger.notify("hi, I'm a notify message")
end

example 'access the options' do
Expand Down Expand Up @@ -48,7 +47,7 @@
'root'
end
describe user(usr), node: node do
it { is_expected.to exist }
it { is_expected.to exist }
end
end
end
Expand All @@ -61,7 +60,7 @@
'root'
end
describe user(usr) do
it { is_expected.to exist }
it { is_expected.to exist }
end
end

Expand Down