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

(FORGE-575) Updates for Faraday 1.x #86

Merged
merged 5 commits into from
Jan 28, 2021
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
Starting with v2.0.0, all notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## v3.0.0 - 2021-01-28

* Breaking: The `puppet_forge` gem now requires at least Ruby 2.4.0.
* Update `faraday` and `faraday_middleware` gem dependencies to 1.x series.
* Update optional `typhoeus` dependency to `>= 1.4` to maintain compatibility with `faraday`.

## v2.3.4 - 2020-03-31

* Update the forge API url to `forgeapi.puppet.com` (instead of using the older puppetlabs.com domain).
Expand Down
6 changes: 2 additions & 4 deletions lib/puppet_forge/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require 'faraday'
require 'faraday_middleware'
require 'puppet_forge/middleware/symbolify_json'

module PuppetForge
# Provide a common mixin for adding a HTTP connection to classes.
Expand Down Expand Up @@ -81,7 +80,7 @@ def default_connection(opts = {})

begin
# Use Typhoeus if available.
Gem::Specification.find_by_name('typhoeus', '~> 1.0.1')
Gem::Specification.find_by_name('typhoeus', '~> 1.4')
require 'typhoeus/adapters/faraday'
adapter = :typhoeus
rescue Gem::LoadError
Expand Down Expand Up @@ -114,8 +113,7 @@ def make_connection(url, adapter_args = nil, opts = {})
end

Faraday.new(url, options) do |builder|
builder.use PuppetForge::Middleware::SymbolifyJson
builder.response(:json, :content_type => /\bjson$/)
builder.response(:json, :content_type => /\bjson$/, :parser_options => { :symbolize_names => true })
builder.response(:raise_error)
builder.use(:connection_failure)

Expand Down
72 changes: 0 additions & 72 deletions lib/puppet_forge/middleware/symbolify_json.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/puppet_forge/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module PuppetForge
VERSION = '2.3.4' # Library version
VERSION = '3.0.0' # Library version
end
12 changes: 6 additions & 6 deletions puppet_forge.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.required_ruby_version = '>= 1.9.3'
spec.required_ruby_version = '>= 2.4.0'

spec.add_runtime_dependency "faraday", [">= 0.9.0", "< 0.18.0", "!= 0.13.1"]
spec.add_runtime_dependency "faraday_middleware", [">= 0.9.0", "< 0.15.0"]
spec.add_dependency 'semantic_puppet', '~> 1.0'
spec.add_dependency 'minitar'
spec.add_dependency 'gettext-setup', '~> 0.11'
spec.add_runtime_dependency "faraday", "~> 1.3"
spec.add_runtime_dependency "faraday_middleware", "~> 1.0"
spec.add_dependency "semantic_puppet", "~> 1.0"
spec.add_dependency "minitar"
spec.add_dependency "gettext-setup", "~> 0.11"

spec.add_development_dependency "rake"
spec.add_development_dependency "rspec", "~> 3.0"
Expand Down
3 changes: 1 addition & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ module StubbingFaraday
def stub_api_for(klass, base_url = "http://api.example.com")
allow(klass).to receive(:conn) do
Faraday.new :url => base_url do |builder|
builder.use PuppetForge::Middleware::SymbolifyJson
builder.response(:json, :content_type => /\bjson$/)
builder.response(:json, :content_type => /\bjson$/, :parser_options => { :symbolize_names => true })
builder.response(:raise_error)
builder.use(:connection_failure)

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/forge/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@

expect {
subject.get('/error')
}.to raise_error(Faraday::ClientError, "the server responded with status 503")
}.to raise_error(Faraday::ServerError, "the server responded with status 503")
end

context 'when an authorization value is provided' do
Expand Down
63 changes: 0 additions & 63 deletions spec/unit/forge/middleware/symbolify_json_spec.rb

This file was deleted.

40 changes: 0 additions & 40 deletions spec/unit/forge/v3/metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,6 @@

end

context "with a valid dependency", :pending => "dependency resolution is not yet in scope" do
let(:data) { {'dependencies' => [{'name' => 'puppetlabs-goodmodule'}] }}

it "adds the dependency" do
expect(subject.dependencies.size).to eq(1)
end
end

context "with a invalid dependency name" do
let(:data) { {'dependencies' => [{'name' => 'puppetlabsbadmodule'}] }}

Expand All @@ -184,45 +176,13 @@
end
end

context "with a valid dependency version range", :pending => "dependency resolution is not yet in scope" do
let(:data) { {'dependencies' => [{'name' => 'puppetlabs-badmodule', 'version_requirement' => '>= 2.0.0'}] }}

it "adds the dependency" do
expect(subject.dependencies.size).to eq(1)
end
end

context "with a invalid version range" do
let(:data) { {'dependencies' => [{'name' => 'puppetlabsbadmodule', 'version_requirement' => '>= banana'}] }}

it "raises an exception" do
expect { subject }.to raise_error(ArgumentError)
end
end

context "with duplicate dependencies", :pending => "dependency resolution is not yet in scope" do
let(:data) { {'dependencies' => [{'name' => 'puppetlabs-dupmodule', 'version_requirement' => '1.0.0'},
{'name' => 'puppetlabs-dupmodule', 'version_requirement' => '0.0.1'}] }
}

it "raises an exception" do
expect { subject }.to raise_error(ArgumentError)
end
end

context "adding a duplicate dependency", :pending => "dependency resolution is not yet in scope" do
let(:data) { {'dependencies' => [{'name' => 'puppetlabs-origmodule', 'version_requirement' => '1.0.0'}] }}

it "with a different version raises an exception" do
metadata.add_dependency('puppetlabs-origmodule', '>= 0.0.1')
expect { subject }.to raise_error(ArgumentError)
end

it "with the same version does not add another dependency" do
metadata.add_dependency('puppetlabs-origmodule', '1.0.0')
expect(subject.dependencies.size).to eq(1)
end
end
end

describe '#dashed_name' do
Expand Down