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

Updated rubocop using bundlelock. #752

Merged
merged 5 commits into from
Sep 25, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ Style/MethodCallWithArgsParentheses:
- raise
- puts
Exclude:
- Gemfile
- '**/Gemfile'

Style/MethodDefParentheses:
EnforcedStyle: require_parentheses
Expand Down Expand Up @@ -675,7 +675,7 @@ Style/LineEndConcatenation:
Style/MethodCallWithoutArgsParentheses:
Enabled: true

Style/MethodMissingSuper:
Lint/MissingSuper:
Enabled: true

Style/MissingRespondToMissing:
Expand Down Expand Up @@ -965,7 +965,7 @@ Lint/UselessAccessModifier:
Lint/UselessAssignment:
Enabled: true

Lint/UselessComparison:
Lint/BinaryOperatorWithIdenticalOperands:
Enabled: true

Lint/UselessElseWithoutRescue:
Expand Down
2 changes: 1 addition & 1 deletion krane.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency("byebug")
spec.add_development_dependency("ruby-prof")
spec.add_development_dependency("ruby-prof-flamegraph")
spec.add_development_dependency("rubocop", "~> 0.88.0")
spec.add_development_dependency("rubocop", "~> 0.89.1")
spec.add_development_dependency("codecov")
end
1 change: 1 addition & 0 deletions lib/krane/kubernetes_resource/persistent_volume_claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class StorageClass < KubernetesResource
attr_reader :name

def initialize(definition)
super(definition: definition, namespace: nil, context: nil, logger: nil)
@definition = definition
@name = definition.dig("metadata", "name").to_s
end
Expand Down
2 changes: 2 additions & 0 deletions test/helpers/fixture_sets/cronjobs.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# frozen_string_literal: true
# rubocop:disable Lint/MissingSuper

module FixtureSetAssertions
class CronJobs < FixtureSet
def initialize(namespace)
Expand Down
2 changes: 2 additions & 0 deletions test/helpers/fixture_sets/ejson_cloud.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# frozen_string_literal: true
# rubocop:disable Lint/MissingSuper

module FixtureSetAssertions
class EjsonCloud < FixtureSet
def initialize(namespace)
Expand Down
2 changes: 2 additions & 0 deletions test/helpers/fixture_sets/hello_cloud.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# frozen_string_literal: true
# rubocop:disable Lint/MissingSuper

module FixtureSetAssertions
class HelloCloud < FixtureSet
def initialize(namespace)
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/mock_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def after_sync
def type
"MockResource"
end
alias_method :kubectl_resource_type, :type
alias_method(:kubectl_resource_type, :type)

def group
"core"
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/task_runner_test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def deploy_task_template(subset = ["template-runner.yml", "configmap-data.yml"])
yield fixtures if block_given?
end
logging_assertion do |logs|
assert_equal true, result, "Deploy failed when it was expected to succeed: \n#{logs}"
assert_equal(true, result, "Deploy failed when it was expected to succeed: \n#{logs}")
end
end
reset_logger
Expand Down
18 changes: 9 additions & 9 deletions test/integration-serial/serial_deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_stage_related_metrics_include_custom_tags_from_namespace
hello_cloud = FixtureSetAssertions::HelloCloud.new(@namespace)
kubeclient.patch_namespace(hello_cloud.namespace, metadata: { labels: { foo: 'bar' } })
metrics = capture_statsd_calls(client: Krane::StatsD.client) do
assert_deploy_success deploy_fixtures("hello-cloud", subset: ["configmap-data.yml"], wait: false)
assert_deploy_success(deploy_fixtures("hello-cloud", subset: ["configmap-data.yml"], wait: false))
end

%w(
Expand All @@ -102,8 +102,8 @@ def test_stage_related_metrics_include_custom_tags_from_namespace

).each do |expected_metric|
metric = metrics.find { |m| m.name == expected_metric }
refute_nil metric, "Metric #{expected_metric} not emitted"
assert_includes metric.tags, "foo:bar", "Metric #{expected_metric} did not have custom tags"
refute_nil(metric, "Metric #{expected_metric} not emitted")
assert_includes(metric.tags, "foo:bar", "Metric #{expected_metric} did not have custom tags")
end
end

