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

Remove pre-condition checks for RSAPI objects #943

Merged
merged 1 commit into from
Feb 17, 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
1 change: 0 additions & 1 deletion lib/pdk/generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module Generate
autoload :Provider, 'pdk/generate/provider'
autoload :PuppetClass, 'pdk/generate/puppet_class'
autoload :PuppetObject, 'pdk/generate/puppet_object'
autoload :ResourceAPIObject, 'pdk/generate/resource_api_object'
autoload :Task, 'pdk/generate/task'
autoload :Transport, 'pdk/generate/transport'

Expand Down
2 changes: 1 addition & 1 deletion lib/pdk/generate/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module PDK
module Generate
class Provider < ResourceAPIObject
class Provider < PuppetObject
def friendly_name
'Resource API Provider'.freeze
end
Expand Down
55 changes: 0 additions & 55 deletions lib/pdk/generate/resource_api_object.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/pdk/generate/transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module PDK
module Generate
class Transport < ResourceAPIObject
class Transport < PuppetObject
def friendly_name
'Resource API Transport'.freeze
end
Expand Down
137 changes: 42 additions & 95 deletions spec/acceptance/new_provider_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,115 +8,62 @@ def update_module!
context 'when run inside of a module' do
include_context 'in a new module', 'new_provider'

