|
96 | 96 |
|
97 | 97 | end |
98 | 98 |
|
99 | | - describe "when modifying Node attributes" do |
100 | | - it "loads attributes from cookbooks" do |
| 99 | + describe "chef_environment" do |
| 100 | + it "should set an environment with chef_environment(something)" do |
| 101 | + lambda { @node.chef_environment("latte") }.should_not raise_error |
| 102 | + end |
| 103 | + |
| 104 | + it "should return the chef_environment with chef_environment()" do |
| 105 | + @node.chef_environment("latte") |
| 106 | + @node.chef_environment.should == "latte" |
| 107 | + end |
| 108 | + |
| 109 | + it "should disallow non-strings (except for nil)" do |
| 110 | + lambda { @node.chef_environment(Hash.new) }.should raise_error(ArgumentError) |
| 111 | + end |
| 112 | + |
| 113 | + it "can be nil" do |
| 114 | + @node.chef_environment("foo") |
| 115 | + @node.chef_environment(nil) |
| 116 | + @node.chef_environment.should == nil |
| 117 | + end |
| 118 | + |
| 119 | + it "cannot be blank" do |
| 120 | + lambda { @node.chef_environment("")}.should raise_error(Chef::Exceptions::ValidationFailed) |
| 121 | + end |
| 122 | + end |
| 123 | + |
| 124 | + describe "attributes" do |
| 125 | + it "should be loaded from the node's cookbooks" do |
101 | 126 | Chef::Config.cookbook_path = File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "cookbooks")) |
102 | 127 | @node.cookbook_collection = Chef::CookbookCollection.new(Chef::CookbookLoader.new) |
103 | 128 | @node.load_attributes |
|
439 | 464 | it "should load a node from a file by fqdn" do |
440 | 465 | @node.find_file("test.example.com") |
441 | 466 | @node.name.should == "test.example.com" |
| 467 | + @node.chef_environment.should == "dev" |
442 | 468 | end |
443 | 469 |
|
444 | 470 | it "should load a node from a file by hostname" do |
|
467 | 493 |
|
468 | 494 | describe "to_hash" do |
469 | 495 | it "should serialize itself as a hash" do |
| 496 | + @node.chef_environment("dev") |
470 | 497 | @node.default_attrs = { "one" => { "two" => "three", "four" => "five", "eight" => "nine" } } |
471 | 498 | @node.override_attrs = { "one" => { "two" => "three", "four" => "six" } } |
472 | 499 | @node.normal_attrs = { "one" => { "two" => "seven" } } |
|
482 | 509 | h["run_list"].should be_include("role[marxist]") |
483 | 510 | h["run_list"].should be_include("role[leninist]") |
484 | 511 | h["run_list"].should be_include("recipe[stalinist]") |
| 512 | + h["chef_environment"].should == "dev" |
485 | 513 | end |
486 | 514 | end |
487 | 515 |
|
|
491 | 519 | json = @node.to_json() |
492 | 520 | json.should =~ /json_class/ |
493 | 521 | json.should =~ /name/ |
| 522 | + json.should =~ /chef_environment/ |
494 | 523 | json.should =~ /normal/ |
495 | 524 | json.should =~ /default/ |
496 | 525 | json.should =~ /override/ |
|
503 | 532 | serialized_node = JSON.parse(json) |
504 | 533 | serialized_node.should be_a_kind_of(Chef::Node) |
505 | 534 | serialized_node.name.should eql(@node.name) |
| 535 | + serialized_node.chef_environment.should eql(@node.chef_environment) |
506 | 536 | @node.each_attribute do |k,v| |
507 | 537 | serialized_node[k].should eql(v) |
508 | 538 | end |
|
0 commit comments