|
| 1 | +#!/usr/bin/env ruby |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | + |
| 5 | +describe Puppet::Type.type(:oratab).provider(:parsed) do |
| 6 | + |
| 7 | + before :each do |
| 8 | + described_class.stubs(:suitable?).returns true |
| 9 | + described_class.stubs(:default_target).returns my_fixture('oratab') |
| 10 | + Puppet::Type.type(:oratab).stubs(:defaultprovider).returns described_class |
| 11 | + @resource = Puppet::Type.type(:oratab).new( |
| 12 | + :name => 'TEST01', |
| 13 | + :ensure => :present, |
| 14 | + :home => '/u01/app/oracle/product/9.2.0.1.0', |
| 15 | + :atboot => :yes, |
| 16 | + :description => 'managed by puppet' |
| 17 | + ) |
| 18 | + @provider = described_class.new(@resource) |
| 19 | + end |
| 20 | + |
| 21 | + [:destroy, :create, :exists?].each do |method| |
| 22 | + it "should respond to #{method}" do |
| 23 | + @provider.should respond_to method |
| 24 | + end |
| 25 | + end |
| 26 | + |
| 27 | + [:home, :atboot, :description].each do |property| |
| 28 | + it "should have getter and setter for property #{property}" do |
| 29 | + @provider.should respond_to property |
| 30 | + @provider.should respond_to "#{property}=".intern |
| 31 | + end |
| 32 | + end |
| 33 | + |
| 34 | + describe "when parsing a line" do |
| 35 | + |
| 36 | + describe "with no description" do |
| 37 | + it "should capture the name" do |
| 38 | + described_class.parse_line('TEST:/app/oracle/db/11.2/db_1:N')[:name].should == 'TEST' |
| 39 | + described_class.parse_line('TEST_01:/app/oracle/db/11.2/db_1:N')[:name].should == 'TEST_01' |
| 40 | + end |
| 41 | + |
| 42 | + it "should capture the home directory" do |
| 43 | + described_class.parse_line('TEST:/db_1:N')[:home].should == '/db_1' |
| 44 | + described_class.parse_line('TEST:/db_1:Y')[:home].should == '/db_1' |
| 45 | + described_class.parse_line('TEST_01:/app/oracle/db/11.2/db_1:Y')[:home].should == '/app/oracle/db/11.2/db_1' |
| 46 | + end |
| 47 | + |
| 48 | + it "should capture the atboot flag" do |
| 49 | + described_class.parse_line('TEST:/app/oracle/db/11.2/db_1:N')[:atboot].should == :no |
| 50 | + described_class.parse_line('TEST:/app/oracle/db/11.2/db_1:Y')[:atboot].should == :yes |
| 51 | + end |
| 52 | + end |
| 53 | + |
| 54 | + describe "with a description" do |
| 55 | + it "should capture the name" do |
| 56 | + described_class.parse_line('TEST:/app/oracle/db/11.2/db_1:N # fancy comment')[:name].should == 'TEST' |
| 57 | + described_class.parse_line('TEST_01:/app/oracle/db/11.2/db_1:N # even ## fancier')[:name].should == 'TEST_01' |
| 58 | + end |
| 59 | + it "should capture the home directory" do |
| 60 | + described_class.parse_line('TEST:/db_1:N # fancy comment')[:home].should == '/db_1' |
| 61 | + described_class.parse_line('TEST_01:/app/oracle/db/11.2/db_1:Y# even ## fancier')[:home].should == '/app/oracle/db/11.2/db_1' |
| 62 | + end |
| 63 | + it "should capture the atboot flag" do |
| 64 | + described_class.parse_line('TEST:/app/oracle/db/11.2/db_1:N # fancy comment')[:atboot].should == :no |
| 65 | + described_class.parse_line('TEST:/app/oracle/db/11.2/db_1:Y## even ## fancier')[:atboot].should == :yes |
| 66 | + end |
| 67 | + it "should capture the description" do |
| 68 | + described_class.parse_line('TEST:/app/oracle/db/11.2/db_1:N # fancy comment')[:description].should == 'fancy comment' |
| 69 | + described_class.parse_line('TEST:/app/oracle/db/11.2/db_1:Y## even ## fancier')[:description].should == '# even ## fancier' |
| 70 | + end |
| 71 | + end |
| 72 | + end |
| 73 | + |
| 74 | + describe "when calling instances" do |
| 75 | + before :each do |
| 76 | + @instances = described_class.instances |
| 77 | + @instances.size.should == 3 |
| 78 | + end |
| 79 | + |
| 80 | + it "should be able to get the first entry" do |
| 81 | + @instances[0].get(:name).should == 'TEST' |
| 82 | + @instances[0].get(:home).should == '/app/oracle/db/11.2/db_1' |
| 83 | + @instances[0].get(:atboot).should == :no |
| 84 | + @instances[0].get(:description).should == 'line added by Agent' |
| 85 | + end |
| 86 | + |
| 87 | + it "should be able to get the second entry" do |
| 88 | + @instances[1].get(:name).should == 'PROD' |
| 89 | + @instances[1].get(:home).should == '/app/oracle/db/11.2/db_2' |
| 90 | + @instances[1].get(:atboot).should == :yes |
| 91 | + @instances[1].get(:description).should == :absent |
| 92 | + end |
| 93 | + |
| 94 | + it "should be able to get the third entry" do |
| 95 | + @instances[2].get(:name).should == 'DR' |
| 96 | + @instances[2].get(:home).should == '/app/oracle/db/11.2/db_4' |
| 97 | + @instances[2].get(:atboot).should == :no |
| 98 | + @instances[2].get(:description).should == 'i am still # an inline comment' |
| 99 | + end |
| 100 | + end |
| 101 | + |
| 102 | +end |
0 commit comments