context 'with the Resource API configured in .sync.yml' do
before(:all) do
File.open('.sync.yml', 'w') do |f|
f.write(<<SYNC)
---
Gemfile:
optional:
':development':
- gem: 'puppet-resource_api'
spec/spec_helper.rb:
mock_with: ':rspec'
SYNC
end
update_module!
describe command('pdk new provider test_provider') do
its(:stdout) { is_expected.to match(%r{#{File.join('lib', 'puppet', 'type', 'test_provider.rb')}}) }
its(:stdout) { is_expected.to match(%r{#{File.join('lib', 'puppet', 'provider', 'test_provider', 'test_provider.rb')}}) }
its(:stdout) { is_expected.to match(%r{#{File.join('spec', 'unit', 'puppet', 'provider', 'test_provider', 'test_provider_spec.rb')}}) }
its(:stdout) { is_expected.to match(%r{#{File.join('spec', 'unit', 'puppet', 'type', 'test_provider_spec.rb')}}) }
its(:stderr) { is_expected.to have_no_output }
its(:exit_status) { is_expected.to eq(0) }

describe file(File.join('lib', 'puppet', 'type')) do
it { is_expected.to be_directory }
end

describe command('pdk new provider test_provider') do
its(:stdout) { is_expected.to match(%r{#{File.join('lib', 'puppet', 'type', 'test_provider.rb')}}) }
its(:stdout) { is_expected.to match(%r{#{File.join('lib', 'puppet', 'provider', 'test_provider', 'test_provider.rb')}}) }
its(:stdout) { is_expected.to match(%r{#{File.join('spec', 'unit', 'puppet', 'provider', 'test_provider', 'test_provider_spec.rb')}}) }
its(:stdout) { is_expected.to match(%r{#{File.join('spec', 'unit', 'puppet', 'type', 'test_provider_spec.rb')}}) }
its(:stderr) { is_expected.to have_no_output }
its(:exit_status) { is_expected.to eq(0) }

describe file(File.join('lib', 'puppet', 'type')) do
it { is_expected.to be_directory }
end

describe file(File.join('lib', 'puppet', 'type', 'test_provider.rb')) do
it { is_expected.to be_file }
its(:content) { is_expected.to match(%r{Puppet::ResourceApi.register_type}) }
its(:content) { is_expected.to match(%r{name: 'test_provider'}) }
end

describe file(File.join('lib', 'puppet', 'provider', 'test_provider')) do
it { is_expected.to be_directory }
end

describe file(File.join('lib', 'puppet', 'provider', 'test_provider', 'test_provider.rb')) do
it { is_expected.to be_file }
its(:content) { is_expected.to match(%r{class Puppet::Provider::TestProvider::TestProvider}) }
end

describe file(File.join('spec', 'unit', 'puppet', 'provider', 'test_provider')) do
it { is_expected.to be_directory }
end

describe file(File.join('spec', 'unit', 'puppet', 'provider', 'test_provider', 'test_provider_spec.rb')) do
it { is_expected.to be_file }
its(:content) { is_expected.to match(%r{RSpec.describe Puppet::Provider::TestProvider::TestProvider do}) }
end

describe file(File.join('spec', 'unit', 'puppet', 'type')) do
it { is_expected.to be_directory }
end
describe file(File.join('lib', 'puppet', 'type', 'test_provider.rb')) do
it { is_expected.to be_file }
its(:content) { is_expected.to match(%r{Puppet::ResourceApi.register_type}) }
its(:content) { is_expected.to match(%r{name: 'test_provider'}) }
end

describe file(File.join('spec', 'unit', 'puppet', 'type', 'test_provider_spec.rb')) do
it { is_expected.to be_file }
its(:content) { is_expected.to match(%r{RSpec.describe 'the test_provider type' do}) }
end
describe file(File.join('lib', 'puppet', 'provider', 'test_provider')) do
it { is_expected.to be_directory }
end

describe command('pdk validate ruby') do
its(:stdout) { is_expected.to have_no_output }
its(:stderr) { is_expected.to match(%r{using ruby \d+\.\d+\.\d+}i) }
its(:stderr) { is_expected.to match(%r{using puppet \d+\.\d+\.\d+}i) }
its(:exit_status) { is_expected.to eq(0) }
end
describe file(File.join('lib', 'puppet', 'provider', 'test_provider', 'test_provider.rb')) do
it { is_expected.to be_file }
its(:content) { is_expected.to match(%r{class Puppet::Provider::TestProvider::TestProvider}) }
end

describe command('pdk test unit') do
its(:stdout) { is_expected.to match(%r{0 failures}) }
its(:stdout) { is_expected.not_to match(%r{no examples found}i) }
its(:exit_status) { is_expected.to eq(0) }
end
describe file(File.join('spec', 'unit', 'puppet', 'provider', 'test_provider')) do
it { is_expected.to be_directory }
end
end

context 'without a .sync.yml' do
before(:all) do
FileUtils.rm_f('.sync.yml')
update_module!
describe file(File.join('spec', 'unit', 'puppet', 'provider', 'test_provider', 'test_provider_spec.rb')) do
it { is_expected.to be_file }
its(:content) { is_expected.to match(%r{RSpec.describe Puppet::Provider::TestProvider::TestProvider do}) }
end

describe command('pdk new provider test_provider2') do
its(:stderr) { is_expected.to match(%r{pdk \(ERROR\): .sync.yml not found}i) }
its(:stdout) { is_expected.to have_no_output }
its(:exit_status) { is_expected.not_to eq(0) }
describe file(File.join('spec', 'unit', 'puppet', 'type')) do
it { is_expected.to be_directory }
end
end

context 'with invalid .sync.yml' do
before(:all) do
File.open('.sync.yml', 'w') do |f|
f.write(<<SYNC)
---
Gemfile:
optional:
':test':
- gem: 'puppet-resource_api'
spec/spec_helper.rb:
mock_with: ':rspec'
SYNC
end
update_module!
describe file(File.join('spec', 'unit', 'puppet', 'type', 'test_provider_spec.rb')) do
it { is_expected.to be_file }
its(:content) { is_expected.to match(%r{RSpec.describe 'the test_provider type' do}) }
end

describe command('pdk new provider test_provider2') do
its(:stderr) { is_expected.to match(%r{pdk \(ERROR\): Gemfile.optional.:development configuration not found}i) }
describe command('pdk validate ruby') do
its(:stdout) { is_expected.to have_no_output }
its(:exit_status) { is_expected.not_to eq(0) }
its(:stderr) { is_expected.to match(%r{using ruby \d+\.\d+\.\d+}i) }
its(:stderr) { is_expected.to match(%r{using puppet \d+\.\d+\.\d+}i) }
its(:exit_status) { is_expected.to eq(0) }
end

describe command('pdk test unit') do
its(:stdout) { is_expected.to match(%r{0 failures}) }
its(:stdout) { is_expected.not_to match(%r{no examples found}i) }
its(:exit_status) { is_expected.to eq(0) }
end
end
end
Expand Down
Loading