diff options
author | Noah Kantrowitz <noah@coderanger.net> | 2018-07-11 13:09:02 -0700 |
---|---|---|
committer | Noah Kantrowitz <noah@coderanger.net> | 2018-07-11 13:09:02 -0700 |
commit | d1783558c0b10b36b1fdc48724ca5c95e3833f56 (patch) | |
tree | 7628bb38a3a4d8150f5eb66557ed28a03712bd8b | |
parent | e28dd582903cb9846a718e00749ac218df563d42 (diff) | |
download | chef-d1783558c0b10b36b1fdc48724ca5c95e3833f56.tar.gz |
Feed the rubocop.
Signed-off-by: Noah Kantrowitz <noah@coderanger.net>
-rw-r--r-- | lib/chef/knife/config_list_profiles.rb | 10 | ||||
-rw-r--r-- | spec/integration/knife/config_list_profiles_spec.rb | 45 |
2 files changed, 28 insertions, 27 deletions
diff --git a/lib/chef/knife/config_list_profiles.rb b/lib/chef/knife/config_list_profiles.rb index 8780f5824a..16b0c5df27 100644 --- a/lib/chef/knife/config_list_profiles.rb +++ b/lib/chef/knife/config_list_profiles.rb @@ -87,14 +87,14 @@ class Chef def render_table(profiles, padding: 2) # Replace the home dir in the client key path with ~. profiles.each do |profile| - profile[:client_key] = profile[:client_key].to_s.gsub(/^#{Regexp.escape(Dir.home)}/, '~') if profile[:client_key] + profile[:client_key] = profile[:client_key].to_s.gsub(/^#{Regexp.escape(Dir.home)}/, "~") if profile[:client_key] end # Render the data to a 2D array that will be used for the table. - table_data = [['', 'Profile', 'Client', 'Key', 'Server']] + profiles.map do |profile| - [profile[:active] ? '*' : ''] + profile.values_at(:profile, :client_name, :client_key, :server_url).map(&:to_s) + table_data = [["", "Profile", "Client", "Key", "Server"]] + profiles.map do |profile| + [profile[:active] ? "*" : ""] + profile.values_at(:profile, :client_name, :client_key, :server_url).map(&:to_s) end # Compute column widths. - column_widths = table_data.first.length.times.map do |i| + column_widths = Array.new(table_data.first.length) do |i| table_data.map { |row| row[i].length + padding }.max end # Special case, the first col gets no padding (because indicator) and last @@ -102,7 +102,7 @@ class Chef column_widths[0] -= padding column_widths[-1] -= padding # Build the format string for each row. - format_string = column_widths.map { |w| "%-#{w}.#{w}s" }.join('') + format_string = column_widths.map { |w| "%-#{w}.#{w}s" }.join("") format_string << "\n" # Print the header row and a separator. table = ui.color(format_string % table_data.first, :green) diff --git a/spec/integration/knife/config_list_profiles_spec.rb b/spec/integration/knife/config_list_profiles_spec.rb index e261d3883f..4deb63677d 100644 --- a/spec/integration/knife/config_list_profiles_spec.rb +++ b/spec/integration/knife/config_list_profiles_spec.rb @@ -62,33 +62,33 @@ describe "knife config list-profiles", :workstation do # 2) Because of how the format strings are built, there is substantial trailing # whitespace in most cases which many editors "helpfully" remove. - context 'with no credentials file' do + context "with no credentials file" do subject { knife_list_profiles.stderr } it { is_expected.to eq "FATAL: No profiles found, #{path_to(".chef/credentials")} does not exist or is empty\n" } end - context 'with an empty credentials file' do - before { file('.chef/credentials', '') } + context "with an empty credentials file" do + before { file(".chef/credentials", "") } subject { knife_list_profiles.stderr } it { is_expected.to eq "FATAL: No profiles found, #{path_to(".chef/credentials")} does not exist or is empty\n" } end - context 'with a simple default profile' do - before { file('.chef/credentials', <<~EOH) } + context "with a simple default profile" do + before { file(".chef/credentials", <<~EOH) } [default] client_name = "testuser" client_key = "testkey.pem" chef_server_url = "https://example.com/organizations/testorg" EOH - it { is_expected.to eq <<-EOH.gsub(/#/, '') } + it { is_expected.to eq <<-EOH.delete("#") } Profile Client Key Server # ----------------------------------------------------------------------------------# *default testuser ~/.chef/testkey.pem https://example.com/organizations/testorg# EOH end - context 'with multiple profiles' do - before { file('.chef/credentials', <<~EOH) } + context "with multiple profiles" do + before { file(".chef/credentials", <<~EOH) } [default] client_name = "testuser" client_key = "testkey.pem" @@ -104,7 +104,7 @@ EOH client_key = "~/src/qauser.pem" chef_server_url = "https://example.com/organizations/testorg" EOH - it { is_expected.to eq <<-EOH.gsub(/#/, '') } + it { is_expected.to eq <<-EOH.delete("#") } Profile Client Key Server # ----------------------------------------------------------------------------------# *default testuser ~/.chef/testkey.pem https://example.com/organizations/testorg# @@ -113,9 +113,9 @@ EOH EOH end - context 'with a non-default active profile' do + context "with a non-default active profile" do let(:cmd_args) { %w{--profile prod} } - before { file('.chef/credentials', <<~EOH) } + before { file(".chef/credentials", <<~EOH) } [default] client_name = "testuser" client_key = "testkey.pem" @@ -131,7 +131,7 @@ EOH client_key = "~/src/qauser.pem" chef_server_url = "https://example.com/organizations/testorg" EOH - it { is_expected.to eq <<-EOH.gsub(/#/, '') } + it { is_expected.to eq <<-EOH.delete("#") } Profile Client Key Server # ----------------------------------------------------------------------------------# default testuser ~/.chef/testkey.pem https://example.com/organizations/testorg# @@ -140,21 +140,21 @@ EOH EOH end - context 'with a minimal profile' do - before { file('.chef/credentials', <<~EOH) } + context "with a minimal profile" do + before { file(".chef/credentials", <<~EOH) } [default] chef_server_url = "https://example.com/organizations/testorg" EOH it { is_expected.to match %r{^*default .*? https://example.com/organizations/testorg$} } end - context 'with -i' do + context "with -i" do let(:cmd_args) { %w{-i} } - before { file('.chef/credentials', <<~EOH) } + before { file(".chef/credentials", <<~EOH) } [default] chef_server_url = "https://example.com/organizations/testorg" EOH - it { is_expected.to eq <<-EOH.gsub(/#/, '') } + it { is_expected.to eq <<-EOH.delete("#") } Profile Client Key Server # ----------------------------------------------------------------# *default https://example.com/organizations/testorg# @@ -163,7 +163,7 @@ EOH context "with --format=json" do let(:cmd_args) { %w{--format=json node_name} } - before { file('.chef/credentials', <<~EOH) } + before { file(".chef/credentials", <<~EOH) } [default] client_name = "testuser" client_key = "testkey.pem" @@ -179,10 +179,11 @@ EOH client_key = "~/src/qauser.pem" chef_server_url = "https://example.com/organizations/testorg" EOH - it { expect(JSON.parse(subject)).to eq [ - {"profile" => "default", "active" => true, "client_name" => "testuser", "client_key" => path_to(".chef/testkey.pem"), "server_url" => "https://example.com/organizations/testorg"}, - {"profile" => "prod", "active" => false, "client_name" => "testuser", "client_key" => path_to(".chef/testkey.pem"), "server_url" => "https://example.com/organizations/prod"}, - {"profile" => "qa", "active" => false, "client_name" => "qauser", "client_key" => path_to("src/qauser.pem"), "server_url" => "https://example.com/organizations/testorg"}, + it { + expect(JSON.parse(subject)).to eq [ + { "profile" => "default", "active" => true, "client_name" => "testuser", "client_key" => path_to(".chef/testkey.pem"), "server_url" => "https://example.com/organizations/testorg" }, + { "profile" => "prod", "active" => false, "client_name" => "testuser", "client_key" => path_to(".chef/testkey.pem"), "server_url" => "https://example.com/organizations/prod" }, + { "profile" => "qa", "active" => false, "client_name" => "qauser", "client_key" => path_to("src/qauser.pem"), "server_url" => "https://example.com/organizations/testorg" }, ] } end end |