~ubuntu-branches/ubuntu/oneiric/puppet/oneiric-security

« back to all changes in this revision

Viewing changes to spec/unit/node/environment.rb

  • Committer: Bazaar Package Importer
  • Author(s): Micah Anderson
  • Date: 2008-07-26 15:43:45 UTC
  • mfrom: (1.1.8 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080726154345-c03m49twzxewdwjn
Tags: 0.24.5-2
* Fix puppetlast to work with 0.24.5
* Adjust logcheck to match against new log messages in 0.24.5
* Update standards version to 3.8.0 (no changes)
* Update changelog to reduce length of line to make lintian happy

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env ruby
 
2
 
 
3
require File.dirname(__FILE__) + '/../../spec_helper'
 
4
 
 
5
require 'puppet/node/environment'
 
6
 
 
7
describe Puppet::Node::Environment do
 
8
    it "should provide a list of valid environments" do
 
9
        Puppet::Node::Environment.valid.should be_instance_of(Array)
 
10
    end
 
11
 
 
12
    it "should determine its list of valid environments from splitting the :environments setting on commas" do
 
13
        Puppet.settings.stubs(:value).with(:environments).returns("one,two")
 
14
        Puppet::Node::Environment.valid.collect { |e| e.to_s }.sort.should == %w{one two}.sort
 
15
    end
 
16
 
 
17
    it "should not use an environment when determining the list of valid environments" do
 
18
        Puppet.settings.expects(:value).with(:environments).returns("one,two")
 
19
        Puppet::Node::Environment.valid
 
20
    end
 
21
 
 
22
    it "should provide a means of identifying invalid environments" do
 
23
        Puppet.settings.expects(:value).with(:environments).returns("one,two")
 
24
        Puppet::Node::Environment.valid?(:three).should be_false
 
25
    end
 
26
 
 
27
    it "should provide a means of identifying valid environments" do
 
28
        Puppet.settings.expects(:value).with(:environments).returns("one,two")
 
29
        Puppet::Node::Environment.valid?(:one).should be_true
 
30
    end
 
31
 
 
32
    it "should be used to determine when an environment setting is valid" do
 
33
        Puppet.settings.expects(:value).with(:environments).returns("one,two")
 
34
        proc { Puppet.settings[:environment] = :three }.should raise_error(ArgumentError)
 
35
    end
 
36
 
 
37
    it "should use the default environment if no name is provided while initializing an environment" do
 
38
        Puppet.settings.expects(:value).with(:environments).returns("one,two")
 
39
        Puppet.settings.expects(:value).with(:environment).returns("one")
 
40
        Puppet::Node::Environment.new().name.should == :one
 
41
    end
 
42
 
 
43
    it "should treat environment instances as singletons" do
 
44
        Puppet.settings.stubs(:value).with(:environments).returns("one")
 
45
        Puppet::Node::Environment.new("one").should equal(Puppet::Node::Environment.new("one"))
 
46
    end
 
47
 
 
48
    it "should treat an environment specified as names or strings as equivalent" do
 
49
        Puppet.settings.stubs(:value).with(:environments).returns("one")
 
50
        Puppet::Node::Environment.new(:one).should equal(Puppet::Node::Environment.new("one"))
 
51
    end
 
52
 
 
53
    it "should fail if an invalid environment instance is asked for" do
 
54
        Puppet.settings.stubs(:value).with(:environments).returns("one,two")
 
55
        proc { Puppet::Node::Environment.new("three") }.should raise_error(ArgumentError)
 
56
    end
 
57
 
 
58
    it "should consider environments that are empty strings invalid" do
 
59
        Puppet::Node::Environment.valid?("").should be_false
 
60
    end
 
61
 
 
62
    it "should fail if a no-longer-valid environment instance is asked for" do
 
63
        Puppet.settings.expects(:value).with(:environments).returns("one")
 
64
        Puppet::Node::Environment.new("one")
 
65
        Puppet.settings.expects(:value).with(:environments).returns("two")
 
66
        proc { Puppet::Node::Environment.new("one") }.should raise_error(ArgumentError)
 
67
    end
 
68
end
 
69
 
 
70
describe Puppet::Node::Environment, " when modeling a specific environment" do
 
71
    before do
 
72
        Puppet.settings.expects(:value).with(:environments).returns("testing")
 
73
    end
 
74
 
 
75
    it "should have a method for returning the environment name" do
 
76
        Puppet::Node::Environment.new("testing").name.should == :testing
 
77
    end
 
78
 
 
79
    it "should provide an array-like accessor method for returning any environment-specific setting" do
 
80
        env = Puppet::Node::Environment.new("testing")
 
81
        env.should respond_to(:[])
 
82
    end
 
83
 
 
84
    it "should ask the Puppet settings instance for the setting qualified with the environment name" do
 
85
        Puppet.settings.expects(:value).with("myvar", :testing).returns("myval")
 
86
        env = Puppet::Node::Environment.new("testing")
 
87
        env["myvar"].should == "myval"
 
88
    end
 
89
end