Skip to content

Commit

Permalink
Initial test working but needs mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
dhollinger committed Jul 22, 2018
1 parent 89e8b1a commit 0cbeea1
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def location_for(place, fake_version = nil)
end

group :test do
gem 'puppetlabs_spec_helper', '~> 2.5.0', :require => false
gem 'puppetlabs_spec_helper', '~> 2.9.1', :require => false
gem 'rspec-puppet', '~> 2.5', :require => false
gem 'rspec-puppet-facts', :require => false
gem 'rspec-puppet-utils', :require => false
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
default_facts.merge!(YAML.load(File.read(File.expand_path('../default_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_facts.yml', __FILE__))
default_facts.merge!(YAML.load(File.read(File.expand_path('../default_module_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_module_facts.yml', __FILE__))
c.default_facts = default_facts
c.mock_with :mocha
c.mock_with :rspec
end

require 'spec_helper_methods'
Expand Down
89 changes: 62 additions & 27 deletions spec/unit/puppet/provider/network_route/network_route_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'spec_helper'

ensure_module_defined('Puppet::Provider::NetworkRoute')
# nsure_module_defined('Puppet::Provider::NetworkRoute')
module Puppet::Provider::NetworkRoute; end
require 'puppet/provider/network_route/network_route'

RSpec.describe Puppet::Provider::NetworkRoute::NetworkRoute do
Expand All @@ -11,39 +12,73 @@
describe '#get' do
it 'processes resources' do
expect(provider.get(context)).to eq [
{
name: 'foo',
ensure: 'present',
},
{
name: 'bar',
ensure: 'present',
},
{:ensure=>"present",
:prefix=>"default",
:default_route=>true,
:gateway=>"10.155.255.1",
:interface=>"wlp3s0",
:metric=>"600",
:protocol=>"dhcp"},
{:ensure=>"present",
:prefix=>"10.155.255.0/24",
:default_route=>false,
:interface=>"wlp3s0",
:metric=>"600",
:source=>"10.155.255.110",
:scope=>"link",
:protocol=>"kernel"},
{:ensure=>"present",
:prefix=>"169.254.0.0/16",
:default_route=>false,
:interface=>"virbr0",
:metric=>"1000",
:scope=>"link"},
{:ensure=>"present",
:prefix=>"172.17.0.0/16",
:default_route=>false,
:interface=>"docker0",
:source=>"172.17.0.1",
:scope=>"link",
:protocol=>"kernel"},
{:ensure=>"present",
:prefix=>"172.18.0.0/16",
:default_route=>false,
:interface=>"br-39a722eeac35",
:source=>"172.18.0.1",
:scope=>"link",
:protocol=>"kernel"},
{:ensure=>"present",
:prefix=>"192.168.122.0/24",
:default_route=>false,
:interface=>"virbr0",
:source=>"192.168.122.1",
:scope=>"link",
:protocol=>"kernel"}
]
end
end

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

provider.create(context, 'a', name: 'a', ensure: 'present')
end
end
# provider.create(context, 'a', name: 'a', ensure: 'present')
# 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
# it 'updates the resource' do
# expect(context).to receive(:notice).with(%r{\AUpdating 'foo'})

provider.update(context, 'foo', name: 'foo', ensure: 'present')
end
end
# provider.update(context, 'foo', name: 'foo', ensure: 'present')
# 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
# it 'deletes the resource' do
# expect(context).to receive(:notice).with(%r{\ADeleting 'foo'})

provider.delete(context, 'foo')
end
end
# provider.delete(context, 'foo')
# end
# end
end

0 comments on commit 0cbeea1

Please sign in to comment.