forked from vmware-archive/vmware-vmware_lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
211 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
language: ruby | ||
bundler_args: --without development | ||
script: "bundle exec rake spec SPEC_OPTS='--format documentation'" | ||
rvm: | ||
- 1.9.3 | ||
- 1.8.7 | ||
- ruby-head | ||
env: | ||
- PUPPET_GEM_VERSION="~> 2.7" | ||
- PUPPET_GEM_VERSION=">= 3.0.0" | ||
matrix: | ||
allow_failures: | ||
- rvm: ruby-head | ||
exclude: | ||
- rvm: 1.9.3 | ||
env: PUPPET_GEM_VERSION="~> 2.7" | ||
- rvm: ruby-head | ||
env: PUPPET_GEM_VERSION="~> 2.7" | ||
notifications: | ||
email: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
source :rubygems | ||
|
||
gem 'hashdiff' | ||
|
||
group :development, :test do | ||
gem 'rake' | ||
gem 'rspec', "~> 2.11.0", :require => false | ||
gem 'mocha', "~> 0.10.5", :require => false | ||
gem 'puppetlabs_spec_helper', :require => false | ||
gem 'rspec-puppet', :require => false | ||
end | ||
|
||
if puppetversion = ENV['PUPPET_GEM_VERSION'] | ||
gem 'puppet', puppetversion, :require => false | ||
else | ||
gem 'puppet', :require => false | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# VMware Common Module | ||
|
||
Common resources for VMware modules. | ||
Common functionality for VMware modules. | ||
|
||
* Transport management for vCSA (ssh), vCenter (vSphere), vShield. | ||
* Puppet features for gems (deprecated in Puppet 3.0). | ||
* Shared Puppet functions and utility module. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'rubygems' | ||
require 'puppetlabs_spec_helper/rake_tasks' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'puppet_x/vmware/util' | ||
require 'puppetlabs_spec_helper/module_spec_helper' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env rspec | ||
|
||
require 'spec_helper' | ||
|
||
describe "the nested_value function" do | ||
let(:scope) { PuppetlabsSpec::PuppetInternals.scope } | ||
|
||
it "should exist" do | ||
Puppet::Parser::Functions.function("nested_value").should == "function_nested_value" | ||
end | ||
|
||
it "should raise a ParseError if there is not exactly 2 arguments" do | ||
lambda { scope.function_nested_value([1]) }.should( raise_error(Puppet::ParseError)) | ||
lambda { scope.function_nested_value([1, 2, 3]) }.should( raise_error(Puppet::ParseError)) | ||
end | ||
|
||
it "should raise a ParseError if second argument is not an Array" do | ||
lambda { scope.function_nested_value([{}, 1]) }.should( raise_error(Puppet::ParseError)) | ||
end | ||
|
||
it "should return :undef for a unavailable hash key" do | ||
result = scope.function_nested_value([{}, ['a', 'b']]) | ||
result.should(eq(:undef)) | ||
end | ||
|
||
it "should return correct value when available" do | ||
result = scope.function_nested_value([{'a'=>{'b'=>3}}, ['a','b']]) | ||
result.should(eq(3)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env rspec | ||
|
||
require 'spec_helper' | ||
require 'puppet/property/vmware' | ||
|
||
describe Puppet::Property::VMware do | ||
before(:each) do | ||
Puppet::Property::VMware.initvars | ||
@resource = stub 'resource', :[]= => nil, :property => nil | ||
@property = Puppet::Property::VMware.new(:resource => @resource) | ||
end | ||
|
||
it 'should camelize snake_case keys for a nested hash' do | ||
@property.camel_munge({'snake_case' => {'lower_case'=>'val'}}).should == {'snakeCase' => {'lowerCase' => 'val'}} | ||
end | ||
end | ||
|
||
# TODO: Have issues assigning property.should=(val) and testing insync? | ||
#describe Puppet::Property::VMware::Hash do | ||
#end | ||
# | ||
#describe Puppet::Property::VMware::Array do | ||
#end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env rspec | ||
|
||
require 'spec_helper' | ||
|
||
transport = Puppet::Type.type(:transport) | ||
|
||
describe transport do | ||
before :each do | ||
@transport = transport | ||
@provider = stub 'provider' | ||
|
||
@resource = @transport.new({ | ||
:name => 'telnet', | ||
:username => 'root', | ||
:password => 'pass', | ||
:server => '127.0.0.1', | ||
}) | ||
end | ||
|
||
it 'should have name as :namevar.' do | ||
@transport.key_attributes.should == [:name] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env rspec | ||
|
||
require 'spec_helper' | ||
require 'puppet_x/puppetlabs/transport' | ||
|
||
module PuppetX::Puppetlabs::Transport | ||
class Dummy | ||
attr_reader :name, :user, :password, :host | ||
|
||
def initialize(option) | ||
@name = option[:name] | ||
@user = option[:username] | ||
@password = option[:password] | ||
@host = option[:server] | ||
end | ||
|
||
def connect | ||
end | ||
|
||
end | ||
end | ||
|
||
|
||
describe PuppetX::Puppetlabs::Transport do | ||
|
||
before(:all) do | ||
@catalog = Puppet::Resource::Catalog.new | ||
('a'..'c').to_a.each do |x| | ||
@catalog.add_resource(Puppet::Type.type(:transport).new({ | ||
:name => "conn_#{x}", | ||
:username => "user_#{x}", | ||
:password => "pass_#{x}", | ||
:server => "server_#{x}", | ||
})) | ||
end | ||
end | ||
|
||
it 'should discover and initialize transport resource' do | ||
@dummy = PuppetX::Puppetlabs::Transport.retrieve(:resource_ref => "Transport[conn_a]", :catalog => @catalog, :provider => 'dummy') | ||
@dummy.class.should == PuppetX::Puppetlabs::Transport::Dummy | ||
@dummy.name.should == 'conn_a' | ||
@dummy.user.should == 'user_a' | ||
@dummy.password.should == 'pass_a' | ||
@dummy.host.should == 'server_a' | ||
end | ||
|
||
it 'should reuse transport resource' do | ||
dummy1 = PuppetX::Puppetlabs::Transport.retrieve(:resource_ref => "Transport[conn_a]", :catalog => @catalog, :provider => 'dummy') | ||
dummy2 = PuppetX::Puppetlabs::Transport.retrieve(:resource_ref => "Transport[conn_a]", :catalog => @catalog, :provider => 'dummy') | ||
dummy1.should == dummy2 | ||
end | ||
|
||
it 'should find existing transport resource' do | ||
dummy1 = PuppetX::Puppetlabs::Transport.retrieve(:resource_ref => "Transport[conn_a]", :catalog => @catalog, :provider => 'dummy') | ||
PuppetX::Puppetlabs::Transport.find('conn_a', 'dummy').should == dummy1 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env rspec | ||
|
||
require 'spec_helper' | ||
|
||
describe PuppetX::VMware::Util do | ||
it 'should camelize snake_case with capital default' do | ||
PuppetX::VMware::Util.camelize('snake_case').should == 'SnakeCase' | ||
end | ||
|
||
it 'should camelize snake_case with appropriate capitalization' do | ||
PuppetX::VMware::Util.camelize('snake_case', :lower).should == 'snakeCase' | ||
end | ||
|
||
it 'should snakeize CamelCase' do | ||
PuppetX::VMware::Util.snakeize('CamelCase').should == 'camel_case' | ||
end | ||
|
||
it 'should default nil for missing nested value' do | ||
PuppetX::VMware::Util.nested_value({'a'=>{'b'=>1}}, ['a', 'c']).should be_nil | ||
end | ||
|
||
it 'should accept block for missing nested value' do | ||
PuppetX::VMware::Util.nested_value({'a'=>{'b'=>1}}, ['a', 'c']){2}.should == 2 | ||
end | ||
|
||
it 'should retrieve nested value' do | ||
PuppetX::VMware::Util.nested_value({'a'=>{'b'=>1}}, ['a', 'b']).should == 1 | ||
end | ||
|
||
# TODO: nested_value_set | ||
end |