summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rwxr-xr-xspec/integration/agent/logging_spec.rb2
-rwxr-xr-xspec/integration/indirector/file_content/file_server_spec.rb5
-rwxr-xr-xspec/integration/node/environment_spec.rb28
-rwxr-xr-xspec/integration/resource/type_collection_spec.rb7
-rw-r--r--spec/lib/puppet_spec/modules.rb2
-rwxr-xr-xspec/spec_helper.rb6
-rw-r--r--spec/unit/face/module/list_spec.rb18
-rwxr-xr-xspec/unit/indirector/node/active_record_spec.rb2
-rwxr-xr-xspec/unit/indirector/node/ldap_spec.rb23
-rwxr-xr-xspec/unit/indirector/node/plain_spec.rb2
-rwxr-xr-xspec/unit/indirector/request_spec.rb23
-rwxr-xr-xspec/unit/module_spec.rb78
-rw-r--r--spec/unit/network/http/api/v2/environments_spec.rb19
-rwxr-xr-xspec/unit/node/environment_spec.rb22
-rwxr-xr-xspec/unit/node_spec.rb29
-rwxr-xr-xspec/unit/parser/ast/collection_spec.rb2
-rwxr-xr-xspec/unit/parser/ast/resource_spec.rb2
-rwxr-xr-xspec/unit/parser/compiler_spec.rb8
-rwxr-xr-xspec/unit/parser/files_spec.rb70
-rwxr-xr-xspec/unit/parser/functions_spec.rb12
-rwxr-xr-xspec/unit/parser/parser_spec.rb12
-rwxr-xr-xspec/unit/parser/resource_spec.rb12
-rwxr-xr-xspec/unit/parser/scope_spec.rb4
-rwxr-xr-xspec/unit/parser/type_loader_spec.rb4
-rwxr-xr-xspec/unit/rails/host_spec.rb2
-rwxr-xr-xspec/unit/resource/type_collection_spec.rb75
-rwxr-xr-xspec/unit/resource/type_spec.rb5
-rwxr-xr-xspec/unit/resource_spec.rb70
-rwxr-xr-xspec/unit/util/autoload_spec.rb33
29 files changed, 255 insertions, 322 deletions
diff --git a/spec/integration/agent/logging_spec.rb b/spec/integration/agent/logging_spec.rb
index 284928ed7..c686397c8 100755
--- a/spec/integration/agent/logging_spec.rb
+++ b/spec/integration/agent/logging_spec.rb
@@ -94,7 +94,7 @@ describe 'agent logging' do
#
# It's not something we are specifically testing here since it occurs
# regardless of user flags.
- Puppet::Util::Log.expects(:newdestination).with(instance_of(Puppet::Transaction::Report)).once
+ Puppet::Util::Log.expects(:newdestination).with(instance_of(Puppet::Transaction::Report)).at_least_once
expected[:loggers].each do |logclass|
Puppet::Util::Log.expects(:newdestination).with(logclass).at_least_once
end
diff --git a/spec/integration/indirector/file_content/file_server_spec.rb b/spec/integration/indirector/file_content/file_server_spec.rb
index bfa2f2017..d35d60b44 100755
--- a/spec/integration/indirector/file_content/file_server_spec.rb
+++ b/spec/integration/indirector/file_content/file_server_spec.rb
@@ -28,10 +28,9 @@ describe Puppet::Indirector::FileContent::FileServer, " when finding files" do
Puppet.settings[:modulepath] = "/no/such/file"
- env = Puppet::Node::Environment.new("foo")
- env.stubs(:modulepath).returns [path]
+ env = Puppet::Node::Environment.create(:foo, [path], '')
- result = Puppet::FileServing::Content.indirection.search("plugins", :environment => "foo", :recurse => true)
+ result = Puppet::FileServing::Content.indirection.search("plugins", :environment => env, :recurse => true)
result.should_not be_nil
result.length.should == 2
diff --git a/spec/integration/node/environment_spec.rb b/spec/integration/node/environment_spec.rb
index c7d9c91a1..105c70944 100755
--- a/spec/integration/node/environment_spec.rb
+++ b/spec/integration/node/environment_spec.rb
@@ -7,6 +7,13 @@ require 'puppet_spec/scope'
describe Puppet::Node::Environment do
include PuppetSpec::Files
+ def a_module_in(name, dir)
+ Dir.mkdir(dir)
+ moddir = File.join(dir, name)
+ Dir.mkdir(moddir)
+ moddir
+ end
+
it "should be able to return each module from its environment with the environment, name, and path set correctly" do
base = tmpfile("env_modules")
Dir.mkdir(base)
@@ -16,15 +23,11 @@ describe Puppet::Node::Environment do
%w{1 2}.each do |num|
dir = File.join(base, "dir#{num}")
dirs << dir
- Dir.mkdir(dir)
- mod = "mod#{num}"
- moddir = File.join(dir, mod)
- mods[mod] = moddir
- Dir.mkdir(moddir)
+
+ mods["mod#{num}"] = a_module_in("mod#{num}", dir)
end
- environment = Puppet::Node::Environment.new("foo")
- environment.stubs(:modulepath).returns dirs
+ environment = Puppet::Node::Environment.create(:foo, dirs, '')
environment.modules.each do |mod|
mod.environment.should == environment
@@ -37,19 +40,14 @@ describe Puppet::Node::Environment do
Dir.mkdir(base)
dirs = []
- mods = {}
%w{1 2}.each do |num|
dir = File.join(base, "dir#{num}")
dirs << dir
- Dir.mkdir(dir)
- mod = "mod"
- moddir = File.join(dir, mod)
- mods[mod] = moddir
- Dir.mkdir(moddir)
+
+ a_module_in("mod", dir)
end
- environment = Puppet::Node::Environment.new("foo")
- environment.stubs(:modulepath).returns dirs
+ environment = Puppet::Node::Environment.create(:foo, dirs, '')
mods = environment.modules
mods.length.should == 1
diff --git a/spec/integration/resource/type_collection_spec.rb b/spec/integration/resource/type_collection_spec.rb
index db2612ed0..6349460be 100755
--- a/spec/integration/resource/type_collection_spec.rb
+++ b/spec/integration/resource/type_collection_spec.rb
@@ -10,11 +10,10 @@ describe Puppet::Resource::TypeCollection do
before do
@dir = tmpfile("autoload_testing")
- Puppet[:modulepath] = @dir
-
FileUtils.mkdir_p @dir
- @code = Puppet::Resource::TypeCollection.new("env")
- Puppet::Node::Environment.new("env").stubs(:known_resource_types).returns @code
+
+ environment = Puppet::Node::Environment.create(:env, [@dir], '')
+ @code = environment.known_resource_types
end
# Setup a module.
diff --git a/spec/lib/puppet_spec/modules.rb b/spec/lib/puppet_spec/modules.rb
index 1b75bb23a..6835e4434 100644
--- a/spec/lib/puppet_spec/modules.rb
+++ b/spec/lib/puppet_spec/modules.rb
@@ -4,7 +4,7 @@ module PuppetSpec::Modules
module_dir = File.join(dir, name)
FileUtils.mkdir_p(module_dir)
- environment = Puppet::Node::Environment.new(options[:environment])
+ environment = options[:environment]
if metadata = options[:metadata]
metadata[:source] ||= 'github'
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 9b7af8552..ee7b37d8a 100755
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -164,10 +164,10 @@ RSpec.configure do |config|
config.instance_variable_get(:@files_to_run).each { |f| logfile.puts f }
end
end
- # Clean up switch of TMPDIR, don't know if needed after this, so needs to reset it
- # to old before removing it
+
+ # return to original tmpdir
ENV['TMPDIR'] = oldtmpdir
- FileUtils.rm_rf(tmpdir) if Puppet::FileSystem.exist?(tmpdir) && tmpdir.to_s.start_with?(oldtmpdir)
+ FileUtils.rm_rf(tmpdir)
end
if ENV['PROFILE']
diff --git a/spec/unit/face/module/list_spec.rb b/spec/unit/face/module/list_spec.rb
index 8ac7e8523..9fc4e7121 100644
--- a/spec/unit/face/module/list_spec.rb
+++ b/spec/unit/face/module/list_spec.rb
@@ -39,15 +39,17 @@ describe "puppet module list" do
barmod1 = PuppetSpec::Modules.create('bar', @modpath1)
foomod2 = PuppetSpec::Modules.create('foo', @modpath2)
- env = Puppet::Node::Environment.new
+ usedenv = Puppet::Node::Environment.create(:useme, [@modpath1, @modpath2], '')
- Puppet::Face[:module, :current].list.should == {
- @modpath1 => [
- Puppet::Module.new('bar', barmod1.path, env),
- Puppet::Module.new('foo', foomod1.path, env)
- ],
- @modpath2 => [Puppet::Module.new('foo', foomod2.path, env)]
- }
+ Puppet.override(:environments => Puppet::Environments::Static.new(usedenv)) do
+ Puppet::Face[:module, :current].list(:environment => 'useme').should == {
+ @modpath1 => [
+ Puppet::Module.new('bar', barmod1.path, usedenv),
+ Puppet::Module.new('foo', foomod1.path, usedenv)
+ ],
+ @modpath2 => [Puppet::Module.new('foo', foomod2.path, usedenv)]
+ }
+ end
end
it "should use the specified environment" do
diff --git a/spec/unit/indirector/node/active_record_spec.rb b/spec/unit/indirector/node/active_record_spec.rb
index 2365dcb3b..ac3c98bc4 100755
--- a/spec/unit/indirector/node/active_record_spec.rb
+++ b/spec/unit/indirector/node/active_record_spec.rb
@@ -9,7 +9,7 @@ describe "Puppet::Node::ActiveRecord", :if => Puppet.features.rails? && Puppet.f
let(:nodename) { "mynode" }
let(:fact_values) { {:afact => "a value"} }
let(:facts) { Puppet::Node::Facts.new(nodename, fact_values) }
- let(:environment) { Puppet::Node::Environment.new("myenv") }
+ let(:environment) { Puppet::Node::Environment.create(:myenv, [], '') }
let(:request) { Puppet::Indirector::Request.new(:node, :find, nodename, nil, :environment => environment) }
let(:node_indirection) { Puppet::Node::ActiveRecord.new }
diff --git a/spec/unit/indirector/node/ldap_spec.rb b/spec/unit/indirector/node/ldap_spec.rb
index 42c08f72b..c19a30150 100755
--- a/spec/unit/indirector/node/ldap_spec.rb
+++ b/spec/unit/indirector/node/ldap_spec.rb
@@ -6,7 +6,7 @@ require 'puppet/indirector/node/ldap'
describe Puppet::Node::Ldap do
let(:nodename) { "mynode.domain.com" }
let(:node_indirection) { Puppet::Node::Ldap.new }
- let(:environment) { Puppet::Node::Environment.new("myenv") }
+ let(:environment) { Puppet::Node::Environment.create(:myenv, [], '') }
let(:fact_values) { {:afact => "a value", "one" => "boo"} }
let(:facts) { Puppet::Node::Facts.new(nodename, fact_values) }
@@ -176,10 +176,13 @@ describe Puppet::Node::Ldap do
end
it "should set the node's environment to the environment of the results" do
- result_env = Puppet::Node::Environment.new("local_test")
+ result_env = Puppet::Node::Environment.create(:local_test, [], '')
Puppet::Node::Facts.indirection.stubs(:find).with(nodename, :environment => result_env).returns(facts)
@result[:environment] = "local_test"
- node_indirection.find(request).environment.should == result_env
+
+ Puppet.override(:environments => Puppet::Environments::Static.new(result_env)) do
+ node_indirection.find(request).environment.should == result_env
+ end
end
it "should retain false parameter values" do
@@ -256,17 +259,20 @@ describe Puppet::Node::Ldap do
end
it "should use the parent's environment if the node has none" do
- env = Puppet::Node::Environment.new("parent")
+ env = Puppet::Node::Environment.create(:parent, [], '')
@entry[:parent] = "parent"
@parent[:environment] = "parent"
Puppet::Node::Facts.indirection.stubs(:find).with(nodename, :environment => env).returns(facts)
- node_indirection.find(request).environment.should == env
+
+ Puppet.override(:environments => Puppet::Environments::Static.new(env)) do
+ node_indirection.find(request).environment.should == env
+ end
end
it "should prefer the node's environment to the parent's" do
- child_env = Puppet::Node::Environment.new("child")
+ child_env = Puppet::Node::Environment.create(:child, [], '')
@entry[:parent] = "parent"
@entry[:environment] = "child"
@@ -274,7 +280,10 @@ describe Puppet::Node::Ldap do
Puppet::Node::Facts.indirection.stubs(:find).with(nodename, :environment => child_env).returns(facts)
- node_indirection.find(request).environment.should == child_env
+ Puppet.override(:environments => Puppet::Environments::Static.new(child_env)) do
+
+ node_indirection.find(request).environment.should == child_env
+ end
end
it "should recursively look up parent information" do
diff --git a/spec/unit/indirector/node/plain_spec.rb b/spec/unit/indirector/node/plain_spec.rb
index 15cef217d..8e1d0decf 100755
--- a/spec/unit/indirector/node/plain_spec.rb
+++ b/spec/unit/indirector/node/plain_spec.rb
@@ -7,7 +7,7 @@ describe Puppet::Node::Plain do
let(:nodename) { "mynode" }
let(:fact_values) { {:afact => "a value"} }
let(:facts) { Puppet::Node::Facts.new(nodename, fact_values) }
- let(:environment) { Puppet::Node::Environment.new("myenv") }
+ let(:environment) { Puppet::Node::Environment.create(:myenv, [], '') }
let(:request) { Puppet::Indirector::Request.new(:node, :find, nodename, nil, :environment => environment) }
let(:node_indirection) { Puppet::Node::Plain.new }
diff --git a/spec/unit/indirector/request_spec.rb b/spec/unit/indirector/request_spec.rb
index 859d5ba0b..e0d9df339 100755
--- a/spec/unit/indirector/request_spec.rb
+++ b/spec/unit/indirector/request_spec.rb
@@ -218,21 +218,28 @@ describe Puppet::Indirector::Request do
Puppet::Indirector::Request.new(:myind, :find, "my key", nil).escaped_key.should == URI.escape("my key")
end
- it "should have an environment accessor" do
- Puppet::Indirector::Request.new(:myind, :find, "my key", nil, :environment => "foo").should respond_to(:environment)
- end
-
it "should set its environment to an environment instance when a string is specified as its environment" do
- Puppet::Indirector::Request.new(:myind, :find, "my key", nil, :environment => "foo").environment.should == Puppet::Node::Environment.new("foo")
+ env = Puppet::Node::Environment.create(:foo, [], '')
+
+ Puppet.override(:environments => Puppet::Environments::Static.new(env)) do
+ Puppet::Indirector::Request.new(:myind, :find, "my key", nil, :environment => "foo").environment.should == env
+ end
end
it "should use any passed in environment instances as its environment" do
- env = Puppet::Node::Environment.new("foo")
+ env = Puppet::Node::Environment.create(:foo, [], '')
+
Puppet::Indirector::Request.new(:myind, :find, "my key", nil, :environment => env).environment.should equal(env)
end
- it "should use the default environment when none is provided" do
- Puppet::Indirector::Request.new(:myind, :find, "my key", nil ).environment.should equal(Puppet::Node::Environment.new)
+ it "should use the configured environment when none is provided" do
+ configured = Puppet::Node::Environment.create(:foo, [], '')
+
+ Puppet[:environment] = "foo"
+
+ Puppet.override(:environments => Puppet::Environments::Static.new(configured)) do
+ Puppet::Indirector::Request.new(:myind, :find, "my key", nil).environment.should == configured
+ end
end
it "should support converting its options to a hash" do
diff --git a/spec/unit/module_spec.rb b/spec/unit/module_spec.rb
index 2a0945468..8e3c46989 100755
--- a/spec/unit/module_spec.rb
+++ b/spec/unit/module_spec.rb
@@ -97,7 +97,6 @@ describe Puppet::Module do
it "should list modules that are missing" do
metadata_file = "#{@modpath}/needy/metadata.json"
- Puppet::FileSystem.expects(:exist?).twice.with(metadata_file).returns true
mod = PuppetSpec::Modules.create(
'needy',
@modpath,
@@ -119,7 +118,6 @@ describe Puppet::Module do
it "should list modules that are missing and have invalid names" do
metadata_file = "#{@modpath}/needy/metadata.json"
- Puppet::FileSystem.expects(:exist?).with(metadata_file).twice.returns true
mod = PuppetSpec::Modules.create(
'needy',
@modpath,
@@ -140,42 +138,43 @@ describe Puppet::Module do
end
it "should list modules with unmet version requirement" do
- ['foobar', 'foobaz'].each do |mod_name|
- metadata_file = "#{@modpath}/#{mod_name}/metadata.json"
- Puppet::FileSystem.stubs(:exist?).with(metadata_file).returns true
- end
+ env = Puppet::Node::Environment.create(:testing, [@modpath], '')
+
mod = PuppetSpec::Modules.create(
- 'foobar',
+ 'test_gte_req',
@modpath,
:metadata => {
:dependencies => [{
"version_requirement" => ">= 2.2.0",
"name" => "baz/foobar"
}]
- }
+ },
+ :environment => env
)
mod2 = PuppetSpec::Modules.create(
- 'foobaz',
+ 'test_specific_req',
@modpath,
:metadata => {
:dependencies => [{
"version_requirement" => "1.0.0",
"name" => "baz/foobar"
}]
- }
+ },
+ :environment => env
)
PuppetSpec::Modules.create(
'foobar',
@modpath,
- :metadata => { :version => '2.0.0', :author => 'baz' }
+ :metadata => { :version => '2.0.0', :author => 'baz' },
+ :environment => env
)
mod.unmet_dependencies.should == [{
:reason => :version_mismatch,
:name => "baz/foobar",
:version_constraint => ">= 2.2.0",
- :parent => { :version => "v9.9.9", :name => "puppetlabs/foobar" },
+ :parent => { :version => "v9.9.9", :name => "puppetlabs/test_gte_req" },
:mod_details => { :installed_version => "2.0.0" }
}]
@@ -183,13 +182,15 @@ describe Puppet::Module do
:reason => :version_mismatch,
:name => "baz/foobar",
:version_constraint => "v1.0.0",
- :parent => { :version => "v9.9.9", :name => "puppetlabs/foobaz" },
+ :parent => { :version => "v9.9.9", :name => "puppetlabs/test_specific_req" },
:mod_details => { :installed_version => "2.0.0" }
}]
end
it "should consider a dependency without a version requirement to be satisfied" do
+ env = Puppet::Node::Environment.create(:testing, [@modpath], '')
+
mod = PuppetSpec::Modules.create(
'foobar',
@modpath,
@@ -197,7 +198,8 @@ describe Puppet::Module do
:dependencies => [{
"name" => "baz/foobar"
}]
- }
+ },
+ :environment => env
)
PuppetSpec::Modules.create(
'foobar',
@@ -205,15 +207,16 @@ describe Puppet::Module do
:metadata => {
:version => '2.0.0',
:author => 'baz'
- }
+ },
+ :environment => env
)
mod.unmet_dependencies.should be_empty
end
it "should consider a dependency without a semantic version to be unmet" do
- metadata_file = "#{@modpath}/foobar/metadata.json"
- Puppet::FileSystem.expects(:exist?).with(metadata_file).times(3).returns true
+ env = Puppet::Node::Environment.create(:testing, [@modpath], '')
+
mod = PuppetSpec::Modules.create(
'foobar',
@modpath,
@@ -221,7 +224,8 @@ describe Puppet::Module do
:dependencies => [{
"name" => "baz/foobar"
}]
- }
+ },
+ :environment => env
)
PuppetSpec::Modules.create(
'foobar',
@@ -229,7 +233,8 @@ describe Puppet::Module do
:metadata => {
:version => '5.1',
:author => 'baz'
- }
+ },
+ :environment => env
)
mod.unmet_dependencies.should == [{
@@ -254,10 +259,8 @@ describe Puppet::Module do
end
it "should only list unmet dependencies" do
- [name, 'satisfied'].each do |mod_name|
- metadata_file = "#{@modpath}/#{mod_name}/metadata.json"
- Puppet::FileSystem.expects(:exist?).with(metadata_file).twice.returns true
- end
+ env = Puppet::Node::Environment.create(:testing, [@modpath], '')
+
mod = PuppetSpec::Modules.create(
name,
@modpath,
@@ -272,7 +275,8 @@ describe Puppet::Module do
"name" => "baz/notsatisfied"
}
]
- }
+ },
+ :environment => env
)
PuppetSpec::Modules.create(
'satisfied',
@@ -280,7 +284,8 @@ describe Puppet::Module do
:metadata => {
:version => '3.3.0',
:author => 'baz'
- }
+ },
+ :environment => env
)
mod.unmet_dependencies.should == [{
@@ -293,6 +298,8 @@ describe Puppet::Module do
end
it "should be empty when all dependencies are met" do
+ env = Puppet::Node::Environment.create(:testing, [@modpath], '')
+
mod = PuppetSpec::Modules.create(
'mymod2',
@modpath,
@@ -307,7 +314,8 @@ describe Puppet::Module do
"name" => "baz/alsosatisfied"
}
]
- }
+ },
+ :environment => env
)
PuppetSpec::Modules.create(
'satisfied',
@@ -315,7 +323,8 @@ describe Puppet::Module do
:metadata => {
:version => '3.3.0',
:author => 'baz'
- }
+ },
+ :environment => env
)
PuppetSpec::Modules.create(
'alsosatisfied',
@@ -323,7 +332,8 @@ describe Puppet::Module do
:metadata => {
:version => '2.1.0',
:author => 'baz'
- }
+ },
+ :environment => env
)
mod.unmet_dependencies.should be_empty
@@ -652,11 +662,13 @@ describe Puppet::Module do
end
it "should know what other modules require it" do
- Puppet.settings[:modulepath] = @modpath
+ env = Puppet::Node::Environment.create(:testing, [@modpath], '')
+
dependable = PuppetSpec::Modules.create(
'dependable',
@modpath,
- :metadata => {:author => 'puppetlabs'}
+ :metadata => {:author => 'puppetlabs'},
+ :environment => env
)
PuppetSpec::Modules.create(
'needy',
@@ -667,7 +679,8 @@ describe Puppet::Module do
"version_requirement" => ">= 2.2.0",
"name" => "puppetlabs/dependable"
}]
- }
+ },
+ :environment => env
)
PuppetSpec::Modules.create(
'wantit',
@@ -678,7 +691,8 @@ describe Puppet::Module do
"version_requirement" => "< 5.0.0",
"name" => "puppetlabs/dependable"
}]
- }
+ },
+ :environment => env
)
dependable.required_by.should =~ [
{
diff --git a/spec/unit/network/http/api/v2/environments_spec.rb b/spec/unit/network/http/api/v2/environments_spec.rb
index adeea57be..394587238 100644
--- a/spec/unit/network/http/api/v2/environments_spec.rb
+++ b/spec/unit/network/http/api/v2/environments_spec.rb
@@ -8,7 +8,9 @@ describe Puppet::Network::HTTP::API::V2::Environments do
include JSONMatchers
it "responds with all of the available environments environments" do
- handler = Puppet::Network::HTTP::API::V2::Environments.new(TestingEnvironmentLoader.new)
+ environment = FakeEnvironment.create(:production, [], '')
+ loader = Puppet::Environments::Static.new(environment)
+ handler = Puppet::Network::HTTP::API::V2::Environments.new(loader)
response = Puppet::Network::HTTP::MemoryResponse.new
handler.call(Puppet::Network::HTTP::Request.from_hash(:headers => { 'accept' => 'application/json' }), response)
@@ -16,7 +18,7 @@ describe Puppet::Network::HTTP::API::V2::Environments do
expect(response.code).to eq(200)
expect(response.type).to eq("application/json")
expect(JSON.parse(response.body)).to eq({
- "search_path" => ["file:///fake"],
+ "search_paths" => loader.search_paths,
"environments" => {
"production" => {
"modules" => {
@@ -30,7 +32,8 @@ describe Puppet::Network::HTTP::API::V2::Environments do
end
it "the response conforms to the environments schema" do
- handler = Puppet::Network::HTTP::API::V2::Environments.new(TestingEnvironmentLoader.new)
+ environment = FakeEnvironment.create(:production, [], '')
+ handler = Puppet::Network::HTTP::API::V2::Environments.new(Puppet::Environments::Static.new(environment))
response = Puppet::Network::HTTP::MemoryResponse.new
handler.call(Puppet::Network::HTTP::Request.from_hash(:headers => { 'accept' => 'application/json' }), response)
@@ -38,16 +41,6 @@ describe Puppet::Network::HTTP::API::V2::Environments do
expect(response.body).to validate_against('api/schemas/environments.json')
end
- class TestingEnvironmentLoader
- def search_paths
- ["file:///fake"]
- end
-
- def list
- [FakeEnvironment.new(:production)]
- end
- end
-
class FakeEnvironment < Puppet::Node::Environment
def modules
fake_module = Puppet::Module.new('testing', '/somewhere/on/disk', self)
diff --git a/spec/unit/node/environment_spec.rb b/spec/unit/node/environment_spec.rb
index fbe791972..0953e0349 100755
--- a/spec/unit/node/environment_spec.rb
+++ b/spec/unit/node/environment_spec.rb
@@ -346,28 +346,6 @@ describe Puppet::Node::Environment do
end
end
- describe Puppet::Node::Environment::Helper do
- before do
- @helper = Object.new
- @helper.extend(Puppet::Node::Environment::Helper)
- end
-
- it "should be able to set and retrieve the environment as a symbol" do
- @helper.environment = :foo
- @helper.environment.name.should == :foo
- end
-
- it "should accept an environment directly" do
- @helper.environment = Puppet::Node::Environment.new(:foo)
- @helper.environment.name.should == :foo
- end
-
- it "should accept an environment as a string" do
- @helper.environment = 'foo'
- @helper.environment.name.should == :foo
- end
- end
-
describe "when performing initial import" do
def parser_and_environment(name)
env = Puppet::Node::Environment.new(name)
diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb
index ae0a33f62..11f24729e 100755
--- a/spec/unit/node_spec.rb
+++ b/spec/unit/node_spec.rb
@@ -5,29 +5,36 @@ require 'matchers/json'
describe Puppet::Node do
include JSONMatchers
+ let(:environment) { Puppet::Node::Environment.create(:bar, [], '') }
+ let(:env_loader) { Puppet::Environments::Static.new(environment) }
+
it "should register its document type as Node" do
PSON.registered_document_types["Node"].should equal(Puppet::Node)
end
describe "when managing its environment" do
it "should use any set environment" do
- Puppet::Node.new("foo", :environment => "bar").environment.name.should == :bar
+ Puppet.override(:environments => env_loader) do
+ Puppet::Node.new("foo", :environment => "bar").environment.should == environment
+ end
end
it "should support providing an actual environment instance" do
- Puppet::Node.new("foo", :environment => Puppet::Node::Environment.new(:bar)).environment.name.should == :bar
+ Puppet::Node.new("foo", :environment => environment).environment.name.should == :bar
end
it "should determine its environment from its parameters if no environment is set" do
- Puppet::Node.new("foo", :parameters => {"environment" => :bar}).environment.name.should == :bar
+ Puppet.override(:environments => env_loader) do
+ Puppet::Node.new("foo", :parameters => {"environment" => :bar}).environment.should == environment
+ end
end
- it "should use the default environment if no environment is provided" do
- Puppet::Node.new("foo").environment.name.should == Puppet::Node::Environment.new.name
- end
+ it "should use the configured environment if no environment is provided" do
+ Puppet[:environment] = environment.name.to_s
- it "should always return an environment instance rather than a string" do
- Puppet::Node.new("foo").environment.should be_instance_of(Puppet::Node::Environment)
+ Puppet.override(:environments => env_loader) do
+ Puppet::Node.new("foo").environment.should == environment
+ end
end
it "should allow the environment to be set after initialization" do
@@ -151,8 +158,10 @@ describe Puppet::Node do
end
it "should include the environment" do
- @node.environment = "production"
- Puppet::Node.should read_json_attribute('environment').from(@node.to_pson).as(Puppet::Node::Environment.new(:production))
+ Puppet.override(:environments => env_loader) do
+ @node.environment = environment
+ Puppet::Node.should read_json_attribute('environment').from(@node.to_pson).as(environment)
+ end
end
end
end
diff --git a/spec/unit/parser/ast/collection_spec.rb b/spec/unit/parser/ast/collection_spec.rb
index bd4f5f82f..a5e40b2c3 100755
--- a/spec/unit/parser/ast/collection_spec.rb
+++ b/spec/unit/parser/ast/collection_spec.rb
@@ -4,7 +4,7 @@ require 'spec_helper'
describe Puppet::Parser::AST::Collection do
before :each do
@mytype = Puppet::Resource::Type.new(:definition, "mytype")
- @environment = Puppet::Node::Environment.new
+ @environment = Puppet::Node::Environment.create(:testing, [], '')
@environment.known_resource_types.add @mytype
@compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("foonode", :environment => @environment))
diff --git a/spec/unit/parser/ast/resource_spec.rb b/spec/unit/parser/ast/resource_spec.rb
index abf815c39..00aa263ff 100755
--- a/spec/unit/parser/ast/resource_spec.rb
+++ b/spec/unit/parser/ast/resource_spec.rb
@@ -97,7 +97,7 @@ describe Puppet::Parser::AST::Resource do
describe "when generating qualified resources" do
before do
@scope = Puppet::Parser::Scope.new Puppet::Parser::Compiler.new(Puppet::Node.new("mynode"))
- @parser = Puppet::Parser::Parser.new(Puppet::Node::Environment.new)
+ @parser = Puppet::Parser::Parser.new(@scope.environment)
["one", "one::two", "three"].each do |name|
@parser.environment.known_resource_types.add(Puppet::Resource::Type.new(:definition, name, {}))
end
diff --git a/spec/unit/parser/compiler_spec.rb b/spec/unit/parser/compiler_spec.rb
index 68210a4df..8a6621520 100755
--- a/spec/unit/parser/compiler_spec.rb
+++ b/spec/unit/parser/compiler_spec.rb
@@ -66,13 +66,15 @@ describe Puppet::Parser::Compiler do
now = Time.now
Time.stubs(:now).returns(now)
- @node = Puppet::Node.new("testnode", :facts => Puppet::Node::Facts.new("facts", {}))
- @known_resource_types = Puppet::Resource::TypeCollection.new "development"
+ environment = Puppet::Node::Environment.create(:testing, [], '')
+ @node = Puppet::Node.new("testnode",
+ :facts => Puppet::Node::Facts.new("facts", {}),
+ :environment => environment)
+ @known_resource_types = environment.known_resource_types
@compiler = Puppet::Parser::Compiler.new(@node)
@scope = Puppet::Parser::Scope.new(@compiler, :source => stub('source'))
@scope_resource = Puppet::Parser::Resource.new(:file, "/my/file", :scope => @scope)
@scope.resource = @scope_resource
- @compiler.environment.stubs(:known_resource_types).returns @known_resource_types
end
it "should have a class method that compiles, converts, and returns a catalog" do
diff --git a/spec/unit/parser/files_spec.rb b/spec/unit/parser/files_spec.rb
index 3813260b4..02ef3d5cf 100755
--- a/spec/unit/parser/files_spec.rb
+++ b/spec/unit/parser/files_spec.rb
@@ -6,6 +6,8 @@ require 'puppet/parser/files'
describe Puppet::Parser::Files do
include PuppetSpec::Files
+ let(:environment) { Puppet::Node::Environment.create(:testing, [], '') }
+
before do
@basepath = make_absolute("/somepath")
end
@@ -13,15 +15,15 @@ describe Puppet::Parser::Files do
describe "when searching for templates" do
it "should return fully-qualified templates directly" do
Puppet::Parser::Files.expects(:modulepath).never
- Puppet::Parser::Files.find_template(@basepath + "/my/template").should == @basepath + "/my/template"
+ Puppet::Parser::Files.find_template(@basepath + "/my/template", environment).should == @basepath + "/my/template"
end
it "should return the template from the first found module" do
mod = mock 'module'
- Puppet::Node::Environment.new.expects(:module).with("mymod").returns mod
-
mod.expects(:template).returns("/one/mymod/templates/mytemplate")
- Puppet::Parser::Files.find_template("mymod/mytemplate").should == "/one/mymod/templates/mytemplate"
+ environment.expects(:module).with("mymod").returns mod
+
+ Puppet::Parser::Files.find_template("mymod/mytemplate", environment).should == "/one/mymod/templates/mytemplate"
end
it "should return the file in the templatedir if it exists" do
@@ -29,101 +31,91 @@ describe Puppet::Parser::Files do
Puppet[:modulepath] = "/one:/two"
File.stubs(:directory?).returns(true)
Puppet::FileSystem.stubs(:exist?).returns(true)
- Puppet::Parser::Files.find_template("mymod/mytemplate").should == File.join(Puppet[:templatedir], "mymod/mytemplate")
+ Puppet::Parser::Files.find_template("mymod/mytemplate", environment).should == File.join(Puppet[:templatedir], "mymod/mytemplate")
end
it "should not raise an error if no valid templatedir exists and the template exists in a module" do
mod = mock 'module'
- Puppet::Node::Environment.new.expects(:module).with("mymod").returns mod
-
mod.expects(:template).returns("/one/mymod/templates/mytemplate")
- Puppet::Parser::Files.stubs(:templatepath).with(nil).returns(nil)
+ environment.expects(:module).with("mymod").returns mod
+ Puppet::Parser::Files.stubs(:templatepath).with(environment).returns(nil)
- Puppet::Parser::Files.find_template("mymod/mytemplate").should == "/one/mymod/templates/mytemplate"
+ Puppet::Parser::Files.find_template("mymod/mytemplate", environment).should == "/one/mymod/templates/mytemplate"
end
it "should return unqualified templates if they exist in the template dir" do
Puppet::FileSystem.stubs(:exist?).returns true
- Puppet::Parser::Files.stubs(:templatepath).with(nil).returns(["/my/templates"])
- Puppet::Parser::Files.find_template("mytemplate").should == "/my/templates/mytemplate"
+ Puppet::Parser::Files.stubs(:templatepath).with(environment).returns(["/my/templates"])
+
+ Puppet::Parser::Files.find_template("mytemplate", environment).should == "/my/templates/mytemplate"
end
it "should only return templates if they actually exist" do
Puppet::FileSystem.expects(:exist?).with("/my/templates/mytemplate").returns true
- Puppet::Parser::Files.stubs(:templatepath).with(nil).returns(["/my/templates"])
- Puppet::Parser::Files.find_template("mytemplate").should == "/my/templates/mytemplate"
+ Puppet::Parser::Files.stubs(:templatepath).with(environment).returns(["/my/templates"])
+ Puppet::Parser::Files.find_template("mytemplate", environment).should == "/my/templates/mytemplate"
end
it "should return nil when asked for a template that doesn't exist" do
Puppet::FileSystem.expects(:exist?).with("/my/templates/mytemplate").returns false
- Puppet::Parser::Files.stubs(:templatepath).with(nil).returns(["/my/templates"])
- Puppet::Parser::Files.find_template("mytemplate").should be_nil
- end
-
- it "should search in the template directories before modules" do
- Puppet::FileSystem.stubs(:exist?).returns true
- Puppet::Parser::Files.stubs(:templatepath).with(nil).returns(["/my/templates"])
- Puppet::Module.expects(:find).never
- Puppet::Parser::Files.find_template("mytemplate")
+ Puppet::Parser::Files.stubs(:templatepath).with(environment).returns(["/my/templates"])
+ Puppet::Parser::Files.find_template("mytemplate", environment).should be_nil
end
it "should accept relative templatedirs" do
Puppet::FileSystem.stubs(:exist?).returns true
Puppet[:templatedir] = "my/templates"
File.expects(:directory?).with(File.expand_path("my/templates")).returns(true)
- Puppet::Parser::Files.find_template("mytemplate").should == File.expand_path("my/templates/mytemplate")
+ Puppet::Parser::Files.find_template("mytemplate", environment).should == File.expand_path("my/templates/mytemplate")
end
it "should use the environment templatedir if no module is found and an environment is specified" do
Puppet::FileSystem.stubs(:exist?).returns true
- Puppet::Parser::Files.stubs(:templatepath).with("myenv").returns(["/myenv/templates"])
- Puppet::Parser::Files.find_template("mymod/mytemplate", "myenv").should == "/myenv/templates/mymod/mytemplate"
+ Puppet::Parser::Files.stubs(:templatepath).with(environment).returns(["/myenv/templates"])
+ Puppet::Parser::Files.find_template("mymod/mytemplate", environment).should == "/myenv/templates/mymod/mytemplate"
end
it "should use first dir from environment templatedir if no module is found and an environment is specified" do
Puppet::FileSystem.stubs(:exist?).returns true
- Puppet::Parser::Files.stubs(:templatepath).with("myenv").returns(["/myenv/templates", "/two/templates"])
- Puppet::Parser::Files.find_template("mymod/mytemplate", "myenv").should == "/myenv/templates/mymod/mytemplate"
+ Puppet::Parser::Files.stubs(:templatepath).with(environment).returns(["/myenv/templates", "/two/templates"])
+ Puppet::Parser::Files.find_template("mymod/mytemplate", environment).should == "/myenv/templates/mymod/mytemplate"
end
it "should use a valid dir when templatedir is a path for unqualified templates and the first dir contains template" do
Puppet::Parser::Files.stubs(:templatepath).returns(["/one/templates", "/two/templates"])
Puppet::FileSystem.expects(:exist?).with("/one/templates/mytemplate").returns(true)
- Puppet::Parser::Files.find_template("mytemplate").should == "/one/templates/mytemplate"
+ Puppet::Parser::Files.find_template("mytemplate", environment).should == "/one/templates/mytemplate"
end
it "should use a valid dir when templatedir is a path for unqualified templates and only second dir contains template" do
Puppet::Parser::Files.stubs(:templatepath).returns(["/one/templates", "/two/templates"])
Puppet::FileSystem.expects(:exist?).with("/one/templates/mytemplate").returns(false)
Puppet::FileSystem.expects(:exist?).with("/two/templates/mytemplate").returns(true)
- Puppet::Parser::Files.find_template("mytemplate").should == "/two/templates/mytemplate"
+ Puppet::Parser::Files.find_template("mytemplate", environment).should == "/two/templates/mytemplate"
end
it "should use the node environment if specified" do
mod = mock 'module'
- Puppet::Node::Environment.new("myenv").expects(:module).with("mymod").returns mod
+ environment.expects(:module).with("mymod").returns mod
mod.expects(:template).returns("/my/modules/mymod/templates/envtemplate")
- Puppet::Parser::Files.find_template("mymod/envtemplate", "myenv").should == "/my/modules/mymod/templates/envtemplate"
+ Puppet::Parser::Files.find_template("mymod/envtemplate", environment).should == "/my/modules/mymod/templates/envtemplate"
end
it "should return nil if no template can be found" do
- Puppet::Parser::Files.find_template("foomod/envtemplate", "myenv").should be_nil
+ Puppet::Parser::Files.find_template("foomod/envtemplate", environment).should be_nil
end
-
- after { Puppet.settings.clear }
end
describe "when searching for manifests" do
it "should ignore invalid modules" do
mod = mock 'module'
- env = Puppet::Node::Environment.new
- env.expects(:module).with("mymod").raises(Puppet::Module::InvalidName, "name is invalid")
+ environment.expects(:module).with("mymod").raises(Puppet::Module::InvalidName, "name is invalid")
Puppet.expects(:value).with(:modulepath).never
Dir.stubs(:glob).returns %w{foo}
- Puppet::Parser::Files.find_manifests_in_modules("mymod/init.pp", env)
+ Puppet::Parser::Files.find_manifests_in_modules("mymod/init.pp", environment)
end
end
@@ -134,8 +126,6 @@ describe Puppet::Parser::Files do
mod.stubs(:match_manifests).with("init.pp").returns(["/one/#{name}/manifests/init.pp"])
end
- let(:environment) { Puppet::Node::Environment.new }
-
it "returns no files when no module is found" do
module_name, files = Puppet::Parser::Files.find_manifests_in_modules("not_here_module/foo", environment)
expect(files).to be_empty
@@ -150,7 +140,7 @@ describe Puppet::Parser::Files do
end
it "does not find the module when it is a different environment" do
- different_env = Puppet::Node::Environment.new("different")
+ different_env = Puppet::Node::Environment.create(:different, [], '')
a_module_in_environment(environment, "mymod")
Puppet::Parser::Files.find_manifests_in_modules("mymod/init.pp", different_env).should_not include("mymod")
diff --git a/spec/unit/parser/functions_spec.rb b/spec/unit/parser/functions_spec.rb
index 8e3f52616..91013586c 100755
--- a/spec/unit/parser/functions_spec.rb
+++ b/spec/unit/parser/functions_spec.rb
@@ -8,20 +8,14 @@ describe Puppet::Parser::Functions do
let(:function_module) { Puppet::Parser::Functions.environment_module(Puppet.lookup(:current_environment)) }
+ let(:environment) { Puppet::Node::Environment.create(:myenv, [], '') }
+
before do
Puppet::Parser::Functions.reset
end
it "should have a method for returning an environment-specific module" do
- Puppet::Parser::Functions.environment_module(Puppet::Node::Environment.new("myenv")).should be_instance_of(Module)
- end
-
- it "should use the current default environment if no environment is provided" do
- Puppet::Parser::Functions.environment_module.should be_instance_of(Module)
- end
-
- it "should be able to retrieve environment modules asked for by name rather than instance" do
- Puppet::Parser::Functions.environment_module(Puppet::Node::Environment.new("myenv")).should equal(Puppet::Parser::Functions.environment_module("myenv"))
+ Puppet::Parser::Functions.environment_module(environment).should be_instance_of(Module)
end
describe "when calling newfunction" do
diff --git a/spec/unit/parser/parser_spec.rb b/spec/unit/parser/parser_spec.rb
index 466bfea13..56062d47e 100755
--- a/spec/unit/parser/parser_spec.rb
+++ b/spec/unit/parser/parser_spec.rb
@@ -19,18 +19,14 @@ describe Puppet::Parser do
end
it "should set the environment" do
- env = Puppet::Node::Environment.new
+ env = Puppet::Node::Environment.create(:testing, [], '')
Puppet::Parser::Parser.new(env).environment.should == env
end
- it "should convert the environment into an environment instance if a string is provided" do
- env = Puppet::Node::Environment.new("testing")
- Puppet::Parser::Parser.new("testing").environment.should == env
- end
-
it "should be able to look up the environment-specific resource type collection" do
- rtc = Puppet::Node::Environment.new("development").known_resource_types
- parser = Puppet::Parser::Parser.new "development"
+ env = Puppet::Node::Environment.create(:development, [], '')
+ rtc = env.known_resource_types
+ parser = Puppet::Parser::Parser.new env
parser.known_resource_types.should equal(rtc)
end
diff --git a/spec/unit/parser/resource_spec.rb b/spec/unit/parser/resource_spec.rb
index 74a66d1c1..f78f83982 100755
--- a/spec/unit/parser/resource_spec.rb
+++ b/spec/unit/parser/resource_spec.rb
@@ -1,15 +1,11 @@
-#! /usr/bin/env ruby
require 'spec_helper'
-# LAK: FIXME This is just new tests for resources; I have
-# not moved all tests over yet.
-
describe Puppet::Parser::Resource do
before do
- @node = Puppet::Node.new("yaynode")
- @known_resource_types = Puppet::Resource::TypeCollection.new("env")
+ environment = Puppet::Node::Environment.create(:testing, [], '')
+ @node = Puppet::Node.new("yaynode", :environment => environment)
+ @known_resource_types = environment.known_resource_types
@compiler = Puppet::Parser::Compiler.new(@node)
- @compiler.environment.stubs(:known_resource_types).returns @known_resource_types
@source = newclass ""
@scope = @compiler.topscope
end
@@ -131,8 +127,6 @@ describe Puppet::Parser::Resource do
describe "when evaluating" do
before do
- @node = Puppet::Node.new "test-node"
- @compiler = Puppet::Parser::Compiler.new @node
@catalog = Puppet::Resource::Catalog.new
source = stub('source')
source.stubs(:module_name)
diff --git a/spec/unit/parser/scope_spec.rb b/spec/unit/parser/scope_spec.rb
index 2267294a3..b9b10618f 100755
--- a/spec/unit/parser/scope_spec.rb
+++ b/spec/unit/parser/scope_spec.rb
@@ -64,7 +64,7 @@ describe Puppet::Parser::Scope do
end
it "should get its environment from its compiler" do
- env = Puppet::Node::Environment.new
+ env = Puppet::Node::Environment.create(:testing, [], '')
compiler = stub 'compiler', :environment => env, :is_a? => true
scope = Puppet::Parser::Scope.new(compiler)
scope.environment.should equal(env)
@@ -87,7 +87,7 @@ describe Puppet::Parser::Scope do
end
describe "when custom functions are called" do
- let(:env) { Puppet::Node::Environment.new('testing') }
+ let(:env) { Puppet::Node::Environment.create(:testing, [], '') }
let(:compiler) { Puppet::Parser::Compiler.new(Puppet::Node.new('foo', :environment => env)) }
let(:scope) { Puppet::Parser::Scope.new(compiler) }
diff --git a/spec/unit/parser/type_loader_spec.rb b/spec/unit/parser/type_loader_spec.rb
index c735db7c2..659ffa942 100755
--- a/spec/unit/parser/type_loader_spec.rb
+++ b/spec/unit/parser/type_loader_spec.rb
@@ -19,10 +19,6 @@ describe Puppet::Parser::TypeLoader do
loader.environment.name.should == :myenv
end
- it "should include the Environment Helper" do
- loader.class.ancestors.should be_include(Puppet::Node::Environment::Helper)
- end
-
it "should delegate its known resource types to its environment" do
loader.known_resource_types.should be_instance_of(Puppet::Resource::TypeCollection)
end
diff --git a/spec/unit/rails/host_spec.rb b/spec/unit/rails/host_spec.rb
index 81d048ef1..746c3a075 100755
--- a/spec/unit/rails/host_spec.rb
+++ b/spec/unit/rails/host_spec.rb
@@ -40,7 +40,7 @@ describe "Puppet::Rails::Host", :if => can_use_scratch_database? do
it "should stringify the environment" do
host = Puppet::Rails::Host.new
- host.environment = Puppet::Node::Environment.new("production")
+ host.environment = Puppet::Node::Environment.create(:production, [], '')
host.environment.class.should == String
end
diff --git a/spec/unit/resource/type_collection_spec.rb b/spec/unit/resource/type_collection_spec.rb
index c3a335ce2..4cd5b339e 100755
--- a/spec/unit/resource/type_collection_spec.rb
+++ b/spec/unit/resource/type_collection_spec.rb
@@ -7,39 +7,20 @@ require 'puppet/resource/type'
describe Puppet::Resource::TypeCollection do
include PuppetSpec::Files
+ let(:environment) { Puppet::Node::Environment.create(:testing, [], '') }
+
before do
@instance = Puppet::Resource::Type.new(:hostclass, "foo")
- @code = Puppet::Resource::TypeCollection.new("env")
- end
-
- it "should require an environment at initialization" do
- env = Puppet::Node::Environment.new("testing")
- Puppet::Resource::TypeCollection.new(env).environment.should equal(env)
- end
-
- it "should convert the environment into an environment instance if a string is provided" do
- env = Puppet::Node::Environment.new("testing")
- Puppet::Resource::TypeCollection.new("testing").environment.should equal(env)
- end
-
- it "should create a 'loader' at initialization" do
- Puppet::Resource::TypeCollection.new("testing").loader.should be_instance_of(Puppet::Parser::TypeLoader)
- end
-
- it "should be able to add a resource type" do
- Puppet::Resource::TypeCollection.new("env").should respond_to(:add)
+ @code = Puppet::Resource::TypeCollection.new(environment)
end
it "should consider '<<' to be an alias to 'add' but should return self" do
- loader = Puppet::Resource::TypeCollection.new("env")
- loader.expects(:add).with "foo"
- loader.expects(:add).with "bar"
- loader << "foo" << "bar"
+ @code.expects(:add).with "foo"
+ @code.expects(:add).with "bar"
+ @code << "foo" << "bar"
end
it "should set itself as the code collection for added resource types" do
- loader = Puppet::Resource::TypeCollection.new("env")
-
node = Puppet::Resource::Type.new(:node, "foo")
@code.add(node)
@@ -96,7 +77,7 @@ describe Puppet::Resource::TypeCollection do
end
it "should remove all nodes, classes, and definitions when cleared" do
- loader = Puppet::Resource::TypeCollection.new("env")
+ loader = Puppet::Resource::TypeCollection.new(environment)
loader.add Puppet::Resource::Type.new(:hostclass, "class")
loader.add Puppet::Resource::Type.new(:definition, "define")
loader.add Puppet::Resource::Type.new(:node, "node")
@@ -200,14 +181,14 @@ describe Puppet::Resource::TypeCollection do
describe "behavior of add for #{data}" do
it "should return the added #{data}" do
- loader = Puppet::Resource::TypeCollection.new("env")
+ loader = Puppet::Resource::TypeCollection.new(environment)
instance = Puppet::Resource::Type.new(data, "foo")
loader.add(instance).should equal(instance)
end
it "should retrieve #{data} insensitive to case" do
- loader = Puppet::Resource::TypeCollection.new("env")
+ loader = Puppet::Resource::TypeCollection.new(environment)
instance = Puppet::Resource::Type.new(data, "Bar")
loader.add instance
@@ -216,75 +197,75 @@ describe Puppet::Resource::TypeCollection do
end
it "should return nil when asked for a #{data} that has not been added" do
- Puppet::Resource::TypeCollection.new("env").send(data, "foo").should be_nil
+ Puppet::Resource::TypeCollection.new(environment).send(data, "foo").should be_nil
end
end
end
describe "when finding a qualified instance" do
it "should return any found instance if the instance name is fully qualified" do
- loader = Puppet::Resource::TypeCollection.new("env")
+ loader = Puppet::Resource::TypeCollection.new(environment)
instance = Puppet::Resource::Type.new(:hostclass, "foo::bar")
loader.add instance
loader.find_hostclass("namespace", "::foo::bar").should equal(instance)
end
it "should return nil if the instance name is fully qualified and no such instance exists" do
- loader = Puppet::Resource::TypeCollection.new("env")
+ loader = Puppet::Resource::TypeCollection.new(environment)
loader.find_hostclass("namespace", "::foo::bar").should be_nil
end
it "should be able to find classes in the base namespace" do
- loader = Puppet::Resource::TypeCollection.new("env")
+ loader = Puppet::Resource::TypeCollection.new(environment)
instance = Puppet::Resource::Type.new(:hostclass, "foo")
loader.add instance
loader.find_hostclass("", "foo").should equal(instance)
end
it "should return the partially qualified object if it exists in a provided namespace" do
- loader = Puppet::Resource::TypeCollection.new("env")
+ loader = Puppet::Resource::TypeCollection.new(environment)
instance = Puppet::Resource::Type.new(:hostclass, "foo::bar::baz")
loader.add instance
loader.find_hostclass("foo", "bar::baz").should equal(instance)
end
it "should be able to find partially qualified objects in any of the provided namespaces" do
- loader = Puppet::Resource::TypeCollection.new("env")
+ loader = Puppet::Resource::TypeCollection.new(environment)
instance = Puppet::Resource::Type.new(:hostclass, "foo::bar::baz")
loader.add instance
loader.find_hostclass(["nons", "foo", "otherns"], "bar::baz").should equal(instance)
end
it "should return the unqualified object if it exists in a provided namespace" do
- loader = Puppet::Resource::TypeCollection.new("env")
+ loader = Puppet::Resource::TypeCollection.new(environment)
instance = Puppet::Resource::Type.new(:hostclass, "foo::bar")
loader.add instance
loader.find_hostclass("foo", "bar").should equal(instance)
end
it "should return the unqualified object if it exists in the parent namespace" do
- loader = Puppet::Resource::TypeCollection.new("env")
+ loader = Puppet::Resource::TypeCollection.new(environment)
instance = Puppet::Resource::Type.new(:hostclass, "foo::bar")
loader.add instance
loader.find_hostclass("foo::bar::baz", "bar").should equal(instance)
end
it "should should return the partially qualified object if it exists in the parent namespace" do
- loader = Puppet::Resource::TypeCollection.new("env")
+ loader = Puppet::Resource::TypeCollection.new(environment)
instance = Puppet::Resource::Type.new(:hostclass, "foo::bar::baz")
loader.add instance
loader.find_hostclass("foo::bar", "bar::baz").should equal(instance)
end
it "should return the qualified object if it exists in the root namespace" do
- loader = Puppet::Resource::TypeCollection.new("env")
+ loader = Puppet::Resource::TypeCollection.new(environment)
instance = Puppet::Resource::Type.new(:hostclass, "foo::bar::baz")
loader.add instance
loader.find_hostclass("foo::bar", "foo::bar::baz").should equal(instance)
end
it "should return nil if the object cannot be found" do
- loader = Puppet::Resource::TypeCollection.new("env")
+ loader = Puppet::Resource::TypeCollection.new(environment)
instance = Puppet::Resource::Type.new(:hostclass, "foo::bar::baz")
loader.add instance
loader.find_hostclass("foo::bar", "eh").should be_nil
@@ -292,7 +273,7 @@ describe Puppet::Resource::TypeCollection do
describe "when topscope has a class that has the same name as a local class" do
before do
- @loader = Puppet::Resource::TypeCollection.new("env")
+ @loader = Puppet::Resource::TypeCollection.new(environment)
[ "foo::bar", "bar" ].each do |name|
@loader.add Puppet::Resource::Type.new(:hostclass, name)
end
@@ -312,7 +293,7 @@ describe Puppet::Resource::TypeCollection do
end
it "should not look in the local scope for classes when the name is qualified" do
- @loader = Puppet::Resource::TypeCollection.new("env")
+ @loader = Puppet::Resource::TypeCollection.new(environment)
@loader.add Puppet::Resource::Type.new(:hostclass, "foo::bar")
@loader.find_hostclass("foo", "::bar").should == nil
@@ -322,24 +303,24 @@ describe Puppet::Resource::TypeCollection do
it "should be able to find nodes" do
node = Puppet::Resource::Type.new(:node, "bar")
- loader = Puppet::Resource::TypeCollection.new("env")
+ loader = Puppet::Resource::TypeCollection.new(environment)
loader.add(node)
loader.find_node(stub("ignored"), "bar").should == node
end
it "should indicate whether any nodes are defined" do
- loader = Puppet::Resource::TypeCollection.new("env")
+ loader = Puppet::Resource::TypeCollection.new(environment)
loader.add_node(Puppet::Resource::Type.new(:node, "foo"))
loader.should be_nodes
end
it "should indicate whether no nodes are defined" do
- Puppet::Resource::TypeCollection.new("env").should_not be_nodes
+ Puppet::Resource::TypeCollection.new(environment).should_not be_nodes
end
describe "when finding nodes" do
before :each do
- @loader = Puppet::Resource::TypeCollection.new("env")
+ @loader = Puppet::Resource::TypeCollection.new(environment)
end
it "should return any node whose name exactly matches the provided node name" do
@@ -368,7 +349,7 @@ describe Puppet::Resource::TypeCollection do
describe "when managing files" do
before do
- @loader = Puppet::Resource::TypeCollection.new("env")
+ @loader = Puppet::Resource::TypeCollection.new(environment)
Puppet::Util::WatchedFile.stubs(:new).returns stub("watched_file")
end
@@ -409,7 +390,7 @@ describe Puppet::Resource::TypeCollection do
describe "when determining the configuration version" do
before do
- @code = Puppet::Resource::TypeCollection.new("env")
+ @code = Puppet::Resource::TypeCollection.new(environment)
end
it "should default to the current time" do
diff --git a/spec/unit/resource/type_spec.rb b/spec/unit/resource/type_spec.rb
index 1ed1ebcd6..1dd0c41db 100755
--- a/spec/unit/resource/type_spec.rb
+++ b/spec/unit/resource/type_spec.rb
@@ -347,14 +347,15 @@ describe Puppet::Resource::Type do
describe "when describing and managing parent classes" do
before do
- @krt = Puppet::Node::Environment.new.known_resource_types
+ environment = Puppet::Node::Environment.create(:testing, [], '')
+ @krt = environment.known_resource_types
@parent = Puppet::Resource::Type.new(:hostclass, "bar")
@krt.add @parent
@child = Puppet::Resource::Type.new(:hostclass, "foo", :parent => "bar")
@krt.add @child
- @scope = Puppet::Parser::Scope.new(Puppet::Parser::Compiler.new(Puppet::Node.new("foo")))
+ @scope = Puppet::Parser::Scope.new(Puppet::Parser::Compiler.new(Puppet::Node.new("foo", :environment => environment)))
end
it "should be able to define a parent" do
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index b6443865a..1ac2decf1 100755
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@ -5,7 +5,8 @@ require 'puppet/resource'
describe Puppet::Resource do
include PuppetSpec::Files
- let :basepath do make_absolute("/somepath") end
+ let(:basepath) { make_absolute("/somepath") }
+ let(:environment) { Puppet::Node::Environment.create(:testing, [], '') }
[:catalog, :file, :line].each do |attr|
it "should have an #{attr} attribute" do
@@ -120,10 +121,6 @@ describe Puppet::Resource do
resource.should be_exported
end
- it "should support an environment attribute" do
- Puppet::Resource.new("file", "/my/file", :environment => :foo).environment.name.should == :foo
- end
-
describe "and munging its type and title" do
describe "when modeling a builtin resource" do
it "should be able to find the resource type" do
@@ -139,19 +136,19 @@ describe Puppet::Resource do
describe "that exists" do
before do
@type = Puppet::Resource::Type.new(:definition, "foo::bar")
- Puppet::Node::Environment.new.known_resource_types.add @type
+ environment.known_resource_types.add @type
end
it "should set its type to the capitalized type name" do
- Puppet::Resource.new("foo::bar", "/my/file").type.should == "Foo::Bar"
+ Puppet::Resource.new("foo::bar", "/my/file", :environment => environment).type.should == "Foo::Bar"
end
it "should be able to find the resource type" do
- Puppet::Resource.new("foo::bar", "/my/file").resource_type.should equal(@type)
+ Puppet::Resource.new("foo::bar", "/my/file", :environment => environment).resource_type.should equal(@type)
end
it "should set its title to the provided title" do
- Puppet::Resource.new("foo::bar", "/my/file").title.should == "/my/file"
+ Puppet::Resource.new("foo::bar", "/my/file", :environment => environment).title.should == "/my/file"
end
end
@@ -179,15 +176,15 @@ describe Puppet::Resource do
describe "that exists" do
before do
@type = Puppet::Resource::Type.new(:hostclass, "foo::bar")
- Puppet::Node::Environment.new.known_resource_types.add @type
+ environment.known_resource_types.add @type
end
it "should set its title to the capitalized, fully qualified resource type" do
- Puppet::Resource.new("class", "foo::bar").title.should == "Foo::Bar"
+ Puppet::Resource.new("class", "foo::bar", :environment => environment).title.should == "Foo::Bar"
end
it "should be able to find the resource type" do
- Puppet::Resource.new("class", "foo::bar").resource_type.should equal(@type)
+ Puppet::Resource.new("class", "foo::bar", :environment => environment).resource_type.should equal(@type)
end
end
@@ -207,9 +204,9 @@ describe Puppet::Resource do
describe "and a class exists whose name is the empty string" do # this was a bit tough to track down
it "should set its title to :main" do
@type = Puppet::Resource::Type.new(:hostclass, "")
- Puppet::Node::Environment.new.known_resource_types.add @type
+ environment.known_resource_types.add @type
- Puppet::Resource.new("class", "").title.should == :main
+ Puppet::Resource.new("class", "", :environment => environment).title.should == :main
end
end
end
@@ -222,9 +219,9 @@ describe Puppet::Resource do
describe "and a class exists whose name is the empty string" do # this was a bit tough to track down
it "should set its title to :main" do
@type = Puppet::Resource::Type.new(:hostclass, "")
- Puppet::Node::Environment.new.known_resource_types.add @type
+ environment.known_resource_types.add @type
- Puppet::Resource.new("class", :main).title.should == :main
+ Puppet::Resource.new("class", :main, :environment => environment).title.should == :main
end
end
end
@@ -237,8 +234,8 @@ describe Puppet::Resource do
it "should not fail when an invalid parameter is used and strict mode is disabled" do
type = Puppet::Resource::Type.new(:definition, "foobar")
- Puppet::Node::Environment.new.known_resource_types.add type
- resource = Puppet::Resource.new("foobar", "/my/file")
+ environment.known_resource_types.add type
+ resource = Puppet::Resource.new("foobar", "/my/file", :environment => environment)
resource[:yay] = true
end
@@ -267,7 +264,7 @@ describe Puppet::Resource do
end
describe "when setting default parameters" do
- let(:foo_node) { Puppet::Node.new('foo') }
+ let(:foo_node) { Puppet::Node.new('foo', :environment => environment) }
let(:compiler) { Puppet::Parser::Compiler.new(foo_node) }
let(:scope) { Puppet::Parser::Scope.new(compiler) }
@@ -276,15 +273,15 @@ describe Puppet::Resource do
end
it "should fail when asked to set default values and it is not a parser resource" do
- Puppet::Node::Environment.new.known_resource_types.add(
+ environment.known_resource_types.add(
Puppet::Resource::Type.new(:definition, "default_param", :arguments => {"a" => ast_string("default")})
)
- resource = Puppet::Resource.new("default_param", "name")
+ resource = Puppet::Resource.new("default_param", "name", :environment => environment)
lambda { resource.set_default_parameters(scope) }.should raise_error(Puppet::DevError)
end
it "should evaluate and set any default values when no value is provided" do
- Puppet::Node::Environment.new.known_resource_types.add(
+ environment.known_resource_types.add(
Puppet::Resource::Type.new(:definition, "default_param", :arguments => {"a" => ast_string("a_default_value")})
)
resource = Puppet::Parser::Resource.new("default_param", "name", :scope => scope)
@@ -293,7 +290,7 @@ describe Puppet::Resource do
end
it "should skip attributes with no default value" do
- Puppet::Node::Environment.new.known_resource_types.add(
+ environment.known_resource_types.add(
Puppet::Resource::Type.new(:definition, "no_default_param", :arguments => {"a" => ast_string("a_default_value")})
)
resource = Puppet::Parser::Resource.new("no_default_param", "name", :scope => scope)
@@ -301,7 +298,7 @@ describe Puppet::Resource do
end
it "should return the list of default parameters set" do
- Puppet::Node::Environment.new.known_resource_types.add(
+ environment.known_resource_types.add(
Puppet::Resource::Type.new(:definition, "default_param", :arguments => {"a" => ast_string("a_default_value")})
)
resource = Puppet::Parser::Resource.new("default_param", "name", :scope => scope)
@@ -315,11 +312,10 @@ describe Puppet::Resource do
let(:apache) { Puppet::Resource::Type.new(:hostclass, 'apache', :arguments => { 'port' => port }) }
before do
- environment = Puppet::Node::Environment.new(environment_name)
environment.known_resource_types.add(apache)
scope.stubs(:host).returns('host')
- scope.stubs(:environment).returns(Puppet::Node::Environment.new(environment_name))
+ scope.stubs(:environment).returns(environment)
scope.stubs(:facts).returns(Puppet::Node::Facts.new("facts", fact_values))
end
@@ -398,17 +394,17 @@ describe Puppet::Resource do
describe "when validating all required parameters are present" do
it "should be able to validate that all required parameters are present" do
- Puppet::Node::Environment.new.known_resource_types.add(
+ environment.known_resource_types.add(
Puppet::Resource::Type.new(:definition, "required_param", :arguments => {"a" => nil})
)
- lambda { Puppet::Resource.new("required_param", "name").validate_complete }.should raise_error(Puppet::ParseError)
+ lambda { Puppet::Resource.new("required_param", "name", :environment => environment).validate_complete }.should raise_error(Puppet::ParseError)
end
it "should not fail when all required parameters are present" do
- Puppet::Node::Environment.new.known_resource_types.add(
+ environment.known_resource_types.add(
Puppet::Resource::Type.new(:definition, "no_required_param")
)
- resource = Puppet::Resource.new("no_required_param", "name")
+ resource = Puppet::Resource.new("no_required_param", "name", :environment => environment)
resource["a"] = "meh"
lambda { resource.validate_complete }.should_not raise_error
end
@@ -455,14 +451,14 @@ describe Puppet::Resource do
it "should correctly detect when provided parameters are not valid for defined resource types" do
type = Puppet::Resource::Type.new(:definition, "foobar")
- Puppet::Node::Environment.new.known_resource_types.add type
- Puppet::Resource.new("foobar", "/my/file").should_not be_valid_parameter("myparam")
+ environment.known_resource_types.add type
+ Puppet::Resource.new("foobar", "/my/file", :environment => environment).should_not be_valid_parameter("myparam")
end
it "should correctly detect when provided parameters are valid for defined resource types" do
type = Puppet::Resource::Type.new(:definition, "foobar", :arguments => {"myparam" => nil})
- Puppet::Node::Environment.new.known_resource_types.add type
- Puppet::Resource.new("foobar", "/my/file").should be_valid_parameter("myparam")
+ environment.known_resource_types.add type
+ Puppet::Resource.new("foobar", "/my/file", :environment => environment).should be_valid_parameter("myparam")
end
it "should allow setting and retrieving of parameters" do
@@ -603,11 +599,9 @@ describe Puppet::Resource do
describe "when serializing a defined type" do
before do
type = Puppet::Resource::Type.new(:definition, "foo::bar")
- Puppet::Node::Environment.new.known_resource_types.add type
- end
+ environment.known_resource_types.add type
- before :each do
- @resource = Puppet::Resource.new('foo::bar', 'xyzzy')
+ @resource = Puppet::Resource.new('foo::bar', 'xyzzy', :environment => environment)
@resource['one'] = 'test'
@resource['two'] = 'other'
@resource.resource_type
diff --git a/spec/unit/util/autoload_spec.rb b/spec/unit/util/autoload_spec.rb
index 3592a63c9..1800dd2dc 100755
--- a/spec/unit/util/autoload_spec.rb
+++ b/spec/unit/util/autoload_spec.rb
@@ -24,14 +24,9 @@ describe Puppet::Util::Autoload do
end
it "should collect all of the lib directories that exist in the current environment's module path" do
- Puppet.settings.parse_config(<<-CONF)
- [foo]
- modulepath = #{@dira}#{File::PATH_SEPARATOR}#{@dirb}#{File::PATH_SEPARATOR}#{@dirc}
- CONF
-
- Puppet[:environment] = "foo"
- Dir.expects(:entries).with(@dira).returns %w{one two}
- Dir.expects(:entries).with(@dirb).returns %w{one two}
+ environment = Puppet::Node::Environment.create(:foo, [@dira, @dirb, @dirc], '')
+ Dir.expects(:entries).with(@dira).returns %w{. .. one two}
+ Dir.expects(:entries).with(@dirb).returns %w{. .. one two}
Puppet::FileSystem.expects(:directory?).with(@dira).returns true
Puppet::FileSystem.expects(:directory?).with(@dirb).returns true
@@ -40,32 +35,14 @@ describe Puppet::Util::Autoload do
FileTest.expects(:directory?).with(regexp_matches(%r{two/lib})).times(2).returns true
FileTest.expects(:directory?).with(regexp_matches(%r{one/lib})).times(2).returns false
- @autoload.class.module_directories.should == ["#{@dira}/two/lib", "#{@dirb}/two/lib"]
- end
-
- it "should not look for lib directories in directories starting with '.'" do
- Puppet.settings.parse_config(<<-CONF)
- [foo]
- modulepath = #{@dira}
- CONF
-
- Puppet[:environment] = "foo"
- Dir.expects(:entries).with(@dira).returns %w{. ..}
-
- Puppet::FileSystem.expects(:directory?).with(@dira).returns true
- Puppet::FileSystem.expects(:directory?).with("#{@dira}/./lib").never
- Puppet::FileSystem.expects(:directory?).with("#{@dira}/./plugins").never
- Puppet::FileSystem.expects(:directory?).with("#{@dira}/../lib").never
- Puppet::FileSystem.expects(:directory?).with("#{@dira}/../plugins").never
-
- @autoload.class.module_directories
+ @autoload.class.module_directories(environment).should == ["#{@dira}/two/lib", "#{@dirb}/two/lib"]
end
it "should include the module directories, the Puppet libdir, and all of the Ruby load directories" do
Puppet[:libdir] = %w{/libdir1 /lib/dir/two /third/lib/dir}.join(File::PATH_SEPARATOR)
@autoload.class.expects(:gem_directories).returns %w{/one /two}
@autoload.class.expects(:module_directories).returns %w{/three /four}
- @autoload.class.search_directories.should == %w{/one /two /three /four} + Puppet[:libdir].split(File::PATH_SEPARATOR) + $LOAD_PATH
+ @autoload.class.search_directories(nil).should == %w{/one /two /three /four} + Puppet[:libdir].split(File::PATH_SEPARATOR) + $LOAD_PATH
end
end