spec for Type and Provider

This commit is contained in:
Sergey Vasilenko 2013-05-31 17:37:48 +04:00
parent 1c505200d1
commit 474e39a96f
4 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1 @@
.gemfile

View File

@ -20,4 +20,9 @@ Puppet::Type.type(:nova_floating).provide(:nova_manage) do
nova_manage("floating", "delete", resource[:network])
end
def parse
/([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})(\/([0-9]{1,2}))?/ =~ resource[:network]
[Regexp.last_match(1), Regexp.last_match(3)]
end
end

View File

@ -0,0 +1,38 @@
require 'spec_helper'
describe Puppet::Type.type(:nova_floating).provider(:nova_manage) do
let(:resource) { Puppet::Type.type(:nova_floating).new(:name => '192.168.1.1' ) }
let(:provider) { resource.provider }
describe "#create_by_name" do
it "should create floating" do
provider.parse().should == ["192.168.1.1", nil]
end
end
for net in ['10.0.0.1', '10.0.0.0/16'] do
describe "#create #{net}" do
it "should create floating for #{net}" do
resource[:network]= net
provider.expects(:nova_manage).with("floating", "create", net)
provider.create()
end
end
describe "#destroy #{net}" do
it "should destroy floating for #{net}" do
resource[:network]= net
provider.expects(:nova_manage).with("floating", "delete", net)
provider.destroy()
end
end
describe "#check masklen #{net}" do
it "should returns right values for #{net}" do
resource[:network]= net
/([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})(\/([0-9]{1,2}))?/ =~ net
provider.parse().should == [Regexp.last_match(1), Regexp.last_match(3)]
end
end
end
end

View File

@ -0,0 +1,26 @@
require 'puppet'
require 'puppet/type/nova_floating'
describe 'Puppet::Type.type(:nova_floating)' do
before :each do
@nova_floating = Puppet::Type.type(:nova_floating).new(:name => 'test_IP', :network => '192.168.1.2')
end
it 'should accept valid IP address' do
@nova_floating[:network] = '192.168.1.1'
@nova_floating[:network] == '192.168.1.1'
end
it 'should accept valid CIDR subnet' do
@nova_floating[:network] = '192.168.1.0/24'
@nova_floating[:network] == '192.168.1.0/24'
end
it 'should not accept masklen more 2 didits' do
expect {
@nova_floating[:network] = '192.168.1.0/245'
}.to raise_error(Puppet::Error, /Invalid value/)
end
it 'should not accept invalid ensure values' do
expect {
@nova_floating[:network] = 'qweqweqweqwe'
}.to raise_error(Puppet::Error, /Invalid value/)
end
end