summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorS.Cavallo <smcavallo@hotmail.com>2018-10-27 14:43:01 -0400
committerLamont Granquist <lamont@scriptkiddie.org>2018-11-28 22:30:43 -0800
commit41a2966f10f8b5d4f193b53279881a8b4f7ab68b (patch)
tree984bc2fe829ff18d1850cd00892e77073f7f3c59
parent7b9ac1bbe15db184d1f8c26e65dd375e68d2073d (diff)
downloadchef-41a2966f10f8b5d4f193b53279881a8b4f7ab68b.tar.gz
chefstyle fixes ONLY
Signed-off-by: S.Cavallo <smcavallo@hotmail.com>
-rw-r--r--lib/chef/provider/package/snap.rb18
-rw-r--r--lib/chef/resource/snap_package.rb2
-rw-r--r--spec/unit/provider/package/snap_spec.rb20
-rw-r--r--spec/unit/resource/snap_package_spec.rb1
4 files changed, 18 insertions, 23 deletions
diff --git a/lib/chef/provider/package/snap.rb b/lib/chef/provider/package/snap.rb
index 090eded54f..35740e4f09 100644
--- a/lib/chef/provider/package/snap.rb
+++ b/lib/chef/provider/package/snap.rb
@@ -192,7 +192,7 @@ class Chef
"args" => ["info", path,]
}.to_json
- #json = call_snap_api('POST', '/v2/snapctl', body)
+ # json = call_snap_api('POST', '/v2/snapctl', body)
response = snapctl(["info", path])
Chef::Log.trace(response)
response.error!
@@ -204,7 +204,7 @@ class Chef
end
def install_snap_from_source(name, path)
- #json = call_snap_api('POST', '/v2/snapctl', body)
+ # json = call_snap_api('POST', '/v2/snapctl', body)
response = snapctl(["install", path])
Chef::Log.trace(response)
response.error!
@@ -237,14 +237,10 @@ class Chef
# @param path [String] Path to the package on disk
# @param content_length [Integer] byte size of the snap file
def generate_multipart_form_data(snap_name, action, options, path, content_length)
-
- # Get the bytes of the file on disk
- #content_length = IO.binread(path)
-
snap_options = []
- options.each do | k,v |
+ options.each do |k, v|
snap_option = <<~SNAP_OPTION
-Content-Disposition: form-data; name="#{k}"
+ Content-Disposition: form-data; name="#{k}"
#{v}
--#{snap_name}
@@ -253,7 +249,7 @@ Content-Disposition: form-data; name="#{k}"
end
multipart_form_data = <<~SNAP_S
-Host:
+ Host:
Content-Type: multipart/form-data; boundary=#{snap_name}
Content-Length: #{content_length}
@@ -281,9 +277,9 @@ Content-Disposition: form-data; name="snap"; filename="#{path}"
def generate_snap_json(snap_names, action, channel, options, revision = nil)
request = {
"action" => action,
- "snaps" => snap_names
+ "snaps" => snap_names,
}
- if %w(install refresh switch).include?(action)
+ if %w{install refresh switch}.include?(action)
request["channel"] = channel
end
diff --git a/lib/chef/resource/snap_package.rb b/lib/chef/resource/snap_package.rb
index f114234e65..4f2cdd3532 100644
--- a/lib/chef/resource/snap_package.rb
+++ b/lib/chef/resource/snap_package.rb
@@ -29,7 +29,7 @@ class Chef
property :channel, String,
description: "The default channel. For example: stable.",
default: "stable",
- equal_to: ["edge", "beta", "candidate", "stable"],
+ equal_to: %w{edge beta candidate stable},
desired_state: false
end
end
diff --git a/spec/unit/provider/package/snap_spec.rb b/spec/unit/provider/package/snap_spec.rb
index c239761552..89c2a649d9 100644
--- a/spec/unit/provider/package/snap_spec.rb
+++ b/spec/unit/provider/package/snap_spec.rb
@@ -61,7 +61,7 @@ describe Chef::Provider::Package::Snap do
describe "#define_resource_requirements" do
before do
- allow_any_instance_of(Chef::Provider::Package::Snap).to receive(:call_snap_api).with('GET', "/v2/snaps/#{package}").and_return(get_by_name_result_success)
+ allow_any_instance_of(Chef::Provider::Package::Snap).to receive(:call_snap_api).with("GET", "/v2/snaps/#{package}").and_return(get_by_name_result_success)
end
it "should raise an exception if a source is supplied but not found when :install" do
@@ -79,7 +79,7 @@ describe Chef::Provider::Package::Snap do
let(:source) { "/tmp/hello_20.snap" }
before do
- allow_any_instance_of(Chef::Provider::Package::Snap).to receive(:call_snap_api).with('GET', "/v2/snaps/#{package}").and_return(get_by_name_result_success)
+ allow_any_instance_of(Chef::Provider::Package::Snap).to receive(:call_snap_api).with("GET", "/v2/snaps/#{package}").and_return(get_by_name_result_success)
end
it "should create a current resource with the name of the new_resource" do
@@ -100,7 +100,7 @@ describe Chef::Provider::Package::Snap do
check_version("2.10")
end
- it 'generates multipart form data' do
+ it "generates multipart form data" do
expected = <<~SNAP_S
Host:
Content-Type: multipart/form-data; boundary=foo
@@ -121,12 +121,12 @@ describe Chef::Provider::Package::Snap do
--foo
SNAP_S
- options = {"devmode" => true}
+ options = {}
+ options["devmode"] = true
path = "hello-world_27.snap"
content_length = "20480"
result = provider.send(:generate_multipart_form_data, "foo", "install", options, path, content_length)
-puts result
expect(result).to eq(expected)
@@ -139,8 +139,8 @@ puts result
let(:source) { nil }
describe "gets the candidate version from the snap store" do
before do
- allow_any_instance_of(Chef::Provider::Package::Snap).to receive(:call_snap_api).with('GET', "/v2/find?name=#{package}").and_return(find_result_success)
- allow_any_instance_of(Chef::Provider::Package::Snap).to receive(:call_snap_api).with('GET', "/v2/snaps/#{package}").and_return(get_by_name_result_success)
+ allow_any_instance_of(Chef::Provider::Package::Snap).to receive(:call_snap_api).with("GET", "/v2/find?name=#{package}").and_return(find_result_success)
+ allow_any_instance_of(Chef::Provider::Package::Snap).to receive(:call_snap_api).with("GET", "/v2/snaps/#{package}").and_return(get_by_name_result_success)
end
def check_version(version)
@@ -158,8 +158,8 @@ puts result
describe "fails to get the candidate version from the snap store" do
before do
- allow_any_instance_of(Chef::Provider::Package::Snap).to receive(:call_snap_api).with('GET', "/v2/find?name=#{package}").and_return(find_result_fail)
- allow_any_instance_of(Chef::Provider::Package::Snap).to receive(:call_snap_api).with('GET', "/v2/snaps/#{package}").and_return(get_by_name_result_fail)
+ allow_any_instance_of(Chef::Provider::Package::Snap).to receive(:call_snap_api).with("GET", "/v2/find?name=#{package}").and_return(find_result_fail)
+ allow_any_instance_of(Chef::Provider::Package::Snap).to receive(:call_snap_api).with("GET", "/v2/snaps/#{package}").and_return(get_by_name_result_fail)
end
it "throws an error if candidate version not found" do
@@ -201,7 +201,7 @@ puts result
revision = nil
actual = provider.send(:generate_snap_json, snap_names, action, channel, options, revision)
- expect(actual).to eq({"action" => "install", "snaps" => ["hello"], "channel" => "stable"})
+ expect(actual).to eq("action" => "install", "snaps" => ["hello"], "channel" => "stable")
end
end
diff --git a/spec/unit/resource/snap_package_spec.rb b/spec/unit/resource/snap_package_spec.rb
index 2155645fcf..e625d6b2c3 100644
--- a/spec/unit/resource/snap_package_spec.rb
+++ b/spec/unit/resource/snap_package_spec.rb
@@ -48,7 +48,6 @@ describe Chef::Resource::SnapPackage, "initialize" do
end
it "channel defaults to stable" do
- "#{resource.channel("stable")}" # the default
expect(resource.channel).to eql("stable")
end