Skip to content

Commit 30aae00

Browse files
committed
Chefstyle fixes
Lint this repo Signed-off-by: Tim Smith <[email protected]>
1 parent 091292b commit 30aae00

13 files changed

+356
-354
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
source 'https://rubygems.org'
1+
source "https://rubygems.org"
22
gemspec

Rakefile

+19-18
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,47 @@
11
#!/usr/bin/env rake
2-
require 'bundler/gem_tasks'
3-
require 'json'
2+
require "bundler/gem_tasks"
3+
require "json"
44

5-
task :default => ['validate:json', 'spec']
5+
task default: ["validate:json", "spec"]
66

77
namespace :validate do
8-
desc 'Validate mock platform data is valid JSON'
8+
desc "Validate mock platform data is valid JSON"
99
task :json do
1010
failure = false
11-
Dir.glob('./lib/fauxhai/platforms/**/*.json') do |file|
11+
Dir.glob("./lib/fauxhai/platforms/**/*.json") do |file|
1212
begin
1313
JSON.parse(File.read(file))
14-
rescue JSON::ParserError => e
14+
rescue JSON::ParserError
1515
failure = true
1616
puts "Failed to parse #{file}."
1717
end
1818
end
1919
exit! if failure
20-
puts 'JSON files validated'
20+
puts "JSON files validated"
2121
end
2222
end
2323

2424
namespace :documentation do
25-
desc 'Update the PLATFORMS.md file with a list of all platforms'
25+
desc "Update the PLATFORMS.md file with a list of all platforms"
2626
task :update_platforms do
27-
File.delete('PLATFORMS.md') if File.exist?('PLATFORMS.md')
28-
f = File.new('PLATFORMS.md', 'w')
27+
File.delete("PLATFORMS.md") if File.exist?("PLATFORMS.md")
28+
f = File.new("PLATFORMS.md", "w")
2929
f.write "## Fauxhai Platforms\n\nThis file lists each platform known to Fauxhai and the available versions for each of those platforms. See the ChefSpec documentation for mocking out platforms and platform versions within ChefSpec.\n"
30-
Dir.glob('./lib/fauxhai/platforms/**').sort.each do |platform_path|
31-
next if platform_path.split('/')[-1] == 'chefspec'
30+
Dir.glob("./lib/fauxhai/platforms/**").sort.each do |platform_path|
31+
next if platform_path.split("/")[-1] == "chefspec"
32+
3233
versions = []
33-
Dir.glob(File.join(platform_path, '**.json')).sort.each do |version_path|
34+
Dir.glob(File.join(platform_path, "**.json")).sort.each do |version_path|
3435
# skip anything marked as deprecated
3536
data = JSON.parse(File.read(version_path))
36-
unless data['deprecated']
37-
versions << version_path.split('/')[-1].chomp('.json')
37+
unless data["deprecated"]
38+
versions << version_path.split("/")[-1].chomp(".json")
3839
end
3940
end
4041
# make sure there are any non-deprecated platforms before writing out the header
4142
unless versions.empty?
42-
f.write "\n### #{platform_path.split('/')[-1]}\n\n"
43-
versions = versions.sort_by { |v| Gem::Version.new(v) } unless platform_path.split('/')[-1] == 'windows' # make sure we're sorted by version and not by strings
43+
f.write "\n### #{platform_path.split("/")[-1]}\n\n"
44+
versions = versions.sort_by { |v| Gem::Version.new(v) } unless platform_path.split("/")[-1] == "windows" # make sure we're sorted by version and not by strings
4445
versions.each do |v|
4546
f.write " - #{v}\n"
4647
end
@@ -50,5 +51,5 @@ namespace :documentation do
5051
end
5152
end
5253

53-
require 'rspec/core/rake_task'
54+
require "rspec/core/rake_task"
5455
RSpec::Core::RakeTask.new(:spec)

bin/fauxhai

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
#!/usr/bin/env ruby
22

3-
lib = File.expand_path(File.dirname(__FILE__) + '../../lib')
3+
lib = File.expand_path(File.dirname(__FILE__) + "../../lib")
44
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
55

