newer pg module
[mirror/dsa-puppet.git] / 3rdparty / modules / postgresql / spec / unit / provider / postgresql_conf / parsed_spec.rb
1 require 'spec_helper'
2 require "tempfile"
3
4 provider_class = Puppet::Type.type(:postgresql_conf).provider(:parsed)
5
6 describe provider_class do
7   let(:title) { 'postgresql_conf' }
8   let(:provider) {
9     conf_class = Puppet::Type.type(:postgresql_conf)
10     provider = conf_class.provider(:parsed)
11     conffile = tmpfilename('postgresql.conf')
12     provider.any_instance.stub(:target).and_return conffile
13     provider
14   }
15
16   before do
17   end
18
19   after :each do
20     provider.initvars
21   end
22
23   describe "simple configuration that should be allowed" do
24     it "should parse a simple ini line" do
25       expect(provider.parse_line("listen_addreses = '*'")).to eq(
26         { :name=>"listen_addreses", :value=>"*", :comment=>nil, :record_type=>:parsed }
27       )
28     end
29
30     it "should parse a simple ini line (2)" do
31       expect(provider.parse_line("   listen_addreses = '*'")).to eq(
32         { :name=>"listen_addreses", :value=>"*", :comment=>nil, :record_type=>:parsed }
33       )
34     end
35
36     it "should parse a simple ini line (3)" do
37       expect(provider.parse_line("listen_addreses = '*' # dont mind me")).to eq(
38         { :name=>"listen_addreses", :value=>"*", :comment=>"dont mind me", :record_type=>:parsed }
39       )
40     end
41
42     it "should parse a comment" do
43       expect(provider.parse_line("# dont mind me")).to eq(
44         { :line=>"# dont mind me", :record_type=>:comment }
45       )
46     end
47
48     it "should parse a comment (2)" do
49       expect(provider.parse_line(" \t# dont mind me")).to eq(
50         { :line=>" \t# dont mind me", :record_type=>:comment }
51       )
52     end
53
54     it "should allow includes" do
55       expect(provider.parse_line("include puppetextra")).to eq(
56         { :name=>"include", :value=>"puppetextra", :comment=>nil, :record_type=>:parsed }
57       )
58     end
59
60     it "should allow numbers through without quotes" do
61       expect(provider.parse_line("wal_keep_segments = 32")).to eq(
62         { :name=>"wal_keep_segments", :value=>"32", :comment=>nil, :record_type=>:parsed }
63       )
64     end
65
66     it "should allow blanks through " do
67       expect(provider.parse_line("")).to eq(
68         { :line=>"", :record_type=>:blank }
69       )
70     end
71
72     it "should parse keys with dots " do
73       expect(provider.parse_line("auto_explain.log_min_duration = 1ms")).to eq(
74         { :name => "auto_explain.log_min_duration", :value => "1ms", :comment => nil, :record_type => :parsed }
75       )
76     end
77   end
78
79   describe "configuration that should be set" do
80     it "should set comment lines" do
81       expect(provider.to_line({ :line=>"# dont mind me", :record_type=>:comment })).to eq(
82         '# dont mind me'
83       )
84     end
85
86     it "should set blank lines" do
87       expect(provider.to_line({ :line=>"", :record_type=>:blank })).to eq(
88         ''
89       )
90     end
91
92     it "should set simple configuration" do
93       expect(provider.to_line({:name=>"listen_addresses", :value=>"*", :comment=>nil, :record_type=>:parsed })).to eq(
94         "listen_addresses = '*'"
95       )
96     end
97
98     it "should set simple configuration with period in name" do
99       expect(provider.to_line({:name => "auto_explain.log_min_duration", :value => '100ms', :comment => nil, :record_type => :parsed })).to eq(
100         "auto_explain.log_min_duration = 100ms"
101       )
102     end
103
104     it "should set simple configuration even with comments" do
105       expect(provider.to_line({:name=>"listen_addresses", :value=>"*", :comment=>'dont mind me', :record_type=>:parsed })).to eq(
106         "listen_addresses = '*' # dont mind me"
107       )
108     end
109
110     it 'should quote includes' do
111       expect(provider.to_line( {:name=>"include", :value=>"puppetextra", :comment=>nil, :record_type=>:parsed })).to eq(
112         "include 'puppetextra'"
113       )
114     end
115
116     it 'should quote multiple words' do
117       expect(provider.to_line( {:name=>"archive_command", :value=>"rsync up", :comment=>nil, :record_type=>:parsed })).to eq(
118         "archive_command = 'rsync up'"
119       )
120     end
121
122     it 'shouldn\'t quote numbers' do
123       expect(provider.to_line( {:name=>"wal_segments", :value=>"32", :comment=>nil, :record_type=>:parsed })).to eq(
124         "wal_segments = 32"
125       )
126     end
127
128     it "should allow numbers" do
129       expect(provider.to_line( {:name=>"integer", :value=>42, :comment=>nil, :record_type=>:parsed })).to eq(
130         "integer = 42"
131       )
132     end
133
134     it "should allow floats" do
135       expect(provider.to_line( {:name=>"float", :value=>2.71828182845, :comment=>nil, :record_type=>:parsed })).to eq(
136         "float = 2.71828182845"
137       )
138     end
139
140     it "quotes addresses" do
141       expect(provider.to_line( {:name=>"listen_addresses", :value=>"0.0.0.0", :comment=>nil, :record_type=>:parsed })).to eq(
142         "listen_addresses = '0.0.0.0'"
143       )
144     end
145   end
146 end
147