Skip to content

Commit 8da9aff

Browse files
committed
Add integration tests for oratab provider
1 parent bbf11a9 commit 8da9aff

File tree

9 files changed

+282
-0
lines changed

9 files changed

+282
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# just a comment
2+
# next line is a blank line
3+
4+
5+
# FOO:BAR:Y
6+
7+
DB_INSYNC:/u01/app/oracle/product/10.1.0/db_1:Y
8+
DB_DELETE:/u01/app/oracle/product/10.1.0/db_3:Y
9+
DB_SYNC_HOME:/u01/app/oracle/product/10.1.0/db_4:Y # ignore # me
10+
11+
12+
DB_SYNC_ATBOOT:/u01/app/oracle/product/10.1.0/db_1:N
13+
DB_SYNC_DESCRIPTION:/u01/app/oracle/product/10.1.0/db_1:N # change me
14+
15+
# just a random comment
16+
17+
DB_DELETE_DESCRIPTION:/u01/app/oracle/product/10.1.0/db_1:N # delete me
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# just a comment
2+
# next line is a blank line
3+
4+
5+
# FOO:BAR:Y
6+
7+
DB_INSYNC:/u01/app/oracle/product/10.1.0/db_1:Y
8+
DB_SYNC_HOME:/new/home:Y # ignore # me
9+
10+
11+
DB_SYNC_ATBOOT:/u01/app/oracle/product/10.1.0/db_1:Y
12+
DB_SYNC_DESCRIPTION:/u01/app/oracle/product/10.1.0/db_1:N # new desc
13+
14+
# just a random comment
15+
16+
DB_DELETE_DESCRIPTION:/u01/app/oracle/product/10.1.0/db_1:N
17+
DB_CREATE:/u01/app/oracle/product/10.1.0/db_2:N # added by puppet
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# just a comment
2+
# next line is a blank line
3+
4+
5+
# FOO:BAR:Y
6+
7+
DB_INSYNC:/u01/app/oracle/product/10.1.0/db_1:Y
8+
DB_DELETE:/u01/app/oracle/product/10.1.0/db_3:Y
9+
DB_SYNC_HOME:/u01/app/oracle/product/10.1.0/db_4:Y # ignore # me
10+
11+
12+
DB_SYNC_ATBOOT:/u01/app/oracle/product/10.1.0/db_1:N
13+
DB_SYNC_DESCRIPTION:/u01/app/oracle/product/10.1.0/db_1:N # change me
14+
15+
# just a random comment
16+
17+
DB_DELETE_DESCRIPTION:/u01/app/oracle/product/10.1.0/db_1:N # delete me
18+
DB_CREATE:/u01/app/oracle/product/10.1.0/db_2:N # added by puppet
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# just a comment
2+
# next line is a blank line
3+
4+
5+
# FOO:BAR:Y
6+
7+
DB_INSYNC:/u01/app/oracle/product/10.1.0/db_1:Y
8+
DB_SYNC_HOME:/u01/app/oracle/product/10.1.0/db_4:Y # ignore # me
9+
10+
11+
DB_SYNC_ATBOOT:/u01/app/oracle/product/10.1.0/db_1:N
12+
DB_SYNC_DESCRIPTION:/u01/app/oracle/product/10.1.0/db_1:N # change me
13+
14+
# just a random comment
15+
16+
DB_DELETE_DESCRIPTION:/u01/app/oracle/product/10.1.0/db_1:N # delete me
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# just a comment
2+
# next line is a blank line
3+
4+
5+
# FOO:BAR:Y
6+
7+
DB_INSYNC:/u01/app/oracle/product/10.1.0/db_1:Y
8+
DB_DELETE:/u01/app/oracle/product/10.1.0/db_3:Y
9+
DB_SYNC_HOME:/u01/app/oracle/product/10.1.0/db_4:Y # ignore # me
10+
11+
12+
DB_SYNC_ATBOOT:/u01/app/oracle/product/10.1.0/db_1:Y
13+
DB_SYNC_DESCRIPTION:/u01/app/oracle/product/10.1.0/db_1:N # change me
14+
15+
# just a random comment
16+
17+
DB_DELETE_DESCRIPTION:/u01/app/oracle/product/10.1.0/db_1:N # delete me
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# just a comment
2+
# next line is a blank line
3+
4+
5+
# FOO:BAR:Y
6+
7+
DB_INSYNC:/u01/app/oracle/product/10.1.0/db_1:Y
8+
DB_DELETE:/u01/app/oracle/product/10.1.0/db_3:Y
9+
DB_SYNC_HOME:/u01/app/oracle/product/10.1.0/db_4:Y # ignore # me
10+
11+
12+
DB_SYNC_ATBOOT:/u01/app/oracle/product/10.1.0/db_1:N
13+
DB_SYNC_DESCRIPTION:/u01/app/oracle/product/10.1.0/db_1:N # new desc
14+
15+
# just a random comment
16+
17+
DB_DELETE_DESCRIPTION:/u01/app/oracle/product/10.1.0/db_1:N # delete me
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# just a comment
2+
# next line is a blank line
3+
4+
5+
# FOO:BAR:Y
6+
7+
DB_INSYNC:/u01/app/oracle/product/10.1.0/db_1:Y
8+
DB_DELETE:/u01/app/oracle/product/10.1.0/db_3:Y
9+
DB_SYNC_HOME:/u01/app/oracle/product/10.1.0/db_4:Y # ignore # me
10+
11+
12+
DB_SYNC_ATBOOT:/u01/app/oracle/product/10.1.0/db_1:N
13+
DB_SYNC_DESCRIPTION:/u01/app/oracle/product/10.1.0/db_1:N # change me
14+
15+
# just a random comment
16+
17+
DB_DELETE_DESCRIPTION:/u01/app/oracle/product/10.1.0/db_1:N
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# just a comment
2+
# next line is a blank line
3+
4+
5+
# FOO:BAR:Y
6+
7+
DB_INSYNC:/u01/app/oracle/product/10.1.0/db_1:Y
8+
DB_DELETE:/u01/app/oracle/product/10.1.0/db_3:Y
9+
DB_SYNC_HOME:/new/home:Y # ignore # me
10+
11+
12+
DB_SYNC_ATBOOT:/u01/app/oracle/product/10.1.0/db_1:N
13+
DB_SYNC_DESCRIPTION:/u01/app/oracle/product/10.1.0/db_1:N # change me
14+
15+
# just a random comment
16+
17+
DB_DELETE_DESCRIPTION:/u01/app/oracle/product/10.1.0/db_1:N # delete me
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'spec_helper'
4+
require 'puppet/file_bucket/dipper'
5+
6+
describe Puppet::Type.type(:oratab).provider(:parsed), '(integration)' do
7+
include PuppetSpec::Files
8+
9+
before :each do
10+
described_class.stubs(:suitable?).returns true
11+
Puppet::Type.type(:oratab).stubs(:defaultprovider).returns described_class
12+
13+
@fake_oratab = tmpfile('oratab')
14+
FileUtils.cp(my_fixture('input'), @fake_oratab)
15+
described_class.stubs(:default_target).returns @fake_oratab
16+
17+
@resource_absent = Puppet::Type.type(:oratab).new(
18+
:name => 'NO_SUCH_DATABASE',
19+
:ensure => :absent
20+
)
21+
@resource_present = Puppet::Type.type(:oratab).new(
22+
:name => 'DB_INSYNC',
23+
:ensure => :present,
24+
:home => '/u01/app/oracle/product/10.1.0/db_1',
25+
:atboot => :yes
26+
)
27+
@resource_create = Puppet::Type.type(:oratab).new(
28+
:name => 'DB_CREATE',
29+
:ensure => :present,
30+
:home => '/u01/app/oracle/product/10.1.0/db_2',
31+
:description => 'added by puppet',
32+
:atboot => :no
33+
)
34+
@resource_delete = Puppet::Type.type(:oratab).new(
35+
:name => 'DB_DELETE',
36+
:ensure => :absent
37+
)
38+
@resource_sync_home = Puppet::Type.type(:oratab).new(
39+
:name => 'DB_SYNC_HOME',
40+
:ensure => :present,
41+
:home => '/new/home'
42+
)
43+
@resource_sync_atboot = Puppet::Type.type(:oratab).new(
44+
:name => 'DB_SYNC_ATBOOT',
45+
:ensure => :present,
46+
:home => '/u01/app/oracle/product/10.1.0/db_1',
47+
:atboot => :yes
48+
)
49+
@resource_sync_description = Puppet::Type.type(:oratab).new(
50+
:name => 'DB_SYNC_DESCRIPTION',
51+
:ensure => :present,
52+
:atboot => :no,
53+
:description => 'new desc'
54+
)
55+
@resource_delete_description = Puppet::Type.type(:oratab).new(
56+
:name => 'DB_DELETE_DESCRIPTION',
57+
:ensure => :present,
58+
:description => ''
59+
)
60+
end
61+
62+
after :each do
63+
described_class.clear
64+
end
65+
66+
def run_in_catalog(*resources)
67+
Puppet::FileBucket::Dipper.any_instance.stubs(:backup) # Don't backup to filebucket
68+
catalog = Puppet::Resource::Catalog.new
69+
catalog.host_config = false
70+
resources.each do |resource|
71+
resource.expects(:err).never
72+
catalog.add_resource(resource)
73+
end
74+
catalog.apply
75+
end
76+
77+
def check_content_against(fixture)
78+
content = File.read(@fake_oratab).lines.map{|l| l.chomp}.reject{|l| l=~ /^\s*#|^\s*$/}.sort.join("\n")
79+
expected_content = File.read(my_fixture(fixture)).lines.map{|l| l.chomp}.reject{|l| l=~ /^\s*#|^\s*$/}.sort.join("\n")
80+
content.should == expected_content
81+
end
82+
83+
describe "when managing one resource" do
84+
85+
describe "with ensure set to absent" do
86+
it "should do nothing if already absent" do
87+
run_in_catalog(@resource_absent)
88+
check_content_against('input')
89+
end
90+
91+
it "should remove oratab entry if currently present" do
92+
run_in_catalog(@resource_delete)
93+
check_content_against('output_single_delete')
94+
end
95+
end
96+
97+
describe "with ensure set to present" do
98+
it "should do nothing if already present and in sync" do
99+
run_in_catalog(@resource_present)
100+
check_content_against('input')
101+
end
102+
103+
it "should create an oratab entry if currently absent" do
104+
run_in_catalog(@resource_create)
105+
check_content_against('output_single_create')
106+
end
107+
108+
it "should sync home if out of sync" do
109+
run_in_catalog(@resource_sync_home)
110+
check_content_against('output_single_sync_home')
111+
end
112+
113+
it "should sync atboot if out of sync" do
114+
run_in_catalog(@resource_sync_atboot)
115+
check_content_against('output_single_sync_atboot')
116+
end
117+
118+
it "should sync description if out sync" do
119+
run_in_catalog(@resource_sync_description)
120+
check_content_against('output_single_sync_description')
121+
end
122+
123+
it "should remove the description (including the #-sign) if description is empty" do
124+
run_in_catalog(@resource_delete_description)
125+
check_content_against('output_single_sync_description_delete')
126+
end
127+
end
128+
end
129+
130+
describe "when managing multiple resources" do
131+
it "should to the right thing (tm)" do
132+
run_in_catalog(
133+
@resource_absent,
134+
@resource_present,
135+
@resource_create,
136+
@resource_delete,
137+
@resource_sync_home,
138+
@resource_sync_atboot,
139+
@resource_sync_description,
140+
@resource_delete_description
141+
)
142+
check_content_against('output_multiple')
143+
end
144+
end
145+
146+
end

0 commit comments

Comments
 (0)