66
args = ARGV.dup
77
ARGV.clear
88

9-
unless (args & ['-v', '--version']).empty?
10-
require 'fauxhai/version'
9+
unless (args & ["-v", "--version"]).empty?
10+
require "fauxhai/version"
1111
puts Fauxhai::VERSION
1212
exit(0)
1313
end
1414

15-
unless (args & ['-h', '--help']).empty?
16-
puts 'Usage: fauxhai'
17-
puts '(There are no flags or options)'
15+
unless (args & ["-h", "--help"]).empty?
16+
puts "Usage: fauxhai"
17+
puts "(There are no flags or options)"
1818
exit(0)
1919
end
2020

21-
require 'fauxhai'
22-
require 'fauxhai/runner'
21+
require "fauxhai"
22+
require "fauxhai/runner"
2323
Fauxhai::Runner.new(args)

fauxhai-ng.gemspec

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
lib = File.expand_path('../lib', __FILE__)
1+
lib = File.expand_path("../lib", __FILE__)
22
$:.unshift(lib) unless $:.include?(lib)
3-
require 'fauxhai/version'
3+
require "fauxhai/version"
44

55
Gem::Specification.new do |spec|
6-
spec.name = 'fauxhai-ng'
6+
spec.name = "fauxhai-ng"
77
spec.version = Fauxhai::VERSION
8-
spec.authors = ['Seth Vargo', 'Tim Smith']
9-
10-
spec.description = 'Easily mock out ohai data'
11-
spec.summary = 'Fauxhai provides an easy way to mock out your ohai data for testing with chefspec!'
12-
spec.homepage = 'https://github.com/chefspec/fauxhai'
13-
spec.license = 'MIT'
8+
spec.authors = ["Seth Vargo", "Tim Smith"]
9+
10+
spec.description = "Easily mock out ohai data"
11+
spec.summary = "Fauxhai provides an easy way to mock out your ohai data for testing with chefspec!"
12+
spec.homepage = "https://github.com/chefspec/fauxhai"
13+
spec.license = "MIT"
1414

15-
spec.required_ruby_version = '>= 2.3'
15+
spec.required_ruby_version = ">= 2.3"
1616

1717
spec.files = %w{LICENSE} + Dir.glob("{lib,bin}/**/*", File::FNM_DOTMATCH).reject { |f| File.directory?(f) }
18-
spec.executables = 'fauxhai'
19-
spec.require_paths = ['lib']
18+
spec.executables = "fauxhai"
19+
spec.require_paths = ["lib"]
2020

21-
spec.add_runtime_dependency 'net-ssh'
21+
spec.add_runtime_dependency "net-ssh"
2222

23-
spec.add_development_dependency 'chef', '>= 13.0'
24-
spec.add_development_dependency 'ohai', '>= 13.0'
25-
spec.add_development_dependency 'rake'
26-
spec.add_development_dependency 'rspec', '~> 3.7'
27-
spec.add_development_dependency 'rspec-its', '~> 1.2'
23+
spec.add_development_dependency "chef", ">= 13.0"
24+
spec.add_development_dependency "ohai", ">= 13.0"
25+
spec.add_development_dependency "rake"
26+
spec.add_development_dependency "rspec", "~> 3.7"
27+
spec.add_development_dependency "rspec-its", "~> 1.2"
2828
end

lib/fauxhai.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module Fauxhai
2-
autoload :Exception, 'fauxhai/exception'
3-
autoload :Fetcher, 'fauxhai/fetcher'
4-
autoload :Mocker, 'fauxhai/mocker'
5-
autoload :VERSION, 'fauxhai/version'
2+
autoload :Exception, "fauxhai/exception"
3+
autoload :Fetcher, "fauxhai/fetcher"
4+
autoload :Mocker, "fauxhai/mocker"
5+
autoload :VERSION, "fauxhai/version"
66

77
def self.root
8-
@@root ||= File.expand_path('../../', __FILE__)
8+
@@root ||= File.expand_path("../../", __FILE__)
99
end
1010

1111
def self.mock(*args, &block)

