From 937e7063b2dd25d1b2e9f778efdfb13ad8f49fdb Mon Sep 17 00:00:00 2001 From: Harry Brundage Date: Fri, 23 Nov 2018 11:26:00 -0500 Subject: [PATCH] Fix lint issues on master (#379) * bundle exec rubocop --auto-correct * Lintfix: don't complain about the filename of the file named after the gem by convention * Appease the linter by using the method-level syntax for rescuing exceptions from a block --- .rubocop.yml | 5 +++++ kubernetes-deploy.gemspec | 4 ++-- .../kubeclient_builder/google_friendly_config.rb | 10 ++++------ test/integration/restart_task_test.rb | 12 ++++++------ 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index d35494138..9651f0ac9 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -9,3 +9,8 @@ Style/TrailingCommaInArrayLiteral: Style/TrailingCommaInHashLiteral: Enabled: false + +Naming/FileName: + Enabled: true + Exclude: + - lib/kubernetes-deploy.rb diff --git a/kubernetes-deploy.gemspec b/kubernetes-deploy.gemspec index 9de541854..f78d8721d 100644 --- a/kubernetes-deploy.gemspec +++ b/kubernetes-deploy.gemspec @@ -15,12 +15,12 @@ Gem::Specification.new do |spec| spec.homepage = "https://github.com/Shopify/kubernetes-deploy" spec.license = "MIT" - spec.files = `git ls-files -z`.split("\x0").reject do |f| + spec.files = %x(git ls-files -z).split("\x0").reject do |f| f.match(%r{^(test|spec|features)/}) end spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } - spec.require_paths = ["lib"] + spec.require_paths = %w(lib) spec.required_ruby_version = '>= 2.3.0' spec.add_dependency "activesupport", ">= 5.0" diff --git a/lib/kubernetes-deploy/kubeclient_builder/google_friendly_config.rb b/lib/kubernetes-deploy/kubeclient_builder/google_friendly_config.rb index d51cb959d..51566c88f 100644 --- a/lib/kubernetes-deploy/kubeclient_builder/google_friendly_config.rb +++ b/lib/kubernetes-deploy/kubeclient_builder/google_friendly_config.rb @@ -32,12 +32,10 @@ def new_token private def json_error_message(body) - json_error_msg = begin - JSON.parse(body || '') || {} - rescue JSON::ParserError - {} - end - json_error_msg['message'] + err = JSON.parse(body || '') || {} + err['message'] + rescue JSON::ParserError + nil end end end diff --git a/test/integration/restart_task_test.rb b/test/integration/restart_task_test.rb index 0df96d643..9a0c932f8 100644 --- a/test/integration/restart_task_test.rb +++ b/test/integration/restart_task_test.rb @@ -44,7 +44,7 @@ def test_restart_named_deployments_twice refute fetch_restarted_at("web"), "no RESTARTED_AT env on fresh deployment" restart = build_restart_task - assert_restart_success(restart.perform(["web"])) + assert_restart_success(restart.perform(%w(web))) assert_logs_match_all([ "Configured to restart deployments by name: web", @@ -61,7 +61,7 @@ def test_restart_named_deployments_twice assert first_restarted_at, "RESTARTED_AT is present after first restart" Timecop.freeze(1.second.from_now) do - assert_restart_success(restart.perform(["web"])) + assert_restart_success(restart.perform(%w(web))) end second_restarted_at = fetch_restarted_at("web") @@ -91,7 +91,7 @@ def test_restart_with_same_resource_twice def test_restart_not_existing_deployment restart = build_restart_task - assert_restart_failure(restart.perform(["web"])) + assert_restart_failure(restart.perform(%w(web))) assert_logs_match_all([ "Configured to restart deployments by name: web", "Result: FAILURE", @@ -131,7 +131,7 @@ def test_restart_not_existing_context namespace: @namespace, logger: logger ) - assert_restart_failure(restart.perform(["web"])) + assert_restart_failure(restart.perform(%w(web))) assert_logs_match_all([ "Result: FAILURE", "`walrus` context must be configured in your kubeconfig file(s)" @@ -145,7 +145,7 @@ def test_restart_not_existing_namespace namespace: "walrus", logger: logger ) - assert_restart_failure(restart.perform(["web"])) + assert_restart_failure(restart.perform(%w(web))) assert_logs_match_all([ "Result: FAILURE", "Namespace `walrus` not found in context `#{TEST_CONTEXT}`" @@ -203,7 +203,7 @@ def test_restart_successful_with_partial_availability assert_deploy_success(result) restart = build_restart_task - assert_restart_success(restart.perform(["web"])) + assert_restart_success(restart.perform(%w(web))) pods = kubeclient.get_pods(namespace: @namespace, label_selector: 'name=web,app=slow-cloud') new_pods = pods.select do |pod|