Skip to content

Commit

Permalink
Enhancement of rubocop and tests configs (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
fwininger authored Apr 27, 2024
1 parent 4c130c9 commit d11771a
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.7', '3.1']
ruby-version: ['3.0', '3.1', '3.2', '3.3']
steps:
- name: checkout
uses: actions/checkout@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
uses: actions/checkout@v1
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1
ruby-version: 3.3
- name: test
run: make build test BUILD=local
- name: report gemfile name
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1
ruby-version: 3.3


- name: Run rubocop
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.7', '3.1']
ruby-version: ['3.0', '3.1', '3.2', '3.3']
registry-version: ['v1', 'v2']
steps:
- name: Setup ruby
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.7', '3.1']
ruby-version: ['3.0', '3.1', '3.2', '3.3']
registry-version: ['v1', 'v2']
steps:
- name: Setup ruby
Expand Down
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ AllCops:

Metrics/BlockLength:
Enabled: false

Metrics/MethodLength:
Enabled: false

inherit_from: .rubocop_todo.yml
50 changes: 0 additions & 50 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/DeprecatedAttributeAssignment:
Exclude:
- 'docker_registry2.gemspec'

# Offense count: 6
# Configuration parameters: EnforcedStyle, AllowedGems, Include.
# SupportedStyles: Gemfile, gems.rb, gemspec
Expand All @@ -22,14 +14,6 @@ Gemspec/DevelopmentDependencies:
Exclude:
- 'docker_registry2.gemspec'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/RequireMFA:
Exclude:
- 'docker_registry2.gemspec'

# Offense count: 1
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Expand All @@ -42,21 +26,6 @@ Lint/ShadowingOuterLocalVariable:
Exclude:
- 'test/test.rb'

# Offense count: 5
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AutoCorrect.
Lint/UselessAssignment:
Exclude:
- 'lib/registry/registry.rb'
- 'test/test.rb'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AutoCorrect, CheckForMethodsWithNoSideEffects.
Lint/Void:
Exclude:
- 'lib/registry/registry.rb'

# Offense count: 4
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Expand All @@ -67,11 +36,6 @@ Metrics/AbcSize:
Metrics/CyclomaticComplexity:
Max: 11

# Offense count: 8
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 34

# Offense count: 2
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/PerceivedComplexity:
Expand Down Expand Up @@ -101,27 +65,13 @@ Style/Documentation:
- 'lib/registry/blob.rb'
- 'lib/registry/registry.rb'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowedVars.
Style/FetchEnvVar:
Exclude:
- 'test/test.rb'

# Offense count: 2
# Configuration parameters: AllowedMethods.
# AllowedMethods: respond_to_missing?
Style/OptionalBooleanParameter:
Exclude:
- 'lib/registry/registry.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: Methods.
Style/RedundantArgument:
Exclude:
- 'lib/registry/registry.rb'

# Offense count: 8
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
Expand Down
4 changes: 2 additions & 2 deletions docker_registry2.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ Gem::Specification.new do |spec|
File.directory?(f)
end
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3'
spec.add_development_dependency 'rubocop', '>= 0.26.0'
spec.add_development_dependency 'rubocop', '>= 1.63.0'
spec.add_development_dependency 'vcr', '~> 6'
spec.add_development_dependency 'webmock'

spec.add_dependency 'rest-client', '>= 1.8.0'
spec.metadata['rubygems_mfa_required'] = 'true'
end
5 changes: 1 addition & 4 deletions lib/registry/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ def _pull_v2(repo, manifest, dir)
# download layer
# puts "getting layer (v2) #{layer['digest']}"
blob(repo, layer['digest'], layer_file)
layer_file
end
end

Expand All @@ -215,7 +214,6 @@ def _pull_v1(repo, manifest, dir)
# puts "getting layer (v1) #{layer['blobSum']}"
blob(repo, layer['blobSum'], layer_file)
# return layer file
layer_file
end
end

Expand All @@ -241,7 +239,6 @@ def blob_size(repo, blobSum)
# Parse the value of the Link HTTP header and return a Hash whose keys are the rel values turned into symbols, and
# the values are URLs. For example, `{ next: '/v2/_catalog?n=100&last=x' }`.
def parse_link_header(header)
last = ''
parts = header.split(',')
links = {}

Expand Down Expand Up @@ -301,7 +298,7 @@ def doreq(type, url, stream = nil, payload = nil)
raise DockerRegistry2::NotFound, "Image not found at #{@uri.host}"
rescue RestClient::Unauthorized => e
header = e.response.headers[:www_authenticate]
method = header.to_s.downcase.split(' ')[0]
method = header.to_s.downcase.split[0]
case method
when 'basic'
response = do_basic_req(type, url, stream, payload)
Expand Down
12 changes: 6 additions & 6 deletions test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def within_tmpdir
FileUtils.remove_entry_secure tmpdir
end

version = ENV['VERSION']
regurl = ENV['REGISTRY']
version = ENV.fetch('VERSION', nil)
regurl = ENV.fetch('REGISTRY', nil)
reg = DockerRegistry2.connect regurl

# do we have tags?
Expand Down Expand Up @@ -57,20 +57,20 @@ def within_tmpdir
# can we get the blob?
case version
when 'v1'
layer_blob = within_tmpdir do |tmpdir|
within_tmpdir do |tmpdir|
tmpfile = File.join(tmpdir, 'first_layer.blob')
reg.blob image, manifest['fsLayers'].first['blobSum'], tmpfile
end
when 'v2'
image_blob = reg.blob image, manifest['config']['digest']
layer_blob = within_tmpdir do |tmpdir|
reg.blob image, manifest['config']['digest']
within_tmpdir do |tmpdir|
tmpfile = File.join(tmpdir, 'first_layer.blob')
reg.blob image, manifest['layers'].first['digest'], tmpfile
end
end

# can we get the digest?
digest = reg.digest image, 'latest'
reg.digest image, 'latest'

# can we pull an image?
within_tmpdir { |tmpdir| reg.pull image, 'latest', tmpdir }
Expand Down

0 comments on commit d11771a

Please sign in to comment.