lib/fauxhai/fetcher.rb

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
require 'digest/sha1'
2-
require 'json'
3-
require 'net/ssh'
1+
require "digest/sha1"
2+
require "json"
3+
require "net/ssh"
44

55
module Fauxhai
66
class Fetcher
@@ -11,11 +11,11 @@ def initialize(options = {}, &override_attributes)
1111
@data = cache
1212
else
1313
Net::SSH.start(host, user, @options) do |ssh|
14-
@data = JSON.parse(ssh.exec!('ohai'))
14+
@data = JSON.parse(ssh.exec!("ohai"))
1515
end
1616

1717
# cache this data so we do not have to SSH again
18-
File.open(cache_file, 'w+') { |f| f.write(@data.to_json) }
18+
File.open(cache_file, "w+") { |f| f.write(@data.to_json) }
1919
end
2020

2121
yield(@data) if block_given?
@@ -45,7 +45,7 @@ def cache_key
4545
end
4646

4747
def cache_file
48-
File.expand_path(File.join(Fauxhai.root, 'tmp', cache_key))
48+
File.expand_path(File.join(Fauxhai.root, "tmp", cache_key))
4949
end
5050

5151
def force_cache_miss?
@@ -67,13 +67,14 @@ def to_s
6767

6868
def host
6969
@host ||= begin
70-
raise ArgumentError, ':host is a required option for Fauxhai.fetch' unless @options[:host]
70+
raise ArgumentError, ":host is a required option for Fauxhai.fetch" unless @options[:host]
71+
7172
@options.delete(:host)
7273
end
7374
end
7475

7576
def user
76-
@user ||= (@options.delete(:user) || ENV['USER'] || ENV['USERNAME']).chomp
77+
@user ||= (@options.delete(:user) || ENV["USER"] || ENV["USERNAME"]).chomp
7778
end
7879
end
7980
end

lib/fauxhai/mocker.rb

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
require 'json'
2-
require 'pathname'
3-
require 'open-uri'
1+
require "json"
2+
require "pathname"
3+
require "open-uri"
44

55
module Fauxhai
66
class Mocker
77
# The base URL for the GitHub project (raw)
8-
RAW_BASE = 'https://raw.githubusercontent.com/chefspec/fauxhai/master'.freeze
8+
RAW_BASE = "https://raw.githubusercontent.com/chefspec/fauxhai/master".freeze
99

1010
# A message about where to find a list of platforms
11-
PLATFORM_LIST_MESSAGE = 'A list of available platforms is available at https://github.com/chefspec/fauxhai/blob/master/PLATFORMS.md'.freeze
11+
PLATFORM_LIST_MESSAGE = "A list of available platforms is available at https://github.com/chefspec/fauxhai/blob/master/PLATFORMS.md".freeze
1212

1313
# Create a new Ohai Mock with fauxhai.
1414
#
@@ -58,7 +58,7 @@ def data
5858
FileUtils.mkdir_p(path.dirname)
5959

6060
begin
61-
File.open(filepath, 'w') { |f| f.write(response_body) }
61+
File.open(filepath, "w") { |f| f.write(response_body) }
6262
rescue Errno::EACCES # a pretty common problem in CI systems
6363
puts "Fetched '#{platform}/#{version}' from GitHub, but could not write to the local path: #{filepath}. Fix the local file permissions to avoid downloading this file every run."
6464
end
@@ -79,21 +79,21 @@ def data
7979
# and eventually remove them while giving end users ample warning.
8080
def parse_and_validate(unparsed_data)
8181
parsed_data = JSON.parse(unparsed_data)
82-
if parsed_data['deprecated']
83-
STDERR.puts "WARNING: Fauxhai platform data for #{parsed_data['platform']} #{parsed_data['platform_version']} is deprecated and will be removed in the 9.0 release 3/2021. #{PLATFORM_LIST_MESSAGE}"
82+
if parsed_data["deprecated"]
83+
STDERR.puts "WARNING: Fauxhai platform data for #{parsed_data["platform"]} #{parsed_data["platform_version"]} is deprecated and will be removed in the 9.0 release 3/2021. #{PLATFORM_LIST_MESSAGE}"
8484
end
8585
parsed_data
8686
end
8787

