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

WIP: Refactor network_route using resource api #262

Closed
wants to merge 15 commits into from
Closed
Prev Previous commit
Next Next commit
Finish unit tests for network_route provider
dhollinger authored and KeithWard committed Dec 8, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 8e53ffb14e2866f0dc636abf5b9382985b9bc3af
1 change: 0 additions & 1 deletion lib/puppet/provider/network_route/network_route.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'net/ip'
# require_relative '../../../puppet_x/voxpupuli/utils'
require 'puppet/resource_api/simple_provider'

# Implementation for the network_route type using the Resource API.
57 changes: 32 additions & 25 deletions spec/unit/puppet/provider/network_route/network_route_spec.rb
Original file line number Diff line number Diff line change
@@ -8,6 +8,14 @@ module Puppet::Provider::NetworkRoute; end
subject(:provider) { described_class.new }

let(:context) { instance_double('Puppet::ResourceApi::BaseContext', 'context') }
let(:routes) { instance_double('Net::IP::Route::Collection', 'routes') }
let(:netiproute) { instance_double('Net::IP::Route', prefix: 'route') }

before(:each) do
allow(Net::IP::Route).to receive(:new).with('should').and_return(netiproute)
allow(Net::IP::Route::Collection).to receive(:new).with('main').and_return(routes)
end

let(:route) do
[
{
@@ -67,38 +75,37 @@ module Puppet::Provider::NetworkRoute; end
end
end

describe 'create(context, name, should)' do
let(:should) { route[0] }

describe '#create(context, name, should)' do
before(:each) do
#allow(Net::IP::Route).to receive(:new).with(should).and_return(:new_route)
#allow(Net::IP).to receive_message_chain("routes.new").with(new_route).and_return(nil)
allow(provider).to receive(:puppet_munge).with(network_route[0]).and_return(should)
allow(provider).to receive(:puppet_munge).with('should').and_return('munged')
end

it 'creates the resource' do
# expect(context).to receive(:notice).with(%r{\ACreating 'a'})

# provider.create(context, 'a', name: 'a', ensure: 'present')
expect(Net::IP::Route).to receive(:new).with(should).and_return('')

provider.create(context, 'default', network_route[0])
it 'creates the resource' do
expect(routes).to receive(:add).with(netiproute)
provider.create(context, 'default', 'should')
end
end

# describe 'update(context, name, should)' do
# it 'updates the resource' do
# expect(context).to receive(:notice).with(%r{\AUpdating 'foo'})
describe '#update(context, name, should)' do
before(:each) do
allow(provider).to receive(:puppet_munge).with('should').and_return('munged')
end

# provider.update(context, 'foo', name: 'foo', ensure: 'present')
# end
# end
it 'updates the resource' do
expect(routes).to receive(:flush).with(netiproute.prefix)
expect(routes).to receive(:add).with(netiproute)
provider.update(context, 'default', 'should')
end
end

# describe 'delete(context, name, should)' do
# it 'deletes the resource' do
# expect(context).to receive(:notice).with(%r{\ADeleting 'foo'})
describe 'delete(context, name, should)' do
before(:each) do
allow(provider).to receive(:puppet_munge).with('should').and_return('munged')
end

# provider.delete(context, 'foo')
# end
# end
it 'deletes the resource' do
expect(routes).to receive(:flush).with(netiproute.prefix)
provider.delete(context, 'default', 'should')
end
end
end