Expand All @@ -129,10 +129,10 @@ def test_all_expected_statsd_metrics_emitted_with_essential_tags
Krane.all_resources.duration
).each do |expected_metric|
metric = metrics.find { |m| m.name == expected_metric }
refute_nil metric, "Metric #{expected_metric} not emitted"
assert_includes metric.tags, "namespace:#{@namespace}", "#{metric.name} is missing namespace tag"
assert_includes metric.tags, "context:#{KubeclientHelper::TEST_CONTEXT}", "#{metric.name} is missing context tag"
assert_includes metric.tags, "sha:test-sha", "#{metric.name} is missing sha tag"
refute_nil(metric, "Metric #{expected_metric} not emitted")
assert_includes(metric.tags, "namespace:#{@namespace}", "#{metric.name} is missing namespace tag")
assert_includes(metric.tags, "context:#{KubeclientHelper::TEST_CONTEXT}", "#{metric.name} is missing context tag")
assert_includes(metric.tags, "sha:test-sha", "#{metric.name} is missing sha tag")
end
end

Expand All @@ -155,8 +155,8 @@ def test_global_deploy_emits_expected_statsd_metrics
Krane.all_resources.duration
).each do |expected_metric|
metric = metrics.find { |m| m.name == expected_metric }
refute_nil metric, "Metric #{expected_metric} not emitted"
assert_includes metric.tags, "context:#{KubeclientHelper::TEST_CONTEXT}", "#{metric.name} is missing context tag"
refute_nil(metric, "Metric #{expected_metric} not emitted")
assert_includes(metric.tags, "context:#{KubeclientHelper::TEST_CONTEXT}", "#{metric.name} is missing context tag")
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/integration/krane_deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ def test_long_running_deployment
by_revision = pods.group_by { |pod| pod.spec.containers.first.env.find { |var| var.name == "GITHUB_REV" }.value }
by_revision.each do |rev, rev_pods|
statuses = rev_pods.map { |pod| pod.status.to_h }
assert_equal 2, rev_pods.length, "#{rev} had #{rev_pods.length} pods (wanted 2). Statuses:\n#{statuses}"
assert_equal(2, rev_pods.length, "#{rev} had #{rev_pods.length} pods (wanted 2). Statuses:\n#{statuses}")
end
assert_logs_match(%r{Service/multi-replica\s+Selects at least 1 pod})
end
Expand Down
24 changes: 12 additions & 12 deletions test/integration/render_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_render_task
assert_render_success(render.run(stream: mock_output_stream))

stdout_assertion do |output|
assert_equal output, <<~RENDERED
assert_equal(output, <<~RENDERED)
---
apiVersion: v1
kind: ConfigMap
Expand Down Expand Up @@ -77,7 +77,7 @@ def test_render_task_multiple_templates
name: hello-cloud-configmap-data
key: datapoint2
RENDERED
assert_equal expected, output
assert_equal(expected, output)
end
end

Expand Down Expand Up @@ -160,7 +160,7 @@ def test_render_task_with_partials_and_bindings
supports_partials: "yep"

RENDERED
assert_equal expected, output
assert_equal(expected, output)
end
end

Expand Down Expand Up @@ -261,9 +261,9 @@ def test_render_valid_fixtures
render = build_render_task(
File.join(fixture_path('hello-cloud'), basename)
)
assert_render_success render.run(stream: mock_output_stream)
assert_render_success(render.run(stream: mock_output_stream))
stdout_assertion do |output|
assert !output.empty?
assert(!output.empty?)
end
end
end
Expand All @@ -277,7 +277,7 @@ def test_render_only_adds_initial_doc_separator_when_missing

assert_render_success(render.run(stream: mock_output_stream))
stdout_assertion do |output|
assert_equal "#{expected}#{expected}", output
assert_equal("#{expected}#{expected}", output)
end

mock_output_stream.rewind
Expand All @@ -298,7 +298,7 @@ def test_render_only_adds_initial_doc_separator_when_missing

assert_render_success(render.run(stream: mock_output_stream))
stdout_assertion do |output|
assert_equal expected, output
assert_equal(expected, output)
end
end

Expand All @@ -310,7 +310,7 @@ def test_render_preserves_duplicate_keys

assert_render_success(render.run(stream: mock_output_stream))
stdout_assertion do |output|
assert_equal expected, output
assert_equal(expected, output)
end
end

Expand All @@ -320,7 +320,7 @@ def test_render_does_not_generate_extra_blank_documents_when_file_is_empty
)
assert_render_success(render.run(stream: mock_output_stream))
stdout_assertion do |output|
assert_equal "", output.strip
assert_equal("", output.strip)
end
assert_logs_match("Rendered effectively_empty.yml.erb successfully, but the result was blank")
end
Expand All @@ -345,7 +345,7 @@ def test_render_k8s_compatibility
assert_render_success(render.run(stream: mock_output_stream))

stdout_assertion do |output|
assert_equal output, <<~RENDERED
assert_equal(output, <<~RENDERED)
---
apiVersion: apps/v1
kind: Deployment
Expand Down Expand Up @@ -402,14 +402,14 @@ def build_render_task(filenames, bindings = {})
def assert_render_success(result)
assert_equal(true, result, "Render failed when it was expected to succeed.#{logs_message_if_captured}")
logging_assertion do |logs|
assert_match Regexp.new("Result: SUCCESS"), logs, "'Result: SUCCESS' not found in the following logs:\n#{logs}"
assert_match(Regexp.new("Result: SUCCESS"), logs, "'Result: SUCCESS' not found in the following logs:\n#{logs}")
end
end

def assert_render_failure(result)
assert_equal(false, result, "Render succeeded when it was expected to fail.#{logs_message_if_captured}")
logging_assertion do |logs|
assert_match Regexp.new("Result: FAILURE"), logs, "'Result: FAILURE' not found in the following logs:\n#{logs}"
assert_match(Regexp.new("Result: FAILURE"), logs, "'Result: FAILURE' not found in the following logs:\n#{logs}")
end
end
end
8 changes: 4 additions & 4 deletions test/integration/runner_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_run_with_verify_result_fails_quickly_if_the_pod_is_deleted_out_of_band
retry
end
end
sleep 0.1
sleep(0.1)
end
end
deleter_thread.abort_on_exception = true
Expand Down Expand Up @@ -131,14 +131,14 @@ def test_run_with_verify_result_neither_misses_nor_duplicates_logs_across_pollin

first_num_printed = nums_printed[0].to_i
# The first time we fetch logs, we grab at most 250 lines, so we likely won't print the first few hundred
assert first_num_printed < 1500, "Unexpected number of initial logs skipped (started with #{first_num_printed})"
assert(first_num_printed < 1500, "Unexpected number of initial logs skipped (started with #{first_num_printed})")

expected_nums = (first_num_printed..5_000).map(&:to_s)
missing_nums = expected_nums - nums_printed.uniq
assert missing_nums.empty?, "Some lines were not streamed: #{missing_nums}"
assert(missing_nums.empty?, "Some lines were not streamed: #{missing_nums}")

num_lines_duplicated = nums_printed.length - nums_printed.uniq.length
assert num_lines_duplicated.zero?, "#{num_lines_duplicated} lines were duplicated"
assert(num_lines_duplicated.zero?, "#{num_lines_duplicated} lines were duplicated")
end
end

Expand Down
10 changes: 5 additions & 5 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ def assert_deploy_failure(result, cause = nil)
assert_equal(false, result, "Deploy succeeded when it was expected to fail.#{logs_message_if_captured}")
logging_assertion do |logs|
cause_string = cause == :timed_out ? "TIMED OUT" : "FAILURE"
assert_match Regexp.new("Result: #{cause_string}"), logs,
"'Result: #{cause_string}' not found in the following logs:\n#{logs}"
assert_match(Regexp.new("Result: #{cause_string}"), logs,
"'Result: #{cause_string}' not found in the following logs:\n#{logs}")
end
end
alias_method :assert_restart_failure, :assert_deploy_failure
Expand All @@ -124,7 +124,7 @@ def assert_deploy_failure(result, cause = nil)
def assert_deploy_success(result)
assert_equal(true, result, "Deploy failed when it was expected to succeed.#{logs_message_if_captured}")
logging_assertion do |logs|
assert_match Regexp.new("Result: SUCCESS"), logs, "'Result: SUCCESS' not found in the following logs:\n#{logs}"
assert_match(Regexp.new("Result: SUCCESS"), logs, "'Result: SUCCESS' not found in the following logs:\n#{logs}")
end
end
alias_method :assert_restart_success, :assert_deploy_success
Expand All @@ -139,7 +139,7 @@ def assert_logs_match(regexp, times = nil)

count = logs.scan(regexp).count
fail_msg = "Expected #{regexp} to appear #{times} time(s) in the log, but it appeared #{count} times"
assert_equal times, count, fail_msg
assert_equal(times, count, fail_msg)
end
end

Expand All @@ -161,7 +161,7 @@ def assert_logs_match_all(entry_list, in_order: false)
def refute_logs_match(regexp)
logging_assertion do |logs|
regexp = regexp.is_a?(Regexp) ? regexp : Regexp.new(Regexp.escape(regexp))
refute regexp =~ logs, "Expected '#{regexp}' not to appear in the following logs:\n#{logs}"
refute(regexp =~ logs, "Expected '#{regexp}' not to appear in the following logs:\n#{logs}")
end
end

Expand Down
8 changes: 4 additions & 4 deletions test/unit/cluster_resource_discovery_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ def test_prunable_global_resources

assert_equal(kinds.length, 12)
%w(PriorityClass StorageClass).each do |expected_kind|
assert kinds.one? { |k| k.include?(expected_kind) }
assert(kinds.one? { |k| k.include?(expected_kind) })
end
%w(node namespace).each do |black_lised_kind|
assert_empty kinds.select { |k| k.downcase.include?(black_lised_kind) }
assert_empty(kinds.select { |k| k.downcase.include?(black_lised_kind) })
end
end

Expand All @@ -52,7 +52,7 @@ def test_prunable_namespaced_resources

assert_equal(kinds.length, 25)
%w(ConfigMap CronJob Deployment).each do |expected_kind|
assert kinds.one? { |k| k.include?(expected_kind) }
assert(kinds.one? { |k| k.include?(expected_kind) })
end
end

Expand All @@ -63,7 +63,7 @@ def test_prunable_namespaced_resources_apply_group_version_kind_overrides
kinds = crd.prunable_resources(namespaced: true)

%w(batch/v1/Job extensions/v1beta1/Ingress).each do |expected_kind|
assert kinds.one? { |k| k.include?(expected_kind) }
assert(kinds.one? { |k| k.include?(expected_kind) })
end
end
end
16 changes: 8 additions & 8 deletions test/unit/krane/kubectl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_run_with_multiple_attempts_retries_and_emits_failure_metrics

metrics = capture_statsd_calls(client: Krane::StatsD.client) do
_out, _err, st = kubectl.run("get", "pods", attempts: 5)
refute_predicate st, :success?
refute_predicate(st, :success?)
end
assert_equal(5, metrics.length)
assert_equal(["Krane.kubectl.error"], metrics.map(&:name).uniq)
Expand Down Expand Up @@ -339,13 +339,13 @@ def test_retry_delay_backoff
ktl = build_kubectl
max_delay_range = ((Krane::Kubectl::MAX_RETRY_DELAY - 0.5)..Krane::Kubectl::MAX_RETRY_DELAY)
1000.times do
assert_includes 0.5..1, ktl.retry_delay(1)
assert_includes 1.5..2, ktl.retry_delay(2)
assert_includes 3.5..4, ktl.retry_delay(3)
assert_includes 7.5..8, ktl.retry_delay(4)
assert_includes max_delay_range, ktl.retry_delay(5)
assert_includes max_delay_range, ktl.retry_delay(6)
assert_includes max_delay_range, ktl.retry_delay(100)
assert_includes(0.5..1, ktl.retry_delay(1))
assert_includes(1.5..2, ktl.retry_delay(2))
assert_includes(3.5..4, ktl.retry_delay(3))
assert_includes(7.5..8, ktl.retry_delay(4))
assert_includes(max_delay_range, ktl.retry_delay(5))
assert_includes(max_delay_range, ktl.retry_delay(6))
assert_includes(max_delay_range, ktl.retry_delay(100))
end
end

Expand Down
Loading