8888
def platform
8989
@options[:platform] ||= begin
9090
STDERR.puts "WARNING: you must specify a 'platform' and optionally a 'version' for your ChefSpec Runner and/or Fauxhai constructor, in the future omitting the platform will become a hard error. #{PLATFORM_LIST_MESSAGE}"
91-
'chefspec'
91+
"chefspec"
9292
end
9393
end
9494

9595
def platform_path
96-
File.join(Fauxhai.root, 'lib', 'fauxhai', 'platforms', platform)
96+
File.join(Fauxhai.root, "lib", "fauxhai", "platforms", platform)
9797
end
9898

9999
def version
@@ -103,13 +103,13 @@ def version
103103
@options[:version]
104104
else
105105
# Check if it's a prefix of an existing version.
106-
versions = Dir["#{platform_path}/*.json"].map {|path| File.basename(path, '.json') }
107-
unless @options[:version].to_s == ''
106+
versions = Dir["#{platform_path}/*.json"].map { |path| File.basename(path, ".json") }
107+
unless @options[:version].to_s == ""
108108
# If the provided version is nil or '', that means take anything,
109109
# otherwise run the prefix match with an extra \D to avoid the
110110
# case where "7.1" matches "7.10.0".
111111
prefix_re = /^#{Regexp.escape(@options[:version])}\D/
112-
versions.select! {|ver| ver =~ prefix_re }
112+
versions.select! { |ver| ver =~ prefix_re }
113113
end
114114

115115
if versions.empty?

lib/fauxhai/runner.rb

+27-27
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
require 'ohai'
2-
require 'ohai/plugins/chef'
1+
require "ohai"
2+
require "ohai/plugins/chef"
33

44
module Fauxhai
55
class Runner
66
def initialize(args)
77
@system = Ohai::System.new
88
@system.all_plugins
99

10-
case @system.data['platform']
11-
when 'windows', :windows
12-
require_relative 'runner/windows'
13-
self.singleton_class.send :include, ::Fauxhai::Runner::Windows
10+
case @system.data["platform"]
11+
when "windows", :windows
12+
require_relative "runner/windows"
13+
singleton_class.send :include, ::Fauxhai::Runner::Windows
1414
else
15-
require_relative 'runner/default'
16-
self.singleton_class.send :include, ::Fauxhai::Runner::Default
15+
require_relative "runner/default"
16+
singleton_class.send :include, ::Fauxhai::Runner::Default
1717
end
1818

1919
result = @system.data.dup.delete_if { |k, v| !whitelist_attributes.include?(k) }.merge(
20-
'languages' => languages,
21-
'counters' => counters,
22-
'current_user' => current_user,
23-
'domain' => domain,
24-
'hostname' => hostname,
25-
'machinename' => hostname,
26-
'fqdn' => fqdn,
27-
'ipaddress' => ipaddress,
28-
'keys' => keys,
29-
'macaddress' => macaddress,
30-
'network' => network,
31-
'uptime' => uptime,
32-
'uptime_seconds' => uptime_seconds,
33-
'idle' => uptime,
34-
'idletime_seconds' => uptime_seconds,
35-
'cpu' => cpu,
36-
'memory' => memory,
37-
'virtualization' => virtualization,
38-
'time' => time
20+
"languages" => languages,
21+
"counters" => counters,
22+
"current_user" => current_user,
23+
"domain" => domain,
24+
"hostname" => hostname,
25+
"machinename" => hostname,
26+
"fqdn" => fqdn,
27+
"ipaddress" => ipaddress,
28+
"keys" => keys,
29+
"macaddress" => macaddress,
30+
"network" => network,
31+
"uptime" => uptime,
32+
"uptime_seconds" => uptime_seconds,
33+
"idle" => uptime,
34+
"idletime_seconds" => uptime_seconds,
35+
"cpu" => cpu,
36+
"memory" => memory,
37+
"virtualization" => virtualization,
38+
"time" => time
3939
)
4040

4141
puts JSON.pretty_generate(result.sort.to_h)

0 commit comments

Comments